From f664d297f7bb009784868bf3fcf0b3e3bb9a646b Mon Sep 17 00:00:00 2001
From: Felipe Heidrich
- * The style value is either one of the style constants defined in
- * class
- * The elements in the segments field specify the start offset of
- * a segment relative to the start of the line. They must follow
- * the following rules:
- *
- *
- *
- * @see Sample code and further information
- */
-public class AnimatedProgress extends Canvas {
-
- static final int SLEEP = 70;
- static final int DEFAULT_WIDTH = 160;
- static final int DEFAULT_HEIGHT = 18;
- boolean active = false;
- boolean showStripes = false;
- int value;
- int orientation = SWT.HORIZONTAL;
- boolean showBorder = false;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * SWT
which is applicable to instances of this
- * class, or must be built by bitwise OR'ing together
- * (that is, using the int
"|" operator) two or more
- * of those SWT
style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- *
- *
- * @exception SWTException
- *
- *
- * @see SWT#VERTICAL
- * @see SWT#HORIZONTAL
- * @see SWT#BORDER
- * @see #getStyle()
- */
-public AnimatedProgress(Composite parent, int style) {
- super(parent, checkStyle(style));
-
- if ((style & SWT.VERTICAL) != 0) {
- orientation = SWT.VERTICAL;
- }
- showBorder = (style & SWT.BORDER) != 0;
-
- addControlListener(new ControlAdapter() {
- public void controlResized(ControlEvent e) {
- redraw();
- }
- });
- addPaintListener(new PaintListener() {
- public void paintControl(PaintEvent e) {
- paint(e);
- }
- });
- addDisposeListener(new DisposeListener() {
- public void widgetDisposed(DisposeEvent e){
- stop();
- }
- });
-}
-private static int checkStyle (int style) {
- int mask = SWT.NONE;
- return style & mask;
-}
-/**
- * Stop the animation if it is not already stopped and
- * reset the presentation to a blank appearance.
- *
- * @exception SWTException
- *
- */
-public synchronized void clear(){
- checkWidget();
- if (active) stop();
- showStripes = false;
- redraw();
-}
-public Point computeSize(int wHint, int hHint, boolean changed) {
- checkWidget();
- Point size = null;
- if (orientation == SWT.HORIZONTAL) {
- size = new Point(DEFAULT_WIDTH, DEFAULT_HEIGHT);
- } else {
- size = new Point(DEFAULT_HEIGHT, DEFAULT_WIDTH);
- }
- if (wHint != SWT.DEFAULT) size.x = wHint;
- if (hHint != SWT.DEFAULT) size.y = hHint;
-
- return size;
-}
-private void drawBevelRect(GC gc, int x, int y, int w, int h, Color topleft, Color bottomright) {
- gc.setForeground(topleft);
- gc.drawLine(x, y, x+w-1, y);
- gc.drawLine(x, y, x, y+h-1);
-
- gc.setForeground(bottomright);
- gc.drawLine(x+w, y, x+w, y+h);
- gc.drawLine(x, y+h, x+w, y+h);
-}
-void paint(PaintEvent event) {
- GC gc = event.gc;
- Display disp= getDisplay();
-
- Rectangle rect= getClientArea();
- gc.fillRectangle(rect);
- if (showBorder) {
- drawBevelRect(gc, rect.x, rect.y, rect.width-1, rect.height-1,
- disp.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW),
- disp.getSystemColor(SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW));
- }
-
- paintStripes(gc);
-}
-void paintStripes(GC gc) {
-
- if (!showStripes) return;
-
- Rectangle rect= getClientArea();
- // Subtracted border painted by paint.
- rect = new Rectangle(rect.x+2, rect.y+2, rect.width-4, rect.height-4);
-
- gc.setLineWidth(2);
- gc.setClipping(rect);
- Color color = getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION);
- gc.setBackground(color);
- gc.fillRectangle(rect);
- gc.setForeground(this.getBackground());
- int step = 12;
- int foregroundValue = value == 0 ? step - 2 : value - 2;
- if (orientation == SWT.HORIZONTAL) {
- int y = rect.y - 1;
- int w = rect.width;
- int h = rect.height + 2;
- for (int i= 0; i < w; i+= step) {
- int x = i + foregroundValue;
- gc.drawLine(x, y, x, h);
- }
- } else {
- int x = rect.x - 1;
- int w = rect.width + 2;
- int h = rect.height;
-
- for (int i= 0; i < h; i+= step) {
- int y = i + foregroundValue;
- gc.drawLine(x, y, w, y);
- }
- }
-
- if (active) {
- value = (value + 2) % step;
- }
-}
-/**
-* Start the animation.
-*
-* @exception SWTException
-*
-*/
-public synchronized void start() {
- checkWidget();
- if (active) return;
-
- active = true;
- showStripes = true;
-
- final Display display = getDisplay();
- final Runnable [] timer = new Runnable [1];
- timer [0] = new Runnable () {
- public void run () {
- if (!active) return;
- GC gc = new GC(AnimatedProgress.this);
- paintStripes(gc);
- gc.dispose();
- display.timerExec (SLEEP, timer [0]);
- }
- };
- display.timerExec (SLEEP, timer [0]);
-}
-/**
-* Stop the animation. Freeze the presentation at its current appearance.
-*/
-public synchronized void stop() {
- //checkWidget();
- active = false;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/BidiSegmentEvent.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/BidiSegmentEvent.java
deleted file mode 100644
index cafd31fcd6..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/BidiSegmentEvent.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.custom;
-
-
-import org.eclipse.swt.events.*;
-
-/**
- * This event is sent to BidiSegmentListeners when a line is to
- * be measured or rendered in a bidi locale. The segments field is
- * used to specify text ranges in the line that should be treated as
- * separate segments for bidi reordering. Each segment will be reordered
- * and rendered separately.
- *
- *
- * In addition, the last element may be set to the end of the line
- * but this is not required.
- *
- * The segments field may be left null if the entire line should
- * be reordered as is.
- *
- * stored line = "R1R2R3" + "R4R5R6" - * R1 to R6 are right-to-left characters. The quotation marks - * are part of the line text. The line is 13 characters long. - * - * segments = null: - * entire line will be reordered and thus the two R2L segments - * swapped (as per the bidi algorithm). - * visual line (rendered on screen) = "R6R5R4" + "R3R2R1" - * - * segments = [0, 5, 8] - * "R1R2R3" will be reordered, followed by [blank]+[blank] and - * "R4R5R6". - * visual line = "R3R2R1" + "R6R5R4" - *- * - * @see Sample code and further information - */ -public class BidiSegmentEvent extends TypedEvent { - - /** - * line start offset - */ - public int lineOffset; - - /** - * line text - */ - public String lineText; - - /** - * bidi segments, see above - */ - public int[] segments; - - static final long serialVersionUID = 3257846571587547957L; - -BidiSegmentEvent(StyledTextEvent e) { - super(e); - lineOffset = e.detail; - lineText = e.text; -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/BidiSegmentListener.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/BidiSegmentListener.java deleted file mode 100644 index e1d9770623..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/BidiSegmentListener.java +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.custom; - -import org.eclipse.swt.internal.SWTEventListener; - -/** - * This listener interface may be implemented in order to receive - * BidiSegmentEvents. - * @see BidiSegmentEvent - */ -public interface BidiSegmentListener extends SWTEventListener { - -/** - * This method is called when a line needs to be reordered for - * measuring or rendering in a bidi locale. - *
- * The following event fields are used:
StyledText
.
- * - * The hashCode() method in this class uses the values of the public - * fields to compute the hash value. When storing instances of the - * class in hashed collections, do not modify these fields after the - * object has been inserted. - *
- *
- * Application code does not need to explicitly release the
- * resources managed by each instance when those instances are no longer
- * required, and thus no dispose()
method is provided.
- *
ST.BULLET_DOT
ST.BULLET_NUMBER
ST.BULLET_LETTER_LOWER
ST.BULLET_LETTER_UPPER
ST.BULLET_TEXT
ST.BULLET_CUSTOM
ST.BULLET_DOT
.
- * The style must have a glyph metrics set.
- *
- * @param style the style
- *
- * @exception IllegalArgumentException Runnable
while providing
- * busy feedback using this busy indicator.
- *
- * @param display the display on which the busy feedback should be
- * displayed. If the display is null, the Display for the current
- * thread will be used. If there is no Display for the current thread,
- * the runnable code will be executed and no busy feedback will be displayed.
- * @param runnable the runnable for which busy feedback is to be shown.
- * Must not be null.
- *
-* @exception IllegalArgumentException
- * Note that although this class is a subclass of Composite
,
- * it does not make sense to set a layout on it.
- *
- *
- * IMPORTANT: This class is not intended to be subclassed. - *
- * - * @see Sample code and further information - * - * @since 3.0 - * @noextend This class is not intended to be subclassed by clients. - */ - -public class CBanner extends Composite { - - Control left; - Control right; - Control bottom; - - boolean simple = true; - - int[] curve = new int[0]; - int curveStart = 0; - Rectangle curveRect = new Rectangle(0, 0, 0, 0); - int curve_width = 5; - int curve_indent = -2; - - int rightWidth = SWT.DEFAULT; - int rightMinWidth = 0; - int rightMinHeight = 0; - Cursor resizeCursor; - boolean dragging = false; - int rightDragDisplacement = 0; - Listener listener; - - static final int OFFSCREEN = -200; - static final int BORDER_BOTTOM = 2; - static final int BORDER_TOP = 3; - static final int BORDER_STRIPE = 1; - static final int CURVE_TAIL = 200; - static final int BEZIER_RIGHT = 30; - static final int BEZIER_LEFT = 30; - static final int MIN_LEFT = 10; - static int BORDER1 = SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW; - - -/** - * Constructs a new instance of this class given its parent - * and a style value describing its behavior and appearance. - *
- * The style value is either one of the style constants defined in
- * class SWT
which is applicable to instances of this
- * class, or must be built by bitwise OR'ing together
- * (that is, using the int
"|" operator) two or more
- * of those SWT
style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- *
true
if the CBanner is rendered
- * with a simple, traditional shape.
- *
- * @return true
if the CBanner is rendered with a simple shape
- *
- * @since 3.0
- */
-public boolean getSimple() {
- checkWidget();
- return simple;
-}
-void onDispose(Event event) {
- removeListener(SWT.Dispose, listener);
- notifyListeners(SWT.Dispose, event);
- event.type = SWT.None;
-
- if (resizeCursor != null) resizeCursor.dispose();
- resizeCursor = null;
- left = null;
- right = null;
- bottom = null;
-}
-void onMouseDown (int x, int y) {
- if (curveRect.contains(x, y)) {
- dragging = true;
- rightDragDisplacement = curveStart - x + curve_width - curve_indent;
- }
-}
-void onMouseExit() {
- if (!dragging) setCursor(null);
-}
-void onMouseMove(int x, int y) {
- if (dragging) {
- Point size = getSize();
- if (!(0 < x && x < size.x)) return;
- rightWidth = Math.max(0, size.x - x - rightDragDisplacement);
- if (rightMinWidth == SWT.DEFAULT) {
- Point minSize = right.computeSize(rightMinWidth, rightMinHeight);
- rightWidth = Math.max(minSize.x, rightWidth);
- } else {
- rightWidth = Math.max(rightMinWidth, rightWidth);
- }
- layout(false);
- return;
- }
- if (curveRect.contains(x, y)) {
- setCursor(resizeCursor);
- } else {
- setCursor(null);
- }
-}
-void onMouseUp () {
- dragging = false;
-}
-void onPaint(GC gc) {
-// Useful for debugging paint problems
-// {
-// Point size = getSize();
-// gc.setBackground(getDisplay().getSystemColor(SWT.COLOR_GREEN));
-// gc.fillRectangle(-10, -10, size.x+20, size.y+20);
-// }
- if (left == null && right == null) return;
- Point size = getSize();
- Color border1 = getDisplay().getSystemColor(BORDER1);
- if (bottom != null) {
- int y = bottom.getBounds().y - BORDER_STRIPE - 1;
- gc.setForeground(border1);
- gc.drawLine(0, y, size.x, y);
- }
- if (left == null || right == null) return;
- int[] line1 = new int[curve.length+6];
- int index = 0;
- int x = curveStart;
- line1[index++] = x + 1;
- line1[index++] = size.y - BORDER_STRIPE;
- for (int i = 0; i < curve.length/2; i++) {
- line1[index++]=x+curve[2*i];
- line1[index++]=curve[2*i+1];
- }
- line1[index++] = x + curve_width;
- line1[index++] = 0;
- line1[index++] = size.x;
- line1[index++] = 0;
-
- Color background = getBackground();
-
- if (getDisplay().getDepth() >= 15) {
- // Anti- aliasing
- int[] line2 = new int[line1.length];
- index = 0;
- for (int i = 0; i < line1.length/2; i++) {
- line2[index] = line1[index++] - 1;
- line2[index] = line1[index++];
- }
- int[] line3 = new int[line1.length];
- index = 0;
- for (int i = 0; i < line1.length/2; i++) {
- line3[index] = line1[index++] + 1;
- line3[index] = line1[index++];
- }
- RGB from = border1.getRGB();
- RGB to = background.getRGB();
- int red = from.red + 3*(to.red - from.red)/4;
- int green = from.green + 3*(to.green - from.green)/4;
- int blue = from.blue + 3*(to.blue - from.blue)/4;
- Color color = new Color(getDisplay(), red, green, blue);
- gc.setForeground(color);
- gc.drawPolyline(line2);
- gc.drawPolyline(line3);
- color.dispose();
-
- // draw tail fading to background
- int x1 = Math.max(0, curveStart - CURVE_TAIL);
- gc.setForeground(background);
- gc.setBackground(border1);
- gc.fillGradientRectangle(x1, size.y - BORDER_STRIPE, curveStart-x1+1, 1, false);
- } else {
- // draw solid tail
- int x1 = Math.max(0, curveStart - CURVE_TAIL);
- gc.setForeground(border1);
- gc.drawLine(x1, size.y - BORDER_STRIPE, curveStart+1, size.y - BORDER_STRIPE);
- }
-
- // draw border
- gc.setForeground(border1);
- gc.drawPolyline(line1);
-}
-
-void onResize() {
- updateCurve(getSize().y);
-}
-/**
-* Set the control that appears on the bottom side of the banner.
-* The bottom control is optional. Setting the bottom control to null will remove it from
-* the banner - however, the creator of the control must dispose of the control.
-*
-* @param control the control to be displayed on the bottom or null
-*
-* @exception SWTException - * Note: No Layout can be set on this Control because it already - * manages the size and position of its children. - *
- * - * @param layout the receiver's new layout or null - * - * @exception SWTExceptiontrue
if the CBanner should render itself in a simple, traditional style
- *
- * @exception SWTException - * CCombo was written to work around certain limitations in the native - * combo box. Specifically, on win32, the height of a CCombo can be set; - * attempts to set the height of a Combo are ignored. CCombo can be used - * anywhere that having the increased flexibility is more important than - * getting native L&F, but the decision should not be taken lightly. - * There is no is no strict requirement that CCombo look or behave - * the same as the native combo box. - *
- *
- * Note that although this class is a subclass of Composite
,
- * it does not make sense to add children to it, or set a layout on it.
- *
- * The style value is either one of the style constants defined in
- * class SWT
which is applicable to instances of this
- * class, or must be built by bitwise OR'ing together
- * (that is, using the int
"|" operator) two or more
- * of those SWT
style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- *
- * Note: To add an item at the end of the list, use the
- * result of calling getItemCount()
as the
- * index or use add(String)
.
- *
ModifyListener
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException SelectionListener
- * interface.
- *
- * widgetSelected
is called when the combo's list selection changes.
- * widgetDefaultSelected
is typically called when ENTER is pressed the combo's text area.
- *
VerifyListener
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException
- * Note: To clear the selected items in the receiver's list,
- * use deselectAll()
.
- *
- * The current selection is copied to the clipboard. - *
- * - * @exception SWTException
- * Note: To clear the selection in the receiver's text field,
- * use clearSelection()
.
- *
String
s which are the items
- * in the receiver's list.
- * - * 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. - *
- * - * @return the items in the receiver's list - * - * @exception SWTExceptiontrue
if the receiver's list is visible,
- * and false
otherwise.
- * - * 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. - *
- * - * @return the receiver's list's visibility state - * - * @exception SWTExceptionPoint
whose x coordinate is the start
- * of the selection in the receiver's text field, and whose y
- * coordinate is the end of the selection. The returned values
- * are zero-relative. An "empty" selection as indicated by
- * the the x and y coordinates having the same value.
- *
- * @return a point representing the selection start and end
- *
- * @exception SWTException setTextLimit()
, it will be the constant
- * Combo.LIMIT
.
- *
- * @return the text limit
- *
- * @exception SWTException - * The selected text is deleted from the widget - * and new text inserted from the clipboard. - *
- * - * @exception SWTException- * @exception SWTException
remove
'ing the old item at the index, and then
- * add
'ing the new item at that index.
- *
- * @param index the index for the item
- * @param string the new text for the item
- *
- * @exception IllegalArgumentException - * Note: No Layout can be set on this Control because it already - * manages the size and position of its children. - *
- * - * @param layout the receiver's new layout or null - * - * @exception SWTExceptiontrue
,
- * and marks it invisible otherwise.
- * - * 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. - *
- * - * @param visible the new visibility state - * - * @exception SWTException
- * Note: The text field in a Combo
is typically
- * only capable of displaying a single line of text. Thus,
- * setting the text to a string containing line breaks or
- * other special characters will probably cause it to
- * display incorrectly.
- *
- * If there is not enough space a CLabel uses the following strategy to fit the - * information into the available space: - *
- * ignores the indent in left align mode - * ignores the image and the gap - * shortens the text by replacing the center portion of the label with an ellipsis - * shortens the text by removing the center portion of the label - *- *
- *
- * IMPORTANT: This class is not intended to be subclassed. - *
- * - * @see SWT Example: CustomControlExample - * @see Sample code and further information - * @noextend This class is not intended to be subclassed by clients. - */ -public class CLabel extends Canvas { - - /** Gap between icon and text */ - private static final int GAP = 5; - /** Left and right margins */ - private static final int INDENT = 3; - /** a string inserted in the middle of text that has been shortened */ - private static final String ELLIPSIS = "..."; //$NON-NLS-1$ // could use the ellipsis glyph on some platforms "\u2026" - /** the alignment. Either CENTER, RIGHT, LEFT. Default is LEFT*/ - private int align = SWT.LEFT; - private int hIndent = INDENT; - private int vIndent = INDENT; - /** the current text */ - private String text; - /** the current icon */ - private Image image; - // The tooltip is used for two purposes - the application can set - // a tooltip or the tooltip can be used to display the full text when the - // the text has been truncated due to the label being too short. - // The appToolTip stores the tooltip set by the application. Control.tooltiptext - // contains whatever tooltip is currently being displayed. - private String appToolTipText; - - private Image backgroundImage; - private Color[] gradientColors; - private int[] gradientPercents; - private boolean gradientVertical; - private Color background; - private Listener disposeListener; - - private static int DRAW_FLAGS = SWT.DRAW_MNEMONIC | SWT.DRAW_TAB | SWT.DRAW_TRANSPARENT | SWT.DRAW_DELIMITER; - -/** - * Constructs a new instance of this class given its parent - * and a style value describing its behavior and appearance. - *
- * The style value is either one of the style constants defined in
- * class SWT
which is applicable to instances of this
- * class, or must be built by bitwise OR'ing together
- * (that is, using the int
"|" operator) two or more
- * of those SWT
style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- *
null
.
- *
- * @return the image of the label or null
- */
-public Image getImage() {
- //checkWidget();
- return image;
-}
-/**
- * Compute the minimum size.
- */
-private Point getTotalSize(Image image, String text) {
- Point size = new Point(0, 0);
-
- if (image != null) {
- Rectangle r = image.getBounds();
- size.x += r.width;
- size.y += r.height;
- }
-
- GC gc = new GC(this);
- if (text != null && text.length() > 0) {
- Point e = gc.textExtent(text, DRAW_FLAGS);
- size.x += e.x;
- size.y = Math.max(size.y, e.y);
- if (image != null) size.x += GAP;
- } else {
- size.y = Math.max(size.y, gc.getFontMetrics().getHeight());
- }
- gc.dispose();
-
- return size;
-}
-public int getStyle () {
- int style = super.getStyle();
- switch (align) {
- case SWT.RIGHT: style |= SWT.RIGHT; break;
- case SWT.CENTER: style |= SWT.CENTER; break;
- case SWT.LEFT: style |= SWT.LEFT; break;
- }
- return style;
-}
-
-/**
- * Return the Label's text.
- *
- * @return the text of the label or null
- */
-public String getText() {
- //checkWidget();
- return text;
-}
-public String getToolTipText () {
- checkWidget();
- return appToolTipText;
-}
-private void initAccessible() {
- Accessible accessible = getAccessible();
- accessible.addAccessibleListener(new AccessibleAdapter() {
- public void getName(AccessibleEvent e) {
- e.result = getText();
- }
-
- public void getHelp(AccessibleEvent e) {
- e.result = getToolTipText();
- }
-
- public void getKeyboardShortcut(AccessibleEvent e) {
- char mnemonic = _findMnemonic(CLabel.this.text);
- if (mnemonic != '\0') {
- e.result = "Alt+"+mnemonic; //$NON-NLS-1$
- }
- }
- });
-
- accessible.addAccessibleControlListener(new AccessibleControlAdapter() {
- public void getChildAtPoint(AccessibleControlEvent e) {
- e.childID = ACC.CHILDID_SELF;
- }
-
- public void getLocation(AccessibleControlEvent e) {
- Rectangle rect = getDisplay().map(getParent(), null, getBounds());
- e.x = rect.x;
- e.y = rect.y;
- e.width = rect.width;
- e.height = rect.height;
- }
-
- public void getChildCount(AccessibleControlEvent e) {
- e.detail = 0;
- }
-
- public void getRole(AccessibleControlEvent e) {
- e.detail = ACC.ROLE_LABEL;
- }
-
- public void getState(AccessibleControlEvent e) {
- e.detail = ACC.STATE_READONLY;
- }
- });
-}
-void onDispose(Event event) {
- removeListener(SWT.Dispose, disposeListener);
- notifyListeners(SWT.Dispose, event);
- event.type = SWT.None;
-
- gradientColors = null;
- gradientPercents = null;
- backgroundImage = null;
- text = null;
- image = null;
- appToolTipText = null;
-}
-void onMnemonic(TraverseEvent event) {
- char mnemonic = _findMnemonic(text);
- if (mnemonic == '\0') return;
- if (Character.toLowerCase(event.character) != mnemonic) return;
- Composite control = this.getParent();
- while (control != null) {
- Control [] children = control.getChildren();
- int index = 0;
- while (index < children.length) {
- if (children [index] == this) break;
- index++;
- }
- index++;
- if (index < children.length) {
- if (children [index].setFocus ()) {
- event.doit = true;
- event.detail = SWT.TRAVERSE_NONE;
- }
- }
- control = control.getParent();
- }
-}
-
-void onPaint(PaintEvent event) {
- Rectangle rect = getClientArea();
- if (rect.width == 0 || rect.height == 0) return;
-
- boolean shortenText = false;
- String t = text;
- Image img = image;
- int availableWidth = Math.max(0, rect.width - 2*hIndent);
- Point extent = getTotalSize(img, t);
- if (extent.x > availableWidth) {
- img = null;
- extent = getTotalSize(img, t);
- if (extent.x > availableWidth) {
- shortenText = true;
- }
- }
-
- GC gc = event.gc;
- String[] lines = text == null ? null : splitString(text);
-
- // shorten the text
- if (shortenText) {
- extent.x = 0;
- for(int i = 0; i < lines.length; i++) {
- Point e = gc.textExtent(lines[i], DRAW_FLAGS);
- if (e.x > availableWidth) {
- lines[i] = shortenText(gc, lines[i], availableWidth);
- extent.x = Math.max(extent.x, getTotalSize(null, lines[i]).x);
- } else {
- extent.x = Math.max(extent.x, e.x);
- }
- }
- if (appToolTipText == null) {
- super.setToolTipText(text);
- }
- } else {
- super.setToolTipText(appToolTipText);
- }
-
- // determine horizontal position
- int x = rect.x + hIndent;
- if (align == SWT.CENTER) {
- x = (rect.width - extent.x)/2;
- }
- if (align == SWT.RIGHT) {
- x = rect.width - hIndent - extent.x;
- }
-
- // draw a background image behind the text
- try {
- if (backgroundImage != null) {
- // draw a background image behind the text
- Rectangle imageRect = backgroundImage.getBounds();
- // tile image to fill space
- gc.setBackground(getBackground());
- gc.fillRectangle(rect);
- int xPos = 0;
- while (xPos < rect.width) {
- int yPos = 0;
- while (yPos < rect.height) {
- gc.drawImage(backgroundImage, xPos, yPos);
- yPos += imageRect.height;
- }
- xPos += imageRect.width;
- }
- } else if (gradientColors != null) {
- // draw a gradient behind the text
- final Color oldBackground = gc.getBackground();
- if (gradientColors.length == 1) {
- if (gradientColors[0] != null) gc.setBackground(gradientColors[0]);
- gc.fillRectangle(0, 0, rect.width, rect.height);
- } else {
- final Color oldForeground = gc.getForeground();
- Color lastColor = gradientColors[0];
- if (lastColor == null) lastColor = oldBackground;
- int pos = 0;
- for (int i = 0; i < gradientPercents.length; ++i) {
- gc.setForeground(lastColor);
- lastColor = gradientColors[i + 1];
- if (lastColor == null) lastColor = oldBackground;
- gc.setBackground(lastColor);
- if (gradientVertical) {
- final int gradientHeight = (gradientPercents[i] * rect.height / 100) - pos;
- gc.fillGradientRectangle(0, pos, rect.width, gradientHeight, true);
- pos += gradientHeight;
- } else {
- final int gradientWidth = (gradientPercents[i] * rect.width / 100) - pos;
- gc.fillGradientRectangle(pos, 0, gradientWidth, rect.height, false);
- pos += gradientWidth;
- }
- }
- if (gradientVertical && pos < rect.height) {
- gc.setBackground(getBackground());
- gc.fillRectangle(0, pos, rect.width, rect.height - pos);
- }
- if (!gradientVertical && pos < rect.width) {
- gc.setBackground(getBackground());
- gc.fillRectangle(pos, 0, rect.width - pos, rect.height);
- }
- gc.setForeground(oldForeground);
- }
- gc.setBackground(oldBackground);
- } else {
- if (background != null || (getStyle() & SWT.DOUBLE_BUFFERED) == 0) {
- gc.setBackground(getBackground());
- gc.fillRectangle(rect);
- }
- }
- } catch (SWTException e) {
- if ((getStyle() & SWT.DOUBLE_BUFFERED) == 0) {
- gc.setBackground(getBackground());
- gc.fillRectangle(rect);
- }
- }
-
- // draw border
- int style = getStyle();
- if ((style & SWT.SHADOW_IN) != 0 || (style & SWT.SHADOW_OUT) != 0) {
- paintBorder(gc, rect);
- }
-
- // draw the image
- if (img != null) {
- Rectangle imageRect = img.getBounds();
- gc.drawImage(img, 0, 0, imageRect.width, imageRect.height,
- x, (rect.height-imageRect.height)/2, imageRect.width, imageRect.height);
- x += imageRect.width + GAP;
- extent.x -= imageRect.width + GAP;
- }
- // draw the text
- if (lines != null) {
- int lineHeight = gc.getFontMetrics().getHeight();
- int textHeight = lines.length * lineHeight;
- int lineY = Math.max(vIndent, rect.y + (rect.height - textHeight) / 2);
- gc.setForeground(getForeground());
- for (int i = 0; i < lines.length; i++) {
- int lineX = x;
- if (lines.length > 1) {
- if (align == SWT.CENTER) {
- int lineWidth = gc.textExtent(lines[i], DRAW_FLAGS).x;
- lineX = x + Math.max(0, (extent.x - lineWidth) / 2);
- }
- if (align == SWT.RIGHT) {
- int lineWidth = gc.textExtent(lines[i], DRAW_FLAGS).x;
- lineX = Math.max(x, rect.x + rect.width - hIndent - lineWidth);
- }
- }
- gc.drawText(lines[i], lineX, lineY, DRAW_FLAGS);
- lineY += lineHeight;
- }
- }
-}
-/**
- * Paint the Label's border.
- */
-private void paintBorder(GC gc, Rectangle r) {
- Display disp= getDisplay();
-
- Color c1 = null;
- Color c2 = null;
-
- int style = getStyle();
- if ((style & SWT.SHADOW_IN) != 0) {
- c1 = disp.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW);
- c2 = disp.getSystemColor(SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW);
- }
- if ((style & SWT.SHADOW_OUT) != 0) {
- c1 = disp.getSystemColor(SWT.COLOR_WIDGET_LIGHT_SHADOW);
- c2 = disp.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW);
- }
-
- if (c1 != null && c2 != null) {
- gc.setLineWidth(1);
- drawBevelRect(gc, r.x, r.y, r.width-1, r.height-1, c1, c2);
- }
-}
-/**
- * Set the alignment of the CLabel.
- * Use the values LEFT, CENTER and RIGHT to align image and text within the available space.
- *
- * @param align the alignment style of LEFT, RIGHT or CENTER
- *
- * @exception SWTException For example, to draw a gradient that varies from dark blue to blue and then to - * white and stays white for the right half of the label, use the following call - * to setBackground:
- *- * clabel.setBackground(new Color[]{display.getSystemColor(SWT.COLOR_DARK_BLUE), - * display.getSystemColor(SWT.COLOR_BLUE), - * display.getSystemColor(SWT.COLOR_WHITE), - * display.getSystemColor(SWT.COLOR_WHITE)}, - * new int[] {25, 50, 100}); - *- * - * @param colors an array of Color that specifies the colors to appear in the gradient - * in order of appearance from left to right; The value
null
- * clears the background gradient; the value null
can be used
- * inside the array of Color to specify the background color.
- * @param percents an array of integers between 0 and 100 specifying the percent of the width
- * of the widget at which the color should change; the size of the percents
- * array must be one less than the size of the colors array.
- *
- * @exception SWTException For example, to draw a gradient that varies from dark blue to white in the vertical, - * direction use the following call - * to setBackground:
- *- * clabel.setBackground(new Color[]{display.getSystemColor(SWT.COLOR_DARK_BLUE), - * display.getSystemColor(SWT.COLOR_WHITE)}, - * new int[] {100}, true); - *- * - * @param colors an array of Color that specifies the colors to appear in the gradient - * in order of appearance from left/top to right/bottom; The value
null
- * clears the background gradient; the value null
can be used
- * inside the array of Color to specify the background color.
- * @param percents an array of integers between 0 and 100 specifying the percent of the width/height
- * of the widget at which the color should change; the size of the percents
- * array must be one less than the size of the colors array.
- * @param vertical indicate the direction of the gradient. True is vertical and false is horizontal.
- *
- * @exception SWTException null
clears it.
- *
- * @param image the image to be displayed in the label or null
- *
- * @exception SWTException null
clears it.
- * - * Mnemonics are indicated by an '&' that causes the next - * character to be the mnemonic. When the user presses a - * key sequence that matches the mnemonic, focus is assigned - * to the control that follows the label. On most platforms, - * the mnemonic appears underlined but may be emphasised in a - * platform specific manner. The mnemonic indicator character - * '&' can be escaped by doubling it in the string, causing - * a single '&' to be displayed. - *
- * - * @param text the text to be displayed in the label or null - * - * @exception SWTExceptiont
so that its length doesn't exceed
- * the given width. The default implementation replaces characters in the
- * center of the original string with an ellipsis ("...").
- * Override if you need a different strategy.
- *
- * @param gc the gc to use for text measurement
- * @param t the text to shorten
- * @param width the width to shorten the text to, in pixels
- * @return the shortened text
- */
-protected String shortenText(GC gc, String t, int width) {
- if (t == null) return null;
- int w = gc.textExtent(ELLIPSIS, DRAW_FLAGS).x;
- if (width<=w) return t;
- int l = t.length();
- int max = l/2;
- int min = 0;
- int mid = (max+min)/2 - 1;
- if (mid <= 0) return t;
- TextLayout layout = new TextLayout (getDisplay());
- layout.setText(t);
- mid = validateOffset(layout, mid);
- while (min < mid && mid < max) {
- String s1 = t.substring(0, mid);
- String s2 = t.substring(validateOffset(layout, l-mid), l);
- int l1 = gc.textExtent(s1, DRAW_FLAGS).x;
- int l2 = gc.textExtent(s2, DRAW_FLAGS).x;
- if (l1+w+l2 > width) {
- max = mid;
- mid = validateOffset(layout, (max+min)/2);
- } else if (l1+w+l2 < width) {
- min = mid;
- mid = validateOffset(layout, (max+min)/2);
- } else {
- min = max;
- }
- }
- String result = mid == 0 ? t : t.substring(0, mid) + ELLIPSIS + t.substring(validateOffset(layout, l-mid), l);
- layout.dispose();
- return result;
-}
-int validateOffset(TextLayout layout, int offset) {
- int nextOffset = layout.getNextOffset(offset, SWT.MOVEMENT_CLUSTER);
- if (nextOffset != offset) return layout.getPreviousOffset(nextOffset, SWT.MOVEMENT_CLUSTER);
- return offset;
-}
-private String[] splitString(String text) {
- String[] lines = new String[1];
- int start = 0, pos;
- do {
- pos = text.indexOf('\n', start);
- if (pos == -1) {
- lines[lines.length - 1] = text.substring(start);
- } else {
- boolean crlf = (pos > 0) && (text.charAt(pos - 1) == '\r');
- lines[lines.length - 1] = text.substring(start, pos - (crlf ? 1 : 0));
- start = pos + 1;
- String[] newLines = new String[lines.length+1];
- System.arraycopy(lines, 0, newLines, 0, lines.length);
- lines = newLines;
- }
- } while (pos != -1);
- return lines;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CLayoutData.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CLayoutData.java
deleted file mode 100644
index 7af979e690..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CLayoutData.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.custom;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.widgets.*;
-
-class CLayoutData {
-
- int defaultWidth = -1, defaultHeight = -1;
- int currentWhint, currentHhint, currentWidth = -1, currentHeight = -1;
-
-Point computeSize (Control control, int wHint, int hHint, boolean flushCache) {
- if (flushCache) flushCache();
- if (wHint == SWT.DEFAULT && hHint == SWT.DEFAULT) {
- if (defaultWidth == -1 || defaultHeight == -1) {
- Point size = control.computeSize (wHint, hHint, flushCache);
- defaultWidth = size.x;
- defaultHeight = size.y;
- }
- return new Point(defaultWidth, defaultHeight);
- }
- if (currentWidth == -1 || currentHeight == -1 || wHint != currentWhint || hHint != currentHhint) {
- Point size = control.computeSize (wHint, hHint, flushCache);
- currentWhint = wHint;
- currentHhint = hHint;
- currentWidth = size.x;
- currentHeight = size.y;
- }
- return new Point(currentWidth, currentHeight);
-}
-void flushCache () {
- defaultWidth = defaultHeight = -1;
- currentWidth = currentHeight = -1;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolder.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolder.java
deleted file mode 100755
index 9d26184c96..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolder.java
+++ /dev/null
@@ -1,4031 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.custom;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.accessibility.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.widgets.*;
-
-/**
- *
- * Instances of this class implement the notebook user interface
- * metaphor. It allows the user to select a notebook page from
- * set of pages.
- *
- * The item children that may be added to instances of this class
- * must be of type CTabItem
.
- * Control
children are created and then set into a
- * tab item using CTabItem#setControl
.
- *
- * Note that although this class is a subclass of Composite
,
- * it does not make sense to set a layout on it.
- *
- *
- * Note: Only one of the styles TOP and BOTTOM - * may be specified. - *
- * IMPORTANT: This class is not intended to be subclassed. - *
- * - * @see CTabFolder, CTabItem snippets - * @see SWT Example: CustomControlExample - * @see Sample code and further information - * @noextend This class is not intended to be subclassed by clients. - */ - -public class CTabFolder extends Composite { - - /** - * marginWidth specifies the number of pixels of horizontal margin - * that will be placed along the left and right edges of the form. - * - * The default value is 0. - */ - public int marginWidth = 0; - /** - * marginHeight specifies the number of pixels of vertical margin - * that will be placed along the top and bottom edges of the form. - * - * The default value is 0. - */ - public int marginHeight = 0; - - /** - * A multiple of the tab height that specifies the minimum width to which a tab - * will be compressed before scrolling arrows are used to navigate the tabs. - * - * NOTE This field is badly named and can not be fixed for backwards compatibility. - * It should not be capitalized. - * - * @deprecated This field is no longer used. See setMinimumCharacters(int) - */ - public int MIN_TAB_WIDTH = 4; - - /** - * Color of innermost line of drop shadow border. - * - * NOTE This field is badly named and can not be fixed for backwards compatibility. - * It should be capitalized. - * - * @deprecated drop shadow border is no longer drawn in 3.0 - */ - public static RGB borderInsideRGB = new RGB (132, 130, 132); - /** - * Color of middle line of drop shadow border. - * - * NOTE This field is badly named and can not be fixed for backwards compatibility. - * It should be capitalized. - * - * @deprecated drop shadow border is no longer drawn in 3.0 - */ - public static RGB borderMiddleRGB = new RGB (143, 141, 138); - /** - * Color of outermost line of drop shadow border. - * - * NOTE This field is badly named and can not be fixed for backwards compatibility. - * It should be capitalized. - * - * @deprecated drop shadow border is no longer drawn in 3.0 - */ - public static RGB borderOutsideRGB = new RGB (171, 168, 165); - - /* sizing, positioning */ - int xClient, yClient; - boolean onBottom = false; - boolean single = false; - boolean simple = true; - int fixedTabHeight = SWT.DEFAULT; - int tabHeight; - int minChars = 20; - - /* item management */ - CTabItem items[] = new CTabItem[0]; - int firstIndex = -1; // index of the left most visible tab. - int selectedIndex = -1; - int[] priority = new int[0]; - boolean mru = false; - Listener listener; - boolean ignoreTraverse; - - /* External Listener management */ - CTabFolder2Listener[] folderListeners = new CTabFolder2Listener[0]; - // support for deprecated listener mechanism - CTabFolderListener[] tabListeners = new CTabFolderListener[0]; - - /* Selected item appearance */ - Image selectionBgImage; - Color[] selectionGradientColors; - int[] selectionGradientPercents; - boolean selectionGradientVertical; - Color selectionForeground; - Color selectionBackground; //selection fade end - Color selectionFadeStart; - - Color selectionHighlightGradientBegin = null; //null == no highlight - //Although we are given new colours all the time to show different states (active, etc), - //some of which may have a highlight and some not, we'd like to retain the highlight colours - //as a cache so that we can reuse them if we're again told to show the highlight. - //We are relying on the fact that only one tab state usually gets a highlight, so only - //a single cache is required. If that happens to not be true, cache simply becomes less effective, - //but we don't leak colours. - Color[] selectionHighlightGradientColorsCache = null; //null is a legal value, check on access - - /* Unselected item appearance */ - Color[] gradientColors; - int[] gradientPercents; - boolean gradientVertical; - boolean showUnselectedImage = true; - - // close, min/max and chevron buttons - Color fillColor; - boolean showClose = false; - boolean showUnselectedClose = true; - - Rectangle chevronRect = new Rectangle(0, 0, 0, 0); - int chevronImageState = NORMAL; - boolean showChevron = false; - Menu showMenu; - - boolean showMin = false; - Rectangle minRect = new Rectangle(0, 0, 0, 0); - boolean minimized = false; - int minImageState = NORMAL; - - boolean showMax = false; - Rectangle maxRect = new Rectangle(0, 0, 0, 0); - boolean maximized = false; - int maxImageState = NORMAL; - - Control topRight; - Rectangle topRightRect = new Rectangle(0, 0, 0, 0); - int topRightAlignment = SWT.RIGHT; - - // borders and shapes - int borderLeft = 0; - int borderRight = 0; - int borderTop = 0; - int borderBottom = 0; - - int highlight_margin = 0; - int highlight_header = 0; - - int[] curve; - int[] topCurveHighlightStart; - int[] topCurveHighlightEnd; - int curveWidth = 0; - int curveIndent = 0; - - // when disposing CTabFolder, don't try to layout the items or - // change the selection as each child is destroyed. - boolean inDispose = false; - - // keep track of size changes in order to redraw only affected area - // on Resize - Point oldSize; - Font oldFont; - - // internal constants - static final int DEFAULT_WIDTH = 64; - static final int DEFAULT_HEIGHT = 64; - static final int BUTTON_SIZE = 18; - - static final int[] TOP_LEFT_CORNER = new int[] {0,6, 1,5, 1,4, 4,1, 5,1, 6,0}; - - //TOP_LEFT_CORNER_HILITE is laid out in reverse (ie. top to bottom) - //so can fade in same direction as right swoop curve - static final int[] TOP_LEFT_CORNER_HILITE = new int[] {5,2, 4,2, 3,3, 2,4, 2,5, 1,6}; - - static final int[] TOP_RIGHT_CORNER = new int[] {-6,0, -5,1, -4,1, -1,4, -1,5, 0,6}; - static final int[] BOTTOM_LEFT_CORNER = new int[] {0,-6, 1,-5, 1,-4, 4,-1, 5,-1, 6,0}; - static final int[] BOTTOM_RIGHT_CORNER = new int[] {-6,0, -5,-1, -4,-1, -1,-4, -1,-5, 0,-6}; - - static final int[] SIMPLE_TOP_LEFT_CORNER = new int[] {0,2, 1,1, 2,0}; - static final int[] SIMPLE_TOP_RIGHT_CORNER = new int[] {-2,0, -1,1, 0,2}; - static final int[] SIMPLE_BOTTOM_LEFT_CORNER = new int[] {0,-2, 1,-1, 2,0}; - static final int[] SIMPLE_BOTTOM_RIGHT_CORNER = new int[] {-2,0, -1,-1, 0,-2}; - static final int[] SIMPLE_UNSELECTED_INNER_CORNER = new int[] {0,0}; - - static final int[] TOP_LEFT_CORNER_BORDERLESS = new int[] {0,6, 1,5, 1,4, 4,1, 5,1, 6,0}; - static final int[] TOP_RIGHT_CORNER_BORDERLESS = new int[] {-7,0, -6,1, -5,1, -2,4, -2,5, -1,6}; - static final int[] BOTTOM_LEFT_CORNER_BORDERLESS = new int[] {0,-6, 1,-6, 1,-5, 2,-4, 4,-2, 5,-1, 6,-1, 6,0}; - static final int[] BOTTOM_RIGHT_CORNER_BORDERLESS = new int[] {-7,0, -7,-1, -6,-1, -5,-2, -3,-4, -2,-5, -2,-6, -1,-6}; - - static final int[] SIMPLE_TOP_LEFT_CORNER_BORDERLESS = new int[] {0,2, 1,1, 2,0}; - static final int[] SIMPLE_TOP_RIGHT_CORNER_BORDERLESS= new int[] {-3,0, -2,1, -1,2}; - static final int[] SIMPLE_BOTTOM_LEFT_CORNER_BORDERLESS = new int[] {0,-3, 1,-2, 2,-1, 3,0}; - static final int[] SIMPLE_BOTTOM_RIGHT_CORNER_BORDERLESS = new int[] {-4,0, -3,-1, -2,-2, -1,-3}; - - static final int SELECTION_FOREGROUND = SWT.COLOR_LIST_FOREGROUND; - static final int SELECTION_BACKGROUND = SWT.COLOR_LIST_BACKGROUND; - static final int BORDER1_COLOR = SWT.COLOR_WIDGET_NORMAL_SHADOW; - static final int FOREGROUND = SWT.COLOR_WIDGET_FOREGROUND; - static final int BACKGROUND = SWT.COLOR_WIDGET_BACKGROUND; - static final int BUTTON_BORDER = SWT.COLOR_WIDGET_DARK_SHADOW; - static final int BUTTON_FILL = SWT.COLOR_LIST_BACKGROUND; - - static final int NONE = 0; - static final int NORMAL = 1; - static final int HOT = 2; - static final int SELECTED = 3; - static final RGB CLOSE_FILL = new RGB(252, 160, 160); - - static final int CHEVRON_CHILD_ID = 0; - static final int MINIMIZE_CHILD_ID = 1; - static final int MAXIMIZE_CHILD_ID = 2; - static final int EXTRA_CHILD_ID_COUNT = 3; - - -/** - * Constructs a new instance of this class given its parent - * and a style value describing its behavior and appearance. - *
- * The style value is either one of the style constants defined in
- * class SWT
which is applicable to instances of this
- * class, or must be built by bitwise OR'ing together
- * (that is, using the int
"|" operator) two or more
- * of those SWT
style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- *
SelectionListener
- * interface.
- *
- * widgetSelected
is called when the user changes the selected tab.
- * widgetDefaultSelected
is not called.
- *
true
if the receiver's border is visible.
- *
- * @return the receiver's border visibility state
- *
- * @exception SWTException true
if the receiver is minimized.
- *
- * @return the receiver's minimized state
- *
- * @exception SWTException true
if the minimize button
- * is visible.
- *
- * @return the visibility of the minimized button
- *
- * @exception SWTException true
if the receiver is maximized.
- * - * - * @return the receiver's maximized state - * - * @exception SWTException
true
if the maximize button
- * is visible.
- *
- * @return the visibility of the maximized button
- *
- * @exception SWTException true
if the receiver displays most
- * recently used tabs and false
otherwise.
- * - * When there is not enough horizontal space to show all the tabs, - * by default, tabs are shown sequentially from left to right in - * order of their index. When the MRU visibility is turned on, - * the tabs that are visible will be the tabs most recently selected. - * Tabs will still maintain their left to right order based on index - * but only the most recently selected tabs are visible. - *
- * For example, consider a CTabFolder that contains "Tab 1", "Tab 2", - * "Tab 3" and "Tab 4" (in order by index). The user selects - * "Tab 1" and then "Tab 3". If the CTabFolder is now - * compressed so that only two tabs are visible, by default, - * "Tab 2" and "Tab 3" will be shown ("Tab 3" since it is currently - * selected and "Tab 2" because it is the previous item in index order). - * If MRU visibility is enabled, the two visible tabs will be "Tab 1" - * and "Tab 3" (in that order from left to right).
- * - * @return the receiver's header's visibility state - * - * @exception SWTExceptiontrue
if the CTabFolder is rendered
- * with a simple, traditional shape.
- *
- * @return true
if the CTabFolder is rendered with a simple shape
- *
- * @since 3.0
- */
-public boolean getSimple() {
- checkWidget();
- return simple;
-}
-/**
- * Returns true
if the CTabFolder only displays the selected tab
- * and false
if the CTabFolder displays multiple tabs.
- *
- * @return true
if the CTabFolder only displays the selected tab and false
if the CTabFolder displays multiple tabs
- *
- * @since 3.0
- */
-public boolean getSingle() {
- checkWidget();
- return single;
-}
-
-public int getStyle() {
- int style = super.getStyle();
- style &= ~(SWT.TOP | SWT.BOTTOM);
- style |= onBottom ? SWT.BOTTOM : SWT.TOP;
- style &= ~(SWT.SINGLE | SWT.MULTI);
- style |= single ? SWT.SINGLE : SWT.MULTI;
- if (borderLeft != 0) style |= SWT.BORDER;
- style &= ~SWT.CLOSE;
- if (showClose) style |= SWT.CLOSE;
- return style;
-}
-/**
- * Returns the height of the tab
- *
- * @return the height of the tab
- *
- * @exception SWTException true
if the close button appears
- * when the user hovers over an unselected tabs.
- *
- * @return true
if the close button appears on unselected tabs
- *
- * @since 3.0
- */
-public boolean getUnselectedCloseVisible() {
- checkWidget();
- return showUnselectedClose;
-}
-/**
- * Returns true
if an image appears
- * in unselected tabs.
- *
- * @return true
if an image appears in unselected tabs
- *
- * @since 3.0
- */
-public boolean getUnselectedImageVisible() {
- checkWidget();
- return showUnselectedImage;
-}
-/**
- * Return the index of the specified tab or -1 if the tab is not
- * in the receiver.
- *
- * @param item the tab item for which the index is required
- *
- * @return the index of the specified tab item or -1
- *
- * @exception IllegalArgumentException - * cfolder.setBackground(new Color[]{display.getSystemColor(SWT.COLOR_DARK_BLUE), - * display.getSystemColor(SWT.COLOR_BLUE), - * display.getSystemColor(SWT.COLOR_WHITE), - * display.getSystemColor(SWT.COLOR_WHITE)}, - * new int[] {25, 50, 100}); - *- * - * @param colors an array of Color that specifies the colors to appear in the gradient - * in order of appearance left to right. The value
null
clears the
- * background gradient. The value null
can be used inside the array of
- * Color to specify the background color.
- * @param percents an array of integers between 0 and 100 specifying the percent of the width
- * of the widget at which the color should change. The size of the percents array must be one
- * less than the size of the colors array.
- *
- * @exception SWTException - * cfolder.setBackground(new Color[]{display.getSystemColor(SWT.COLOR_DARK_BLUE), - * display.getSystemColor(SWT.COLOR_BLUE), - * display.getSystemColor(SWT.COLOR_WHITE), - * display.getSystemColor(SWT.COLOR_WHITE)}, - * new int[] {25, 50, 100}, true); - *- * - * @param colors an array of Color that specifies the colors to appear in the gradient - * in order of appearance left to right. The value
null
clears the
- * background gradient. The value null
can be used inside the array of
- * Color to specify the background color.
- * @param percents an array of integers between 0 and 100 specifying the percent of the width
- * of the widget at which the color should change. The size of the percents array must be one
- * less than the size of the colors array.
- *
- * @param vertical indicate the direction of the gradient. True is vertical and false is horizontal.
- *
- * @exception SWTException true
,
- * and marks it invisible otherwise.
- *
- * @param visible the new visibility state
- *
- * @exception SWTException - * Note: No Layout can be set on this Control because it already - * manages the size and position of its children. - *
- * - * @param layout the receiver's new layout or null - * - * @exception SWTExceptiontrue
,
- * and marks it invisible otherwise.
- *
- * @param visible the new visibility state
- *
- * @exception SWTException - * For example, consider a CTabFolder that contains "Tab 1", "Tab 2", - * "Tab 3" and "Tab 4" (in order by index). The user selects - * "Tab 1" and then "Tab 3". If the CTabFolder is now - * compressed so that only two tabs are visible, by default, - * "Tab 2" and "Tab 3" will be shown ("Tab 3" since it is currently - * selected and "Tab 2" because it is the previous item in index order). - * If MRU visibility is enabled, the two visible tabs will be "Tab 1" - * and "Tab 3" (in that order from left to right).
- * - * @param show the new visibility state - * - * @exception SWTException- * cfolder.setBackground(new Color[]{display.getSystemColor(SWT.COLOR_DARK_BLUE), - * display.getSystemColor(SWT.COLOR_BLUE), - * display.getSystemColor(SWT.COLOR_WHITE), - * display.getSystemColor(SWT.COLOR_WHITE)}, - * new int[] {25, 50, 100}); - *- * - * @param colors an array of Color that specifies the colors to appear in the gradient - * in order of appearance left to right. The value
null
clears the
- * background gradient. The value null
can be used inside the array of
- * Color to specify the background color.
- * @param percents an array of integers between 0 and 100 specifying the percent of the width
- * of the widget at which the color should change. The size of the percents array must be one
- * less than the size of the colors array.
- *
- * @exception SWTException - * cfolder.setBackground(new Color[]{display.getSystemColor(SWT.COLOR_DARK_BLUE), - * display.getSystemColor(SWT.COLOR_BLUE), - * display.getSystemColor(SWT.COLOR_WHITE), - * display.getSystemColor(SWT.COLOR_WHITE)}, - * new int[] {25, 50, 100}, true); - *- * - * @param colors an array of Color that specifies the colors to appear in the gradient - * in order of appearance left to right. The value
null
clears the
- * background gradient. The value null
can be used inside the array of
- * Color to specify the background color.
- * @param percents an array of integers between 0 and 100 specifying the percent of the width
- * of the widget at which the color should change. The size of the percents array must be one
- * less than the size of the colors array.
- *
- * @param vertical indicate the direction of the gradient. True is vertical and false is horizontal.
- *
- * @exception SWTException true
if the CTabFolder should render itself in a simple, traditional style
- *
- * @exception SWTException true
if only the selected tab should be displayed otherwise, multiple tabs will be shown.
- *
- * @exception SWTException SWT.TOP
for tabs along the top or SWT.BOTTOM
for tabs along the bottom
- *
- * @exception SWTException
- * The alignment parameter sets the layout of the control in the tab area.
- * SWT.RIGHT
will cause the control to be positioned on the far
- * right of the folder and it will have its default size. SWT.FILL
- * will size the control to fill all the available space to the right of the
- * last tab. If there is no available space, the control will not be visible.
- *
SWT.RIGHT
or SWT.FILL
- *
- * @exception SWTException true
makes the close button appear
- *
- * @exception SWTException true
makes the image appear
- *
- * @exception SWTException CTabFolder2Listener
interface.
- *
- * Classes that wish to deal with CTabFolderEvent
s can
- * extend this class and override only the methods which they are
- * interested in.
- *
- * The default behaviour is to close the CTabItem. - *
- * - * @param event an event indicating the item being closed - */ -public void close(CTabFolderEvent event){} - -/** - * Sent when the user clicks on the minimize button of a CTabFolder. - *- * The default behaviour is to do nothing. - *
- * - * @param event an event containing information about the minimize - */ -public void minimize(CTabFolderEvent event){} - -/** - * Sent when the user clicks on the maximize button of a CTabFolder. - *- * The default behaviour is to do nothing. - *
- * - * @param event an event containing information about the maximize - */ -public void maximize(CTabFolderEvent event){} - -/** - * Sent when the user clicks on the restore button of a CTabFolder. - *- * The default behaviour is to do nothing. - *
- * - * @param event an event containing information about the restore - */ -public void restore(CTabFolderEvent event){} - -/** - * Sent when the user clicks on the chevron button of a CTabFolder. - *- * The default behaviour is to show a list of items that are not currently - * visible and to change the selection based on the item selected from the list. - *
- * - * @param event an event containing information about the show list - */ -public void showList(CTabFolderEvent event){} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolder2Listener.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolder2Listener.java deleted file mode 100644 index 7e2e17862f..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolder2Listener.java +++ /dev/null @@ -1,112 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.custom; - -import org.eclipse.swt.internal.*; - -/** - * Classes which implement this interface provide methods - * that deal with the events that are generated by the CTabFolder - * control. - *
- * After creating an instance of a class that implements
- * this interface it can be added to a CTabFolder using the
- * addCTabFolder2Listener
method and removed using
- * the removeCTabFolder2Listener
method. When
- * events occurs in a CTabFolder the appropriate method
- * will be invoked.
- *
false
and displaying a selection list.
- *
- * @param event an event containing information about the show list
- *
- * @see CTabFolder#setSelection(CTabItem)
- */
-public void showList(CTabFolderEvent event);
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolderAdapter.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolderAdapter.java
deleted file mode 100755
index 85f210a938..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolderAdapter.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.custom;
-
-
-/**
- * This adapter class provides a default implementation for the
- * method described by the CTabFolderListener
interface.
- *
- * @see CTabFolderListener
- * @see CTabFolderEvent
- * @see Sample code and further information
- */
-public class CTabFolderAdapter implements CTabFolderListener {
- public void itemClosed(CTabFolderEvent event){}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolderEvent.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolderEvent.java
deleted file mode 100755
index 99394bf37a..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolderEvent.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.custom;
-
-
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.widgets.*;
-
-/**
- * This event is sent when an event is generated in the CTabFolder.
- *
- * @see Sample code and further information
- */
-public class CTabFolderEvent extends TypedEvent {
- /**
- * The tab item for the operation.
- */
- public Widget item;
-
- /**
- * A flag indicating whether the operation should be allowed.
- * Setting this field to false
will cancel the operation.
- * Applies to the close and showList events.
- */
- public boolean doit;
-
- /**
- * The widget-relative, x coordinate of the chevron button
- * at the time of the event. Applies to the showList event.
- *
- * @since 3.0
- */
- public int x;
- /**
- * The widget-relative, y coordinate of the chevron button
- * at the time of the event. Applies to the showList event.
- *
- * @since 3.0
- */
- public int y;
- /**
- * The width of the chevron button at the time of the event.
- * Applies to the showList event.
- *
- * @since 3.0
- */
- public int width;
- /**
- * The height of the chevron button at the time of the event.
- * Applies to the showList event.
- *
- * @since 3.0
- */
- public int height;
-
- static final long serialVersionUID = 3760566386225066807L;
-
-/**
- * Constructs a new instance of this class.
- *
- * @param w the widget that fired the event
- */
-CTabFolderEvent(Widget w) {
- super(w);
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the event
- */
-public String toString() {
- String string = super.toString ();
- return string.substring (0, string.length() - 1) // remove trailing '}'
- + " item=" + item
- + " doit=" + doit
- + " x=" + x
- + " y=" + y
- + " width=" + width
- + " height=" + height
- + "}";
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolderLayout.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolderLayout.java
deleted file mode 100644
index e01fac6e55..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolderLayout.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.custom;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.widgets.*;
-
-/**
- * This class provides the layout for CTabFolder
- *
- * @see CTabFolder
- */
-class CTabFolderLayout extends Layout {
-protected Point computeSize(Composite composite, int wHint, int hHint, boolean flushCache) {
- CTabFolder folder = (CTabFolder)composite;
- CTabItem[] items = folder.items;
- // preferred width of tab area to show all tabs
- int tabW = 0;
- GC gc = new GC(folder);
- for (int i = 0; i < items.length; i++) {
- if (folder.single) {
- tabW = Math.max(tabW, items[i].preferredWidth(gc, true, false));
- } else {
- tabW += items[i].preferredWidth(gc, i == folder.selectedIndex, false);
- }
- }
- gc.dispose();
- tabW += 3;
- if (folder.showMax) tabW += CTabFolder.BUTTON_SIZE;
- if (folder.showMin) tabW += CTabFolder.BUTTON_SIZE;
- if (folder.single) tabW += 3*CTabFolder.BUTTON_SIZE/2; //chevron
- if (folder.topRight != null) {
- Point pt = folder.topRight.computeSize(SWT.DEFAULT, folder.tabHeight, flushCache);
- tabW += 3 + pt.x;
- }
- if (!folder.single && !folder.simple) tabW += folder.curveWidth - 2*folder.curveIndent;
-
- int controlW = 0;
- int controlH = 0;
- // preferred size of controls in tab items
- for (int i = 0; i < items.length; i++) {
- Control control = items[i].getControl();
- if (control != null && !control.isDisposed()){
- Point size = control.computeSize (wHint, hHint, flushCache);
- controlW = Math.max (controlW, size.x);
- controlH = Math.max (controlH, size.y);
- }
- }
-
- int minWidth = Math.max(tabW, controlW);
- int minHeight = (folder.minimized) ? 0 : controlH;
- if (minWidth == 0) minWidth = CTabFolder.DEFAULT_WIDTH;
- if (minHeight == 0) minHeight = CTabFolder.DEFAULT_HEIGHT;
-
- if (wHint != SWT.DEFAULT) minWidth = wHint;
- if (hHint != SWT.DEFAULT) minHeight = hHint;
-
- return new Point (minWidth, minHeight);
-}
-protected boolean flushCache(Control control) {
- return true;
-}
-protected void layout(Composite composite, boolean flushCache) {
- CTabFolder folder = (CTabFolder)composite;
- // resize content
- if (folder.selectedIndex != -1) {
- Control control = folder.items[folder.selectedIndex].getControl();
- if (control != null && !control.isDisposed()) {
- control.setBounds(folder.getClientArea());
- }
- }
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolderListener.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolderListener.java
deleted file mode 100755
index 4fdeab51fe..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolderListener.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.custom;
-
-import org.eclipse.swt.internal.*;
-
-/**
- * Classes which implement this interface provide a method
- * that deals with events generated in the CTabFolder.
- *
- * After creating an instance of a class that implements
- * this interface it can be added to a CTabFolder using the
- * addCTabFolderListener
method and removed using
- * the removeCTabFolderListener
method. When a
- * tab item is closed, the itemClosed method will be invoked.
- *
- * IMPORTANT: This class is not intended to be subclassed. - *
- * - * @see CTabFolder, CTabItem snippets - * @see Sample code and further information - * @noextend This class is not intended to be subclassed by clients. - */ -public class CTabItem extends Item { - CTabFolder parent; - int x,y,width,height = 0; - Control control; // the tab page - - String toolTipText; - String shortenedText; - int shortenedTextWidth; - - // Appearance - Font font; - Image disabledImage; - - Rectangle closeRect = new Rectangle(0, 0, 0, 0); - int closeImageState = CTabFolder.NONE; - boolean showClose = false; - boolean showing = false; - - // internal constants - static final int TOP_MARGIN = 2; - static final int BOTTOM_MARGIN = 2; - static final int LEFT_MARGIN = 4; - static final int RIGHT_MARGIN = 4; - static final int INTERNAL_SPACING = 4; - static final int FLAGS = SWT.DRAW_TRANSPARENT | SWT.DRAW_MNEMONIC; - static final String ELLIPSIS = "..."; //$NON-NLS-1$ // could use the ellipsis glyph on some platforms "\u2026" - -/** - * Constructs a new instance of this class given its parent - * (which must be aCTabFolder
) and a style value
- * describing its behavior and appearance. The item is added
- * to the end of the items maintained by its parent.
- *
- * The style value is either one of the style constants defined in
- * class SWT
which is applicable to instances of this
- * class, or must be built by bitwise OR'ing together
- * (that is, using the int
"|" operator) two or more
- * of those SWT
style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- *
CTabFolder
), a style value
- * describing its behavior and appearance, and the index
- * at which to place it in the items maintained by its parent.
- *
- * The style value is either one of the style constants defined in
- * class SWT
which is applicable to instances of this
- * class, or must be built by bitwise OR'ing together
- * (that is, using the int
"|" operator) two or more
- * of those SWT
style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- *
CTabFolder
.
- *
- * @return the receiver's parent
- *
- * @exception SWTException true
to indicate that the receiver's close button should be shown.
- * Otherwise return false
. The initial value is defined by the style (SWT.CLOSE)
- * that was used to create the receiver.
- *
- * @return true
if the close button should be shown
- *
- * @exception SWTException true
if the item will be rendered in the visible area of the CTabFolder. Returns false otherwise.
-*
-* @return true
if the item will be rendered in the visible area of the CTabFolder. Returns false otherwise.
-*
-* @exception SWTException true
to indicate that the receiver's close button should be shown.
- * If the parent (CTabFolder) was created with SWT.CLOSE style, changing this value has
- * no effect.
- *
- * @param close the new state of the close button
- *
- * @exception SWTException Here is an example of using a ControlEditor:
-*
-*
- *
- * @param start the start of the line
- * @param length the length of the line
- */
-void addLineIndex(int start, int length) {
- int size = lines.length;
- if (lineCount == size) {
- // expand the lines by powers of 2
- int[][] newLines = new int[size+Compatibility.pow2(expandExp)][2];
- System.arraycopy(lines, 0, newLines, 0, size);
- lines = newLines;
- expandExp++;
- }
- int[] range = new int[] {start, length};
- lines[lineCount] = range;
- lineCount++;
-}
-/**
- * Adds a line index to the end of
- *
- * @param start the start of the line
- * @param length the length of the line
- * @param linesArray the array to which to add the line index
- * @param count the position at which to add the line
- * @return a new array of line indexes
- */
-int[][] addLineIndex(int start, int length, int[][] linesArray, int count) {
- int size = linesArray.length;
- int[][] newLines = linesArray;
- if (count == size) {
- newLines = new int[size+Compatibility.pow2(replaceExpandExp)][2];
- replaceExpandExp++;
- System.arraycopy(linesArray, 0, newLines, 0, size);
- }
- int[] range = new int[] {start, length};
- newLines[count] = range;
- return newLines;
-}
-/**
- * Adds a
- *
- * @param listener the listener
- * @exception IllegalArgumentException
- *
- * @param position the position at which a change is occurring
- * @param sizeHint the size of the change
- * @param line the line where the gap will go
- */
-void adjustGap(int position, int sizeHint, int line) {
- if (position == gapStart) {
- // text is being inserted at the gap position
- int size = (gapEnd - gapStart) - sizeHint;
- if (lowWatermark <= size && size <= highWatermark)
- return;
- } else if ((position + sizeHint == gapStart) && (sizeHint < 0)) {
- // text is being deleted at the gap position
- int size = (gapEnd - gapStart) - sizeHint;
- if (lowWatermark <= size && size <= highWatermark)
- return;
- }
- moveAndResizeGap(position, sizeHint, line);
-}
-/**
- * Calculates the indexes of each line in the text store. Assumes no gap exists.
- * Optimized to do less checking.
- */
-void indexLines(){
- int start = 0;
- lineCount = 0;
- int textLength = textStore.length;
- int i;
- for (i = start; i < textLength; i++) {
- char ch = textStore[i];
- if (ch == SWT.CR) {
- // see if the next character is a LF
- if (i + 1 < textLength) {
- ch = textStore[i+1];
- if (ch == SWT.LF) {
- i++;
- }
- }
- addLineIndex(start, i - start + 1);
- start = i + 1;
- } else if (ch == SWT.LF) {
- addLineIndex(start, i - start + 1);
- start = i + 1;
- }
- }
- addLineIndex(start, i - start);
-}
-/**
- * Returns whether or not the given character is a line delimiter. Both CR and LF
- * are valid line delimiters.
- *
- *
- * @param ch the character to test
- * @return true if ch is a delimiter, false otherwise
- */
-boolean isDelimiter(char ch) {
- if (ch == SWT.CR) return true;
- if (ch == SWT.LF) return true;
- return false;
-}
-/**
- * Determine whether or not the replace operation is valid. DefaultContent will not allow
- * the /r/n line delimiter to be split or partially deleted.
- *
- *
- * @param start start offset of text to replace
- * @param replaceLength start offset of text to replace
- * @param newText start offset of text to replace
- * @return a boolean specifying whether or not the replace operation is valid
- */
-protected boolean isValidReplace(int start, int replaceLength, String newText){
- if (replaceLength == 0) {
- // inserting text, see if the \r\n line delimiter is being split
- if (start == 0) return true;
- if (start == getCharCount()) return true;
- char before = getTextRange(start - 1, 1).charAt(0);
- if (before == '\r') {
- char after = getTextRange(start, 1).charAt(0);
- if (after == '\n') return false;
- }
- } else {
- // deleting text, see if part of a \r\n line delimiter is being deleted
- char startChar = getTextRange(start, 1).charAt(0);
- if (startChar == '\n') {
- // see if char before delete position is \r
- if (start != 0) {
- char before = getTextRange(start - 1, 1).charAt(0);
- if (before == '\r') return false;
- }
- }
- char endChar = getTextRange(start + replaceLength - 1, 1).charAt(0);
- if (endChar == '\r') {
- // see if char after delete position is \n
- if (start + replaceLength != getCharCount()) {
- char after = getTextRange(start + replaceLength, 1).charAt(0);
- if (after == '\n') return false;
- }
- }
- }
- return true;
-}
-/**
- * Calculates the indexes of each line of text in the given range.
- *
- *
- * @param offset the logical start offset of the text lineate
- * @param length the length of the text to lineate, includes gap
- * @param numLines the number of lines to initially allocate for the line index array,
- * passed in for efficiency (the exact number of lines may be known)
- * @return a line indexes array where each line is identified by a start offset and
- * a length
- */
-int[][] indexLines(int offset, int length, int numLines){
- int[][] indexedLines = new int[numLines][2];
- int start = 0;
- int lineCount = 0;
- int i;
- replaceExpandExp = 1;
- for (i = start; i < length; i++) {
- int location = i + offset;
- if ((location >= gapStart) && (location < gapEnd)) {
- // ignore the gap
- } else {
- char ch = textStore[location];
- if (ch == SWT.CR) {
- // see if the next character is a LF
- if (location+1 < textStore.length) {
- ch = textStore[location+1];
- if (ch == SWT.LF) {
- i++;
- }
- }
- indexedLines = addLineIndex(start, i - start + 1, indexedLines, lineCount);
- lineCount++;
- start = i + 1;
- } else if (ch == SWT.LF) {
- indexedLines = addLineIndex(start, i - start + 1, indexedLines, lineCount);
- lineCount++;
- start = i + 1;
- }
- }
- }
- int[][] newLines = new int[lineCount+1][2];
- System.arraycopy(indexedLines, 0, newLines, 0, lineCount);
- int[] range = new int[] {start, i - start};
- newLines[lineCount] = range;
- return newLines;
-}
-/**
- * Inserts text.
- *
- *
- * @param position the position at which to insert the text
- * @param text the text to insert
- */
-void insert(int position, String text) {
- if (text.length() == 0) return;
-
- int startLine = getLineAtOffset(position);
- int change = text.length();
- boolean endInsert = position == getCharCount();
- adjustGap(position, change, startLine);
-
- // during an insert the gap will be adjusted to start at
- // position and it will be associated with startline, the
- // inserted text will be placed in the gap
- int startLineOffset = getOffsetAtLine(startLine);
- // at this point, startLineLength will include the start line
- // and all of the newly inserted text
- int startLineLength = getPhysicalLine(startLine).length();
-
- if (change > 0) {
- // shrink gap
- gapStart += (change);
- for (int i = 0; i < text.length(); i++) {
- textStore[position + i]= text.charAt(i);
- }
- }
-
- // figure out the number of new lines that have been inserted
- int [][] newLines = indexLines(startLineOffset, startLineLength, 10);
- // only insert an empty line if it is the last line in the text
- int numNewLines = newLines.length - 1;
- if (newLines[numNewLines][1] == 0) {
- // last inserted line is a new line
- if (endInsert) {
- // insert happening at end of the text, leave numNewLines as
- // is since the last new line will not be concatenated with another
- // line
- numNewLines += 1;
- } else {
- numNewLines -= 1;
- }
- }
-
- // make room for the new lines
- expandLinesBy(numNewLines);
- // shift down the lines after the replace line
- for (int i = lineCount - 1; i > startLine; i--) {
- lines[i + numNewLines]=lines[i];
- }
- // insert the new lines
- for (int i = 0; i < numNewLines; i++) {
- newLines[i][0] += startLineOffset;
- lines[startLine + i]=newLines[i];
- }
- // update the last inserted line
- if (numNewLines < newLines.length) {
- newLines[numNewLines][0] += startLineOffset;
- lines[startLine + numNewLines] = newLines[numNewLines];
- }
-
- lineCount += numNewLines;
- gapLine = getLineAtPhysicalOffset(gapStart);
-}
-/**
- * Moves the gap and adjusts its size in anticipation of a text change.
- * The gap is resized to actual size + the specified size and moved to the given
- * position.
- *
- *
- * @param position the position at which a change is occurring
- * @param size the size of the change
- * @param newGapLine the line where the gap should be put
- */
-void moveAndResizeGap(int position, int size, int newGapLine) {
- char[] content = null;
- int oldSize = gapEnd - gapStart;
- int newSize;
- if (size > 0) {
- newSize = highWatermark + size;
- } else {
- newSize = lowWatermark - size;
- }
- // remove the old gap from the lines information
- if (gapExists()) {
- // adjust the line length
- lines[gapLine][1] = lines[gapLine][1] - oldSize;
- // adjust the offsets of the lines after the gapLine
- for (int i = gapLine + 1; i < lineCount; i++) {
- lines[i][0] = lines[i][0] - oldSize;
- }
- }
-
- if (newSize < 0) {
- if (oldSize > 0) {
- // removing the gap
- content = new char[textStore.length - oldSize];
- System.arraycopy(textStore, 0, content, 0, gapStart);
- System.arraycopy(textStore, gapEnd, content, gapStart, content.length - gapStart);
- textStore = content;
- }
- gapStart = gapEnd = position;
- return;
- }
- content = new char[textStore.length + (newSize - oldSize)];
- int newGapStart = position;
- int newGapEnd = newGapStart + newSize;
- if (oldSize == 0) {
- System.arraycopy(textStore, 0, content, 0, newGapStart);
- System.arraycopy(textStore, newGapStart, content, newGapEnd, content.length - newGapEnd);
- } else if (newGapStart < gapStart) {
- int delta = gapStart - newGapStart;
- System.arraycopy(textStore, 0, content, 0, newGapStart);
- System.arraycopy(textStore, newGapStart, content, newGapEnd, delta);
- System.arraycopy(textStore, gapEnd, content, newGapEnd + delta, textStore.length - gapEnd);
- } else {
- int delta = newGapStart - gapStart;
- System.arraycopy(textStore, 0, content, 0, gapStart);
- System.arraycopy(textStore, gapEnd, content, gapStart, delta);
- System.arraycopy(textStore, gapEnd + delta, content, newGapEnd, content.length - newGapEnd);
- }
- textStore = content;
- gapStart = newGapStart;
- gapEnd = newGapEnd;
-
- // add the new gap to the lines information
- if (gapExists()) {
- gapLine = newGapLine;
- // adjust the line length
- int gapLength = gapEnd - gapStart;
- lines[gapLine][1] = lines[gapLine][1] + (gapLength);
- // adjust the offsets of the lines after the gapLine
- for (int i = gapLine + 1; i < lineCount; i++) {
- lines[i][0] = lines[i][0] + gapLength;
- }
- }
-}
-/**
- * Returns the number of lines that are in the specified text.
- *
- *
- * @param startOffset the start of the text to lineate
- * @param length the length of the text to lineate
- * @return number of lines
- */
-int lineCount(int startOffset, int length){
- if (length == 0) {
- return 0;
- }
- int lineCount = 0;
- int count = 0;
- int i = startOffset;
- if (i >= gapStart) {
- i += gapEnd - gapStart;
- }
- while (count < length) {
- if ((i >= gapStart) && (i < gapEnd)) {
- // ignore the gap
- } else {
- char ch = textStore[i];
- if (ch == SWT.CR) {
- // see if the next character is a LF
- if (i + 1 < textStore.length) {
- ch = textStore[i+1];
- if (ch == SWT.LF) {
- i++;
- count++;
- }
- }
- lineCount++;
- } else if (ch == SWT.LF) {
- lineCount++;
- }
- count++;
- }
- i++;
- }
- return lineCount;
-}
-/**
- * Returns the number of lines that are in the specified text.
- *
- *
- * @param text the text to lineate
- * @return number of lines in the text
- */
-int lineCount(String text){
- int lineCount = 0;
- int length = text.length();
- for (int i = 0; i < length; i++) {
- char ch = text.charAt(i);
- if (ch == SWT.CR) {
- if (i + 1 < length && text.charAt(i + 1) == SWT.LF) {
- i++;
- }
- lineCount++;
- } else if (ch == SWT.LF) {
- lineCount++;
- }
- }
- return lineCount;
-}
-/**
- * @return the logical length of the text store
- */
-public int getCharCount() {
- int length = gapEnd - gapStart;
- return (textStore.length - length);
-}
-/**
- * Returns the line at
- *
- * @param index the index of the line to return
- * @return the logical line text (i.e., without the gap)
- * @exception IllegalArgumentException
- *
- * @return the platform line delimiter as specified in the line.separator
- * system property.
- */
-public String getLineDelimiter() {
- return LineDelimiter;
-}
-/**
- * Returns the line at the given index with delimiters.
- *
- * @param index the index of the line to return
- * @return the logical line text (i.e., without the gap) with delimiters
- */
-String getFullLine(int index) {
- int start = lines[index][0];
- int length = lines[index][1];
- int end = start + length - 1;
- if (!gapExists() || (end < gapStart) || (start >= gapEnd)) {
- // line is before or after the gap
- return new String(textStore, start, length);
- } else {
- // gap is in the specified range, strip out the gap
- StringBuffer buffer = new StringBuffer();
- int gapLength = gapEnd - gapStart;
- buffer.append(textStore, start, gapStart - start);
- buffer.append(textStore, gapEnd, length - gapLength - (gapStart - start));
- return buffer.toString();
- }
-}
-/**
- * Returns the physical line at the given index (i.e., with delimiters and the gap).
- *
- *
- * @param index the line index
- * @return the physical line
- */
-String getPhysicalLine(int index) {
- int start = lines[index][0];
- int length = lines[index][1];
- return getPhysicalText(start, length);
-}
-/**
- * @return the number of lines in the text store
- */
-public int getLineCount(){
- return lineCount;
-}
-/**
- * Returns the line at the given offset.
- *
- *
- * @param charPosition logical character offset (i.e., does not include gap)
- * @return the line index
- * @exception IllegalArgumentException
- *
- * @param position physical character offset (i.e., includes gap)
- * @return the line index
- */
-int getLineAtPhysicalOffset(int position){
- int high = lineCount;
- int low = -1;
- int index = lineCount;
- while (high - low > 1) {
- index = (high + low) / 2;
- int lineStart = lines[index][0];
- int lineEnd = lineStart + lines[index][1] - 1;
- if (position <= lineStart) {
- high = index;
- } else if (position <= lineEnd) {
- high = index;
- break;
- } else {
- low = index;
- }
- }
- return high;
-}
-/**
- * Returns the logical offset of the given line.
- *
- *
- * @param lineIndex index of line
- * @return the logical starting offset of the line. When there are not any lines,
- * getOffsetAtLine(0) is a valid call that should answer 0.
- * @exception IllegalArgumentException
- *
- * @param numLines the number to increase the array by
- */
-void expandLinesBy(int numLines) {
- int size = lines.length;
- if (size - lineCount >= numLines) {
- return;
- }
- int[][] newLines = new int[size+Math.max(10, numLines)][2];
- System.arraycopy(lines, 0, newLines, 0, size);
- lines = newLines;
-}
-/**
- * Reports an SWT error.
- *
- *
- * @param code the error code
- */
-void error (int code) {
- SWT.error(code);
-}
-/**
- * Returns whether or not a gap exists in the text store.
- *
- *
- * @return true if gap exists, false otherwise
- */
-boolean gapExists() {
- return gapStart != gapEnd;
-}
-/**
- * Returns a string representing the continuous content of
- * the text store.
- *
- *
- * @param start the physical start offset of the text to return
- * @param length the physical length of the text to return
- * @return the text
- */
-String getPhysicalText(int start, int length) {
- return new String(textStore, start, length);
-}
-/**
- * Returns a string representing the logical content of
- * the text store (i.e., gap stripped out).
- *
- *
- * @param start the logical start offset of the text to return
- * @param length the logical length of the text to return
- * @return the text
- */
-public String getTextRange(int start, int length) {
- if (textStore == null)
- return "";
- if (length == 0)
- return "";
- int end= start + length;
- if (!gapExists() || (end < gapStart))
- return new String(textStore, start, length);
- if (gapStart < start) {
- int gapLength= gapEnd - gapStart;
- return new String(textStore, start + gapLength , length);
- }
- StringBuffer buf = new StringBuffer();
- buf.append(textStore, start, gapStart - start);
- buf.append(textStore, gapEnd, end - gapStart);
- return buf.toString();
-}
-/**
- * Removes the specified
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException
- *
- * When sending the TextChangingEvent,
-*
-* @see Sample code and further information
-*/
-public class ControlEditor {
-
- /**
- * Specifies how the editor should be aligned relative to the control. Allowed values
- * are SWT.LEFT, SWT.RIGHT and SWT.CENTER. The default value is SWT.CENTER.
- */
- public int horizontalAlignment = SWT.CENTER;
-
- /**
- * Specifies whether the editor should be sized to use the entire width of the control.
- * True means resize the editor to the same width as the cell. False means do not adjust
- * the width of the editor. The default value is false.
- */
- public boolean grabHorizontal = false;
-
- /**
- * Specifies the minimum width the editor can have. This is used in association with
- * a true value of grabHorizontal. If the cell becomes smaller than the minimumWidth, the
- * editor will not made smaller than the minimum width value. The default value is 0.
- */
- public int minimumWidth = 0;
-
- /**
- * Specifies how the editor should be aligned relative to the control. Allowed values
- * are SWT.TOP, SWT.BOTTOM and SWT.CENTER. The default value is SWT.CENTER.
- */
- public int verticalAlignment = SWT.CENTER;
-
- /**
- * Specifies whether the editor should be sized to use the entire height of the control.
- * True means resize the editor to the same height as the underlying control. False means do not adjust
- * the height of the editor. The default value is false.
- */
- public boolean grabVertical = false;
-
- /**
- * Specifies the minimum height the editor can have. This is used in association with
- * a true value of grabVertical. If the control becomes smaller than the minimumHeight, the
- * editor will not made smaller than the minimum height value. The default value is 0.
- */
- public int minimumHeight = 0;
-
- Composite parent;
- Control editor;
- private boolean hadFocus;
- private Listener controlListener;
- private Listener scrollbarListener;
-
- private final static int [] EVENTS = {SWT.KeyDown, SWT.KeyUp, SWT.MouseDown, SWT.MouseUp, SWT.Resize};
-/**
-* Creates a ControlEditor for the specified Composite.
-*
-* @param parent the Composite above which this editor will be displayed
-*
-*/
-public ControlEditor (Composite parent) {
- this.parent = parent;
-
- controlListener = new Listener() {
- public void handleEvent(Event e) {
- layout ();
- }
- };
- for (int i=0; i
-* Canvas canvas = new Canvas(shell, SWT.BORDER);
-* canvas.setBounds(10, 10, 300, 300);
-* Color color = new Color(null, 255, 0, 0);
-* canvas.setBackground(color);
-* ControlEditor editor = new ControlEditor (canvas);
-* // The editor will be a button in the bottom right corner of the canvas.
-* // When selected, it will launch a Color dialog that will change the background
-* // of the canvas.
-* Button button = new Button(canvas, SWT.PUSH);
-* button.setText("Select Color...");
-* button.addSelectionListener (new SelectionAdapter() {
-* public void widgetSelected(SelectionEvent e) {
-* ColorDialog dialog = new ColorDialog(shell);
-* dialog.open();
-* RGB rgb = dialog.getRGB();
-* if (rgb != null) {
-* if (color != null) color.dispose();
-* color = new Color(null, rgb);
-* canvas.setBackground(color);
-* }
-*
-* }
-* });
-*
-* editor.horizontalAlignment = SWT.RIGHT;
-* editor.verticalAlignment = SWT.BOTTOM;
-* editor.grabHorizontal = false;
-* editor.grabVertical = false;
-* Point size = button.computeSize(SWT.DEFAULT, SWT.DEFAULT);
-* editor.minimumWidth = size.x;
-* editor.minimumHeight = size.y;
-* editor.setEditor (button);
-*
StyledTextContent> will always have
- * at least one empty line.
- */
-DefaultContent() {
- super();
- setText("");
-}
-/**
- * Adds a line to the end of the line indexes array. Increases the size of the array if necessary.
- *
lineCount
is updated to reflect the new entry.
- * linesArray
. Increases the
- * size of the array if necessary and returns a new array.
- * TextChangeListener
listening for
- * TextChangingEvent
and TextChangedEvent
. A
- * TextChangingEvent
is sent before changes to the text occur.
- * A TextChangedEvent
is sent after changes to the text
- * occurred.
- *
- *
- */
-public void addTextChangeListener(TextChangeListener listener) {
- if (listener == null) error(SWT.ERROR_NULL_ARGUMENT);
- StyledTextListener typedListener = new StyledTextListener(listener);
- textListeners.addElement(typedListener);
-}
-/**
- * Adjusts the gap to accommodate a text change that is occurring.
- * index
without delimiters.
- *
- *
- */
-public String getLine(int index) {
- if ((index >= lineCount) || (index < 0)) error(SWT.ERROR_INVALID_ARGUMENT);
- int start = lines[index][0];
- int length = lines[index][1];
- int end = start + length - 1;
- if (!gapExists() || (end < gapStart) || (start >= gapEnd)) {
- // line is before or after the gap
- while ((length - 1 >= 0) && isDelimiter(textStore[start+length-1])) {
- length--;
- }
- return new String(textStore, start, length);
- } else {
- // gap is in the specified range, strip out the gap
- StringBuffer buf = new StringBuffer();
- int gapLength = gapEnd - gapStart;
- buf.append(textStore, start, gapStart - start);
- buf.append(textStore, gapEnd, length - gapLength - (gapStart - start));
- length = buf.length();
- while ((length - 1 >=0) && isDelimiter(buf.charAt(length - 1))) {
- length--;
- }
- return buf.toString().substring(0, length);
- }
-}
-/**
- * Returns the line delimiter that should be used by the StyledText
- * widget when inserting new lines. This delimiter may be different than the
- * delimiter that is used by the StyledTextContent
interface.
- *
- *
- */
-public int getLineAtOffset(int charPosition){
- if ((charPosition > getCharCount()) || (charPosition < 0)) error(SWT.ERROR_INVALID_ARGUMENT);
- int position;
- if (charPosition < gapStart) {
- // position is before the gap
- position = charPosition;
- } else {
- // position includes the gap
- position = charPosition + (gapEnd - gapStart);
- }
-
- // if last line and the line is not empty you can ask for
- // a position that doesn't exist (the one to the right of the
- // last character) - for inserting
- if (lineCount > 0) {
- int lastLine = lineCount - 1;
- if (position == lines[lastLine][0] + lines[lastLine][1])
- return lastLine;
- }
-
- int high = lineCount;
- int low = -1;
- int index = lineCount;
- while (high - low > 1) {
- index = (high + low) / 2;
- int lineStart = lines[index][0];
- int lineEnd = lineStart + lines[index][1] - 1;
- if (position <= lineStart) {
- high = index;
- } else if (position <= lineEnd) {
- high = index;
- break;
- } else {
- low = index;
- }
- }
- return high;
-}
-/**
- * Returns the line index at the given physical offset.
- *
- *
- */
-public int getOffsetAtLine(int lineIndex) {
- if (lineIndex == 0) return 0;
- if ((lineIndex >= lineCount) || (lineIndex < 0)) error(SWT.ERROR_INVALID_ARGUMENT);
- int start = lines[lineIndex][0];
- if (start > gapEnd) {
- return start - (gapEnd - gapStart);
- } else {
- return start;
- }
-}
-/**
- * Increases the line indexes array to accommodate more lines.
- * TextChangeListener
.
- *
- *
- */
-public void removeTextChangeListener(TextChangeListener listener){
- if (listener == null) error(SWT.ERROR_NULL_ARGUMENT);
- for (int i = 0; i < textListeners.size(); i++) {
- TypedListener typedListener = (TypedListener) textListeners.elementAt(i);
- if (typedListener.getEventListener () == listener) {
- textListeners.removeElementAt(i);
- break;
- }
- }
-}
-/**
- * Replaces the text with newText
starting at position start
- * for a length of replaceLength
. Notifies the appropriate listeners.
- * newLineCount
is the number of
- * lines that are going to be inserted and replaceLineCount
is
- * the number of lines that are going to be deleted, based on the change
- * that occurs visually. For example:
- *
- *
- *
- * - * @param text the text - */ -public void setText (String text){ - textStore = text.toCharArray(); - gapStart = -1; - gapEnd = -1; - expandExp = 1; - indexLines(); - StyledTextEvent event = new StyledTextEvent(this); - event.type = StyledText.TextSet; - event.text = ""; - sendTextEvent(event); -} -/** - * Deletes text. - *
- * @param position the position at which the text to delete starts - * @param length the length of the text to delete - * @param numLines the number of lines that are being deleted - */ -void delete(int position, int length, int numLines) { - if (length == 0) return; - - int startLine = getLineAtOffset(position); - int startLineOffset = getOffsetAtLine(startLine); - int endLine = getLineAtOffset(position + length); - - String endText = ""; - boolean splittingDelimiter = false; - if (position + length < getCharCount()) { - endText = getTextRange(position + length - 1, 2); - if ((endText.charAt(0) == SWT.CR) && (endText.charAt(1) == SWT.LF)) { - splittingDelimiter = true; - } - } - - adjustGap(position + length, -length, startLine); - int [][] oldLines = indexLines(position, length + (gapEnd - gapStart), numLines); - - // enlarge the gap - the gap can be enlarged either to the - // right or left - if (position + length == gapStart) { - gapStart -= length; - } else { - gapEnd += length; - } - - // figure out the length of the new concatenated line, do so by - // finding the first line delimiter after position - int j = position; - boolean eol = false; - while (j < textStore.length && !eol) { - if (j < gapStart || j >= gapEnd) { - char ch = textStore[j]; - if (isDelimiter(ch)) { - if (j + 1 < textStore.length) { - if (ch == SWT.CR && (textStore[j+1] == SWT.LF)) { - j++; - } - } - eol = true; - } - } - j++; - } - // update the line where the deletion started - lines[startLine][1] = (position - startLineOffset) + (j - position); - // figure out the number of lines that have been deleted - int numOldLines = oldLines.length - 1; - if (splittingDelimiter) numOldLines -= 1; - // shift up the lines after the last deleted line, no need to update - // the offset or length of the lines - for (int i = endLine + 1; i < lineCount; i++) { - lines[i - numOldLines] = lines[i]; - } - lineCount -= numOldLines; - gapLine = getLineAtPhysicalOffset(gapStart); -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/ExtendedModifyEvent.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/ExtendedModifyEvent.java deleted file mode 100755 index 3d429291df..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/ExtendedModifyEvent.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.custom; - -import org.eclipse.swt.events.*; - -/** - * This event is sent after a text change occurs. - * - * @see Sample code and further information - */ -public final class ExtendedModifyEvent extends TypedEvent { - /** start offset of the new text */ - public int start; - /** length of the new text */ - public int length; - /** replaced text or empty string if no text was replaced */ - public String replacedText; - - static final long serialVersionUID = 3258696507027830832L; - -/** - * Constructs a new instance of this class based on the - * information in the given event. - * - * @param e the event containing the information - */ -public ExtendedModifyEvent(StyledTextEvent e) { - super(e); - start = e.start; - length = e.end - e.start; - replacedText = e.text; -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/ExtendedModifyListener.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/ExtendedModifyListener.java deleted file mode 100755 index 86ca395bc2..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/ExtendedModifyListener.java +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.custom; - -import org.eclipse.swt.internal.SWTEventListener; - -/** - * Classes which implement this interface provide a method - * that deals with the event that is generated when text - * is modified. - * - * @see ExtendedModifyEvent - * @see Sample code and further information - */ -public interface ExtendedModifyListener extends SWTEventListener { - -/** - * This method is called after a text change occurs. - *
- * The following event fields are used:
- * The following event fields are used:
ranges
can be used to share
- * styles and reduce memory usage.
- */
- public StyleRange[] styles;
-
- /**
- * line alignment (input, output)
- *
- * @since 3.2
- */
- public int alignment;
-
- /**
- * line indent (input, output)
- *
- * @since 3.2
- */
- public int indent;
-
- /**
- * line justification (input, output)
- *
- * @since 3.2
- */
- public boolean justify;
-
- /**
- * line bullet (output)
- * @since 3.2
- */
- public Bullet bullet;
-
- /**
- * line bullet index (output)
- * @since 3.2
- */
- public int bulletIndex;
-
- static final long serialVersionUID = 3906081274027192884L;
-
-/**
- * Constructs a new instance of this class based on the
- * information in the given event.
- *
- * @param e the event containing the information
- */
-public LineStyleEvent(StyledTextEvent e) {
- super(e);
- styles = e.styles;
- ranges = e.ranges;
- lineOffset = e.detail;
- lineText = e.text;
- alignment = e.alignment;
- justify = e.justify;
- indent = e.indent;
- bullet = e.bullet;
- bulletIndex = e.bulletIndex;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/LineStyleListener.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/LineStyleListener.java
deleted file mode 100755
index a6acfda978..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/LineStyleListener.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.custom;
-
-import org.eclipse.swt.internal.SWTEventListener;
-
-/**
- * Classes which implement this interface provide a method
- * that can provide the style information for a line that
- * is to be drawn.
- *
- * @see LineStyleEvent
- * @see Sample code and further information
- */
-public interface LineStyleListener extends SWTEventListener {
-
-/**
- * This method is called when a line is about to be drawn in order to get the
- * line's style information.
- * - * The following event fields are used:
- * The following event fields are used:
- * The following event fields are used:
- * The following event fields are used:
-* @return the widget font -* -* @exception SWTException
-* This operation will fail if the items cannot -* be queried from the OS. -* -* @return the items in the widget -* -* @exception SWTException
-* If the item is not currently selected, it is selected. -* If the item at an index is selected, it remains selected. -* If the string is not matched, it is ignored. -* -* @param string the text of the item -* -* @exception SWTException
-* When new font is null, the font reverts -* to the default system font for the widget. -* -* @param font the new font (or null) -* -* @exception SWTException
-* The previous selection is cleared. -* The previous items are deleted. -* The new items are added. -* The top index is set to 0. -* -* @param strings the array of items -* -* This operation will fail when an item is null -* or could not be added in the OS. -* -* @exception IllegalArgumentException
StyledText
.
- *
- * @see Sample code and further information
- */
-public class ST {
-
- /*
- * Navigation Key Actions. Key bindings for the actions are set
- * by the StyledText widget.
- */
- public static final int LINE_UP = 16777217; // binding = SWT.ARROW_UP
- public static final int LINE_DOWN = 16777218; // binding = SWT.ARROW_DOWN
- public static final int LINE_START = 16777223; // binding = SWT.HOME
- public static final int LINE_END = 16777224; // binding = SWT.END
- public static final int COLUMN_PREVIOUS = 16777219; // binding = SWT.ARROW_LEFT
- public static final int COLUMN_NEXT = 16777220; // binding = SWT.ARROW_RIGHT
- public static final int PAGE_UP = 16777221; // binding = SWT.PAGE_UP
- public static final int PAGE_DOWN = 16777222; // binding = SWT.PAGE_DOWN
- public static final int WORD_PREVIOUS = 17039363; // binding = SWT.MOD1 + SWT.ARROW_LEFT
- public static final int WORD_NEXT = 17039364; // binding = SWT.MOD1 + SWT.ARROW_RIGHT
- public static final int TEXT_START = 17039367; // binding = SWT.MOD1 + SWT.HOME
- public static final int TEXT_END = 17039368; // binding = SWT.MOD1 + SWT.END
- public static final int WINDOW_START = 17039365; // binding = SWT.MOD1 + SWT.PAGE_UP
- public static final int WINDOW_END = 17039366; // binding = SWT.MOD1 + SWT.PAGE_DOWN
-
- /*
- * Selection Key Actions
- */
- public static final int SELECT_ALL = 262209; // binding = SWT.MOD1 + 'A'
- public static final int SELECT_LINE_UP = 16908289; // binding = SWT.MOD2 + SWT.ARROW_UP
- public static final int SELECT_LINE_DOWN = 16908290; // binding = SWT.MOD2 + SWT.ARROW_DOWN
- public static final int SELECT_LINE_START = 16908295; // binding = SWT.MOD2 + SWT.HOME
- public static final int SELECT_LINE_END = 16908296; // binding = SWT.MOD2 + SWT.END
- public static final int SELECT_COLUMN_PREVIOUS = 16908291; // binding = SWT.MOD2 + SWT.ARROW_LEFT
- public static final int SELECT_COLUMN_NEXT = 16908292; // binding = SWT.MOD2 + SWT.ARROW_RIGHT
- public static final int SELECT_PAGE_UP = 16908293; // binding = SWT.MOD2 + SWT.PAGE_UP
- public static final int SELECT_PAGE_DOWN = 16908294; // binding = SWT.MOD2 + SWT.PAGE_DOWN
- public static final int SELECT_WORD_PREVIOUS = 17170435; // binding = SWT.MOD1 + SWT.MOD2 + SWT.ARROW_LEFT
- public static final int SELECT_WORD_NEXT = 17170436; // binding = SWT.MOD1 + SWT.MOD2 + SWT.ARROW_RIGHT
- public static final int SELECT_TEXT_START = 17170439; // binding = SWT.MOD1 + SWT.MOD2 + SWT.HOME
- public static final int SELECT_TEXT_END = 17170440; // binding = SWT.MOD1 + SWT.MOD2 + SWT.END
- public static final int SELECT_WINDOW_START = 17170437; // binding = SWT.MOD1 + SWT.MOD2 + SWT.PAGE_UP
- public static final int SELECT_WINDOW_END = 17170438; // binding = SWT.MOD1 + SWT.MOD2 + SWT.PAGE_DOWN
-
- /*
- * Modification Key Actions
- */
- public static final int CUT = 131199; // binding = SWT.MOD2 + SWT.DEL
- public static final int COPY = 17039369; // binding = SWT.MOD1 + SWT.INSERT;
- public static final int PASTE = 16908297; // binding = SWT.MOD2 + SWT.INSERT ;
- public static final int DELETE_PREVIOUS = '\b'; // binding = SWT.BS;
- public static final int DELETE_NEXT = 0x7F; // binding = SWT.DEL;
- public static final int DELETE_WORD_PREVIOUS = 262152; // binding = SWT.BS | SWT.MOD1;
- public static final int DELETE_WORD_NEXT = 262271; // binding = SWT.DEL | SWT.MOD1;
-
- /*
- * Miscellaneous Key Actions
- */
- public static final int TOGGLE_OVERWRITE = 16777225; // binding = SWT.INSERT;
-
- /**
- * TEMPORARY CODE - API SUBJECT TO CHANGE
- *
- * Toggle block selection mode
- *
- * @since 3.5
- */
- public static final int TOGGLE_BLOCKSELECTION = 16777226;
-
- /**
- * Bullet style dot.
- *
- * @see Bullet
- *
- * @since 3.2
- */
- public static final int BULLET_DOT = 1 << 0;
-
- /**
- * Bullet style number.
- *
- * @see Bullet
- *
- * @since 3.2
- */
- public static final int BULLET_NUMBER = 1 << 1;
-
- /**
- * Bullet style lower case letter.
- *
- * @see Bullet
- *
- * @since 3.2
- */
- public static final int BULLET_LETTER_LOWER = 1 << 2;
-
- /**
- * Bullet style upper case letter.
- *
- * @see Bullet
- *
- * @since 3.2
- */
- public static final int BULLET_LETTER_UPPER = 1 << 3;
-
- /**
- * Bullet style text.
- *
- * @see Bullet
- *
- * @since 3.2
- */
- public static final int BULLET_TEXT = 1 << 4;
-
- /**
- * Bullet style custom draw.
- *
- * @see StyledText#addPaintObjectListener(PaintObjectListener)
- * @see StyledText#removePaintObjectListener(PaintObjectListener)
- * @see Bullet
- *
- * @since 3.2
- */
- public static final int BULLET_CUSTOM = 1 << 5;
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/SashForm.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/SashForm.java
deleted file mode 100755
index 232652d665..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/SashForm.java
+++ /dev/null
@@ -1,446 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.custom;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.widgets.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * The SashForm is a composite control that lays out its children in a
- * row or column arrangement (as specified by the orientation) and places
- * a Sash between each child. One child may be maximized to occupy the
- * entire size of the SashForm. The relative sizes of the children may
- * be specified using weights.
- * - *
- * The style value is either one of the style constants defined in
- * class SWT
which is applicable to instances of this
- * class, or must be built by bitwise OR'ing together
- * (that is, using the int
"|" operator) two or more
- * of those SWT
style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- *
- * Note: No Layout can be set on this Control because it already - * manages the size and position of its children. - *
- * - * @param layout the receiver's new layout or null - * - * @exception SWTExceptionThere are two ways to use the ScrolledComposite: - * - *
- * 1) Set the size of the control that is being scrolled and the ScrolledComposite
- * will show scrollbars when the contained control can not be fully seen.
- *
- * 2) The second way imitates the way a browser would work. Set the minimum size of
- * the control and the ScrolledComposite will show scroll bars if the visible area is
- * less than the minimum size of the control and it will expand the size of the control
- * if the visible area is greater than the minimum size. This requires invoking
- * both setMinWidth(), setMinHeight() and setExpandHorizontal(), setExpandVertical().
- *
- *
- *
- *
- * public static void main (String [] args) {
- * Display display = new Display ();
- * Color red = display.getSystemColor(SWT.COLOR_RED);
- * Color blue = display.getSystemColor(SWT.COLOR_BLUE);
- * Shell shell = new Shell (display);
- * shell.setLayout(new FillLayout());
- *
- * // set the size of the scrolled content - method 1
- * final ScrolledComposite sc1 = new ScrolledComposite(shell, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
- * final Composite c1 = new Composite(sc1, SWT.NONE);
- * sc1.setContent(c1);
- * c1.setBackground(red);
- * GridLayout layout = new GridLayout();
- * layout.numColumns = 4;
- * c1.setLayout(layout);
- * Button b1 = new Button (c1, SWT.PUSH);
- * b1.setText("first button");
- * c1.setSize(c1.computeSize(SWT.DEFAULT, SWT.DEFAULT));
- *
- * // set the minimum width and height of the scrolled content - method 2
- * final ScrolledComposite sc2 = new ScrolledComposite(shell, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
- * sc2.setExpandHorizontal(true);
- * sc2.setExpandVertical(true);
- * final Composite c2 = new Composite(sc2, SWT.NONE);
- * sc2.setContent(c2);
- * c2.setBackground(blue);
- * layout = new GridLayout();
- * layout.numColumns = 4;
- * c2.setLayout(layout);
- * Button b2 = new Button (c2, SWT.PUSH);
- * b2.setText("first button");
- * sc2.setMinSize(c2.computeSize(SWT.DEFAULT, SWT.DEFAULT));
- *
- * Button add = new Button (shell, SWT.PUSH);
- * add.setText("add children");
- * final int[] index = new int[]{0};
- * add.addListener(SWT.Selection, new Listener() {
- * public void handleEvent(Event e) {
- * index[0]++;
- * Button button = new Button(c1, SWT.PUSH);
- * button.setText("button "+index[0]);
- * // reset size of content so children can be seen - method 1
- * c1.setSize(c1.computeSize(SWT.DEFAULT, SWT.DEFAULT));
- * c1.layout();
- *
- * button = new Button(c2, SWT.PUSH);
- * button.setText("button "+index[0]);
- * // reset the minimum width and height so children can be seen - method 2
- * sc2.setMinSize(c2.computeSize(SWT.DEFAULT, SWT.DEFAULT));
- * c2.layout();
- * }
- * });
- *
- * shell.open ();
- * while (!shell.isDisposed ()) {
- * if (!display.readAndDispatch ()) display.sleep ();
- * }
- * display.dispose ();
- * }
- *
- * The style value is either one of the style constants defined in
- * class SWT
which is applicable to instances of this
- * class, or must be built by bitwise OR'ing together
- * (that is, using the int
"|" operator) two or more
- * of those SWT
style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- *
true
if the content control
- * will be expanded to fill available horizontal space.
- *
- * @return the receiver's horizontal expansion state
- *
- * @exception SWTException true
if the content control
- * will be expanded to fill available vertical space.
- *
- * @return the receiver's vertical expansion state
- *
- * @exception SWTException true
if the receiver automatically scrolls to a focused child control
- * to make it visible. Otherwise, returns false
.
- *
- * @return a boolean indicating whether focused child controls are automatically scrolled into the viewport
- *
- * @exception SWTException - * Note: No Layout can be set on this Control because it already - * manages the size and position of its children. - *
- * - * @param layout the receiver's new layout or null - * - * @exception SWTExceptionfalse
, show a focused control is off.
- * By default, show a focused control is off.
- *
- * @param show true
to show a focused control.
- *
- * @exception SWTException Here is an example which places ten buttons in a stack layout and - * flips between them: - * - *
- * public static void main(String[] args) {
- * Display display = new Display();
- * Shell shell = new Shell(display);
- * shell.setLayout(new GridLayout());
- *
- * final Composite parent = new Composite(shell, SWT.NONE);
- * parent.setLayoutData(new GridData(GridData.FILL_BOTH));
- * final StackLayout layout = new StackLayout();
- * parent.setLayout(layout);
- * final Button[] bArray = new Button[10];
- * for (int i = 0; i < 10; i++) {
- * bArray[i] = new Button(parent, SWT.PUSH);
- * bArray[i].setText("Button "+i);
- * }
- * layout.topControl = bArray[0];
- *
- * Button b = new Button(shell, SWT.PUSH);
- * b.setText("Show Next Button");
- * final int[] index = new int[1];
- * b.addListener(SWT.Selection, new Listener(){
- * public void handleEvent(Event e) {
- * index[0] = (index[0] + 1) % 10;
- * layout.topControl = bArray[index[0]];
- * parent.layout();
- * }
- * });
- *
- * shell.open();
- * while (shell != null && !shell.isDisposed()) {
- * if (!display.readAndDispatch())
- * display.sleep();
- * }
- * }
- *
- *
- * @see StackLayout snippets
- * @see SWT Example: LayoutExample
- * @see Sample code and further information
- */
-
-public class StackLayout extends Layout {
-
- /**
- * marginWidth specifies the number of pixels of horizontal margin
- * that will be placed along the left and right edges of the layout.
- *
- * The default value is 0.
- */
- public int marginWidth = 0;
- /**
- * marginHeight specifies the number of pixels of vertical margin
- * that will be placed along the top and bottom edges of the layout.
- *
- * The default value is 0.
- */
- public int marginHeight = 0;
-
- /**
- * topControl the Control that is displayed at the top of the stack.
- * All other controls that are children of the parent composite will not be visible.
- */
- public Control topControl;
-
-protected Point computeSize(Composite composite, int wHint, int hHint, boolean flushCache) {
- Control children[] = composite.getChildren();
- int maxWidth = 0;
- int maxHeight = 0;
- for (int i = 0; i < children.length; i++) {
- Point size = children[i].computeSize(wHint, hHint, flushCache);
- maxWidth = Math.max(size.x, maxWidth);
- maxHeight = Math.max(size.y, maxHeight);
- }
- int width = maxWidth + 2 * marginWidth;
- int height = maxHeight + 2 * marginHeight;
- if (wHint != SWT.DEFAULT) width = wHint;
- if (hHint != SWT.DEFAULT) height = hHint;
- return new Point(width, height);
-}
-
-protected boolean flushCache(Control control) {
- return true;
-}
-
-protected void layout(Composite composite, boolean flushCache) {
- Control children[] = composite.getChildren();
- Rectangle rect = composite.getClientArea();
- rect.x += marginWidth;
- rect.y += marginHeight;
- rect.width -= 2 * marginWidth;
- rect.height -= 2 * marginHeight;
- for (int i = 0; i < children.length; i++) {
- children[i].setBounds(rect);
- children[i].setVisible(children[i] == topControl);
-
- }
-}
-
-String getName () {
- String string = getClass ().getName ();
- int index = string.lastIndexOf ('.');
- if (index == -1) return string;
- return string.substring (index + 1, string.length ());
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the layout
- */
-public String toString () {
- String string = getName ()+" {";
- if (marginWidth != 0) string += "marginWidth="+marginWidth+" ";
- if (marginHeight != 0) string += "marginHeight="+marginHeight+" ";
- if (topControl != null) string += "topControl="+topControl+" ";
- string = string.trim();
- string += "}";
- return string;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyleRange.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyleRange.java
deleted file mode 100755
index 76469db5f9..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyleRange.java
+++ /dev/null
@@ -1,213 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.custom;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.CloneableCompatibility;
-
-/**
- * StyleRange
defines a set of styles for a specified
- * range of text.
- * - * The hashCode() method in this class uses the values of the public - * fields to compute the hash value. When storing instances of the - * class in hashed collections, do not modify these fields after the - * object has been inserted. - *
- * - * @see Sample code and further information - */ -public class StyleRange extends TextStyle implements CloneableCompatibility { - - /** - * the start offset of the range, zero-based from the document start - */ - public int start; - - /** - * the length of the range - */ - public int length; - - /** - * the font style of the range. It may be a combination of - * SWT.NORMAL, SWT.ITALIC or SWT.BOLD - * - * Note: the font style is not used if thefont
attribute
- * is set
- */
- public int fontStyle = SWT.NORMAL;
-
-/**
- * Create a new style range with no styles
- *
- * @since 3.2
- */
-public StyleRange() {
-}
-
-/**
- * Create a new style range from an existing text style.
- *
- * @param style the text style to copy
- *
- * @since 3.4
- */
-public StyleRange(TextStyle style) {
- super(style);
-}
-
-/**
- * Create a new style range.
- *
- * @param start start offset of the style
- * @param length length of the style
- * @param foreground foreground color of the style, null if none
- * @param background background color of the style, null if none
- */
-public StyleRange(int start, int length, Color foreground, Color background) {
- super(null, foreground, background);
- this.start = start;
- this.length = length;
-}
-
-/**
- * Create a new style range.
- *
- * @param start start offset of the style
- * @param length length of the style
- * @param foreground foreground color of the style, null if none
- * @param background background color of the style, null if none
- * @param fontStyle font style of the style, may be SWT.NORMAL, SWT.ITALIC or SWT.BOLD
- */
-public StyleRange(int start, int length, Color foreground, Color background, int fontStyle) {
- this(start, length, foreground, background);
- this.fontStyle = fontStyle;
-}
-
-/**
- * Compares the argument to the receiver, and returns true
- * if they represent the same object using a class
- * specific comparison.
- *
- * @param object the object to compare with this object
- * @return true
if the object is the same as this object and false
otherwise
- *
- * @see #hashCode()
- */
-public boolean equals(Object object) {
- if (object == this) return true;
- if (object instanceof StyleRange) {
- StyleRange style = (StyleRange)object;
- if (start != style.start) return false;
- if (length != style.length) return false;
- return similarTo(style);
- }
- return false;
-}
-
-/**
- * Returns an integer hash code for the receiver. Any two
- * objects that return true
when passed to
- * equals
must return the same value for this
- * method.
- *
- * @return the receiver's hash
- *
- * @see #equals(Object)
- */
-public int hashCode() {
- return super.hashCode() ^ fontStyle;
-}
-boolean isVariableHeight() {
- return font != null || metrics != null || rise != 0;
-}
-/**
- * Returns whether or not the receiver is unstyled (i.e., does not have any
- * style attributes specified).
- *
- * @return true if the receiver is unstyled, false otherwise.
- */
-public boolean isUnstyled() {
- if (font != null) return false;
- if (rise != 0) return false;
- if (metrics != null) return false;
- if (foreground != null) return false;
- if (background != null) return false;
- if (fontStyle != SWT.NORMAL) return false;
- if (underline) return false;
- if (strikeout) return false;
- if (borderStyle != SWT.NONE) return false;
- return true;
-}
-
-/**
- * Compares the specified object to this StyleRange and answer if the two
- * are similar. The object must be an instance of StyleRange and have the
- * same field values for except for start and length.
- *
- * @param style the object to compare with this object
- * @return true if the objects are similar, false otherwise
- */
-public boolean similarTo(StyleRange style) {
- if (!super.equals(style)) return false;
- if (fontStyle != style.fontStyle) return false;
- return true;
-}
-
-/**
- * Returns a new StyleRange with the same values as this StyleRange.
- *
- * @return a shallow copy of this StyleRange
- */
-public Object clone() {
- try {
- return super.clone();
- } catch (CloneNotSupportedException e) {
- return null;
- }
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the StyleRange
- */
-public String toString() {
- StringBuffer buffer = new StringBuffer();
- buffer.append("StyleRange {");
- buffer.append(start);
- buffer.append(", ");
- buffer.append(length);
- buffer.append(", fontStyle=");
- switch (fontStyle) {
- case SWT.BOLD:
- buffer.append("bold");
- break;
- case SWT.ITALIC:
- buffer.append("italic");
- break;
- case SWT.BOLD | SWT.ITALIC:
- buffer.append("bold-italic");
- break;
- default:
- buffer.append("normal");
- }
- String str = super.toString();
- int index = str.indexOf('{');
- str = str.substring(index + 1);
- if (str.length() > 1) buffer.append(", ");
- buffer.append(str);
- return buffer.toString();
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java
deleted file mode 100755
index 50e1587b2e..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java
+++ /dev/null
@@ -1,9475 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.custom;
-
-
-import java.util.*;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.accessibility.*;
-import org.eclipse.swt.dnd.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.printing.*;
-import org.eclipse.swt.widgets.*;
-
-/**
- * A StyledText is an editable user interface object that displays lines
- * of text. The following style attributes can be defined for the text:
- * - * In addition to text style attributes, the background color of a line may - * be specified. - *
- * There are two ways to use this widget when specifying text style information. - * You may use the API that is defined for StyledText or you may define your own - * LineStyleListener. If you define your own listener, you will be responsible - * for maintaining the text style information for the widget. IMPORTANT: You may - * not define your own listener and use the StyledText API. The following - * StyledText API is not supported if you have defined a LineStyleListener: - *
- * There are two ways to use this widget when specifying line background colors. - * You may use the API that is defined for StyledText or you may define your own - * LineBackgroundListener. If you define your own listener, you will be responsible - * for maintaining the line background color information for the widget. - * IMPORTANT: You may not define your own listener and use the StyledText API. - * The following StyledText API is not supported if you have defined a - * LineBackgroundListener: - *
- * The content implementation for this widget may also be user-defined. To do so, - * you must implement the StyledTextContent interface and use the StyledText API - * setContent(StyledTextContent) to initialize the widget. - *
- *
- * IMPORTANT: This class is not intended to be subclassed. - *
- * - * @see StyledText snippets - * @see SWT Examples: CustomControlExample, TextEditor - * @see Sample code and further information - * @noextend This class is not intended to be subclassed by clients. - */ -public class StyledText extends Canvas { - static final char TAB = '\t'; - static final String PlatformLineDelimiter = System.getProperty("line.separator"); - static final int BIDI_CARET_WIDTH = 3; - static final int DEFAULT_WIDTH = 64; - static final int DEFAULT_HEIGHT = 64; - static final int V_SCROLL_RATE = 50; - static final int H_SCROLL_RATE = 10; - - static final int ExtendedModify = 3000; - static final int LineGetBackground = 3001; - static final int LineGetStyle = 3002; - static final int TextChanging = 3003; - static final int TextSet = 3004; - static final int VerifyKey = 3005; - static final int TextChanged = 3006; - static final int LineGetSegments = 3007; - static final int PaintObject = 3008; - static final int WordNext = 3009; - static final int WordPrevious = 3010; - static final int CaretMoved = 3011; - - static final int PREVIOUS_OFFSET_TRAILING = 0; - static final int OFFSET_LEADING = 1; - - Color selectionBackground; // selection background color - Color selectionForeground; // selection foreground color - StyledTextContent content; // native content (default or user specified) - StyledTextRenderer renderer; - Listener listener; - TextChangeListener textChangeListener; // listener for TextChanging, TextChanged and TextSet events from StyledTextContent - int verticalScrollOffset = 0; // pixel based - int horizontalScrollOffset = 0; // pixel based - int topIndex = 0; // top visible line - int topIndexY; - int clientAreaHeight = 0; // the client area height. Needed to calculate content width for new visible lines during Resize callback - int clientAreaWidth = 0; // the client area width. Needed during Resize callback to determine if line wrap needs to be recalculated - int tabLength = 4; // number of characters in a tab - int leftMargin; - int topMargin; - int rightMargin; - int bottomMargin; - Color marginColor; - int columnX; // keep track of the horizontal caret position when changing lines/pages. Fixes bug 5935 - int caretOffset; - int caretAlignment; - Point selection = new Point(0, 0); // x and y are start and end caret offsets of selection - Point clipboardSelection; // x and y are start and end caret offsets of previous selection - int selectionAnchor; // position of selection anchor. 0 based offset from beginning of text - Point doubleClickSelection; // selection after last mouse double click - boolean editable = true; - boolean wordWrap = false; - boolean doubleClickEnabled = true; // see getDoubleClickEnabled - boolean overwrite = false; // insert/overwrite edit mode - int textLimit = -1; // limits the number of characters the user can type in the widget. Unlimited by default. - Hashtable keyActionMap = new Hashtable(); - Color background = null; // workaround for bug 4791 - Color foreground = null; // - Clipboard clipboard; - int clickCount; - int autoScrollDirection = SWT.NULL; // the direction of autoscrolling (up, down, right, left) - int autoScrollDistance = 0; - int lastTextChangeStart; // cache data of the - int lastTextChangeNewLineCount; // last text changing - int lastTextChangeNewCharCount; // event for use in the - int lastTextChangeReplaceLineCount; // text changed handler - int lastTextChangeReplaceCharCount; - int lastCharCount = 0; - int lastLineBottom; // the bottom pixel of the last line been replaced - boolean isMirrored; - boolean bidiColoring = false; // apply the BIDI algorithm on text segments of the same color - Image leftCaretBitmap = null; - Image rightCaretBitmap = null; - int caretDirection = SWT.NULL; - int caretWidth = 0; - Caret defaultCaret = null; - boolean updateCaretDirection = true; - boolean fixedLineHeight; - boolean dragDetect = true; - IME ime; - Cursor cursor; - int alignment; - boolean justify; - int indent; - int lineSpacing; - int alignmentMargin; - - //block selection - boolean blockSelection; - int blockXAnchor = -1, blockYAnchor = -1; - int blockXLocation = -1, blockYLocation = -1; - - - final static boolean IS_MAC, IS_GTK, IS_MOTIF; - static { - String platform = SWT.getPlatform(); - IS_MAC = "carbon".equals(platform) || "cocoa".equals(platform); - IS_GTK = "gtk".equals(platform); - IS_MOTIF = "motif".equals(platform); - } - - /** - * The Printing class implements printing of a range of text. - * An instance ofPrinting
is returned in the
- * StyledText#print(Printer) API. The run() method may be
- * invoked from any thread.
- */
- static class Printing implements Runnable {
- final static int LEFT = 0; // left aligned header/footer segment
- final static int CENTER = 1; // centered header/footer segment
- final static int RIGHT = 2; // right aligned header/footer segment
-
- Printer printer;
- StyledTextRenderer printerRenderer;
- StyledTextPrintOptions printOptions;
- Rectangle clientArea;
- FontData fontData;
- Font printerFont;
- Hashtable resources;
- int tabLength;
- GC gc; // printer GC
- int pageWidth; // width of a printer page in pixels
- int startPage; // first page to print
- int endPage; // last page to print
- int startLine; // first (wrapped) line to print
- int endLine; // last (wrapped) line to print
- boolean singleLine; // widget single line mode
- Point selection = null; // selected text
- boolean mirrored; // indicates the printing gc should be mirrored
- int lineSpacing;
- int printMargin;
-
- /**
- * Creates an instance of Printing
.
- * Copies the widget content and rendering data that needs
- * to be requested from listeners.
- *
- * @param parent StyledText widget to print.
- * @param printer printer device to print on.
- * @param printOptions print options
- */
- Printing(StyledText styledText, Printer printer, StyledTextPrintOptions printOptions) {
- this.printer = printer;
- this.printOptions = printOptions;
- this.mirrored = (styledText.getStyle() & SWT.MIRRORED) != 0;
- singleLine = styledText.isSingleLine();
- startPage = 1;
- endPage = Integer.MAX_VALUE;
- PrinterData data = printer.getPrinterData();
- if (data.scope == PrinterData.PAGE_RANGE) {
- startPage = data.startPage;
- endPage = data.endPage;
- if (endPage < startPage) {
- int temp = endPage;
- endPage = startPage;
- startPage = temp;
- }
- } else if (data.scope == PrinterData.SELECTION) {
- selection = styledText.getSelectionRange();
- }
- printerRenderer = new StyledTextRenderer(printer, null);
- printerRenderer.setContent(copyContent(styledText.getContent()));
- cacheLineData(styledText);
- }
- /**
- * Caches all line data that needs to be requested from a listener.
- *
- * @param printerContent StyledTextContent
to request
- * line data for.
- */
- void cacheLineData(StyledText styledText) {
- StyledTextRenderer renderer = styledText.renderer;
- renderer.copyInto(printerRenderer);
- fontData = styledText.getFont().getFontData()[0];
- tabLength = styledText.tabLength;
- int lineCount = printerRenderer.lineCount;
- if (styledText.isListening(LineGetBackground) || (styledText.isBidi() && styledText.isListening(LineGetSegments)) || styledText.isListening(LineGetStyle)) {
- StyledTextContent content = printerRenderer.content;
- for (int i = 0; i < lineCount; i++) {
- String line = content.getLine(i);
- int lineOffset = content.getOffsetAtLine(i);
- StyledTextEvent event = styledText.getLineBackgroundData(lineOffset, line);
- if (event != null && event.lineBackground != null) {
- printerRenderer.setLineBackground(i, 1, event.lineBackground);
- }
- if (styledText.isBidi()) {
- int[] segments = styledText.getBidiSegments(lineOffset, line);
- printerRenderer.setLineSegments(i, 1, segments);
- }
- event = styledText.getLineStyleData(lineOffset, line);
- if (event != null) {
- printerRenderer.setLineIndent(i, 1, event.indent);
- printerRenderer.setLineAlignment(i, 1, event.alignment);
- printerRenderer.setLineJustify(i, 1, event.justify);
- printerRenderer.setLineBullet(i, 1, event.bullet);
- StyleRange[] styles = event.styles;
- if (styles != null && styles.length > 0) {
- printerRenderer.setStyleRanges(event.ranges, styles);
- }
- }
- }
- }
- Point screenDPI = styledText.getDisplay().getDPI();
- Point printerDPI = printer.getDPI();
- resources = new Hashtable ();
- for (int i = 0; i < lineCount; i++) {
- Color color = printerRenderer.getLineBackground(i, null);
- if (color != null) {
- if (printOptions.printLineBackground) {
- Color printerColor = (Color)resources.get(color);
- if (printerColor == null) {
- printerColor = new Color (printer, color.getRGB());
- resources.put(color, printerColor);
- }
- printerRenderer.setLineBackground(i, 1, printerColor);
- } else {
- printerRenderer.setLineBackground(i, 1, null);
- }
- }
- int indent = printerRenderer.getLineIndent(i, 0);
- if (indent != 0) {
- printerRenderer.setLineIndent(i, 1, indent * printerDPI.x / screenDPI.x);
- }
- }
- StyleRange[] styles = printerRenderer.styles;
- for (int i = 0; i < printerRenderer.styleCount; i++) {
- StyleRange style = styles[i];
- Font font = style.font;
- if (style.font != null) {
- Font printerFont = (Font)resources.get(font);
- if (printerFont == null) {
- printerFont = new Font (printer, font.getFontData());
- resources.put(font, printerFont);
- }
- style.font = printerFont;
- }
- Color color = style.foreground;
- if (color != null) {
- Color printerColor = (Color)resources.get(color);
- if (printOptions.printTextForeground) {
- if (printerColor == null) {
- printerColor = new Color (printer, color.getRGB());
- resources.put(color, printerColor);
- }
- style.foreground = printerColor;
- } else {
- style.foreground = null;
- }
- }
- color = style.background;
- if (color != null) {
- Color printerColor = (Color)resources.get(color);
- if (printOptions.printTextBackground) {
- if (printerColor == null) {
- printerColor = new Color (printer, color.getRGB());
- resources.put(color, printerColor);
- }
- style.background = printerColor;
- } else {
- style.background = null;
- }
- }
- if (!printOptions.printTextFontStyle) {
- style.fontStyle = SWT.NORMAL;
- }
- style.rise = style.rise * printerDPI.y / screenDPI.y;
- GlyphMetrics metrics = style.metrics;
- if (metrics != null) {
- metrics.ascent = metrics.ascent * printerDPI.y / screenDPI.y;
- metrics.descent = metrics.descent * printerDPI.y / screenDPI.y;
- metrics.width = metrics.width * printerDPI.x / screenDPI.x;
- }
- }
- lineSpacing = styledText.lineSpacing * printerDPI.y / screenDPI.y;
- if (printOptions.printLineNumbers) {
- printMargin = 3 * printerDPI.x / screenDPI.x;
- }
- }
- /**
- * Copies the text of the specified StyledTextContent
.
- *
- * @param original the StyledTextContent
to copy.
- */
- StyledTextContent copyContent(StyledTextContent original) {
- StyledTextContent printerContent = new DefaultContent();
- int insertOffset = 0;
- for (int i = 0; i < original.getLineCount(); i++) {
- int insertEndOffset;
- if (i < original.getLineCount() - 1) {
- insertEndOffset = original.getOffsetAtLine(i + 1);
- } else {
- insertEndOffset = original.getCharCount();
- }
- printerContent.replaceTextRange(insertOffset, 0, original.getTextRange(insertOffset, insertEndOffset - insertOffset));
- insertOffset = insertEndOffset;
- }
- return printerContent;
- }
- /**
- * Disposes of the resources and the PrintRenderer
.
- */
- void dispose() {
- if (gc != null) {
- gc.dispose();
- gc = null;
- }
- if (resources != null) {
- Enumeration enumeration = resources.elements();
- while (enumeration.hasMoreElements()) {
- Resource resource = (Resource) enumeration.nextElement();
- resource.dispose();
- }
- resources = null;
- }
- if (printerFont != null) {
- printerFont.dispose();
- printerFont = null;
- }
- if (printerRenderer != null) {
- printerRenderer.dispose();
- printerRenderer = null;
- }
- }
- void init() {
- Rectangle trim = printer.computeTrim(0, 0, 0, 0);
- Point dpi = printer.getDPI();
-
- printerFont = new Font(printer, fontData.getName(), fontData.getHeight(), SWT.NORMAL);
- clientArea = printer.getClientArea();
- pageWidth = clientArea.width;
- // one inch margin around text
- clientArea.x = dpi.x + trim.x;
- clientArea.y = dpi.y + trim.y;
- clientArea.width -= (clientArea.x + trim.width);
- clientArea.height -= (clientArea.y + trim.height);
-
- int style = mirrored ? SWT.RIGHT_TO_LEFT : SWT.LEFT_TO_RIGHT;
- gc = new GC(printer, style);
- gc.setFont(printerFont);
- printerRenderer.setFont(printerFont, tabLength);
- int lineHeight = printerRenderer.getLineHeight();
- if (printOptions.header != null) {
- clientArea.y += lineHeight * 2;
- clientArea.height -= lineHeight * 2;
- }
- if (printOptions.footer != null) {
- clientArea.height -= lineHeight * 2;
- }
-
- // TODO not wrapped
- StyledTextContent content = printerRenderer.content;
- startLine = 0;
- endLine = singleLine ? 0 : content.getLineCount() - 1;
- PrinterData data = printer.getPrinterData();
- if (data.scope == PrinterData.PAGE_RANGE) {
- int pageSize = clientArea.height / lineHeight;//WRONG
- startLine = (startPage - 1) * pageSize;
- } else if (data.scope == PrinterData.SELECTION) {
- startLine = content.getLineAtOffset(selection.x);
- if (selection.y > 0) {
- endLine = content.getLineAtOffset(selection.x + selection.y - 1);
- } else {
- endLine = startLine - 1;
- }
- }
- }
- /**
- * Prints the lines in the specified page range.
- */
- void print() {
- Color background = gc.getBackground();
- Color foreground = gc.getForeground();
- int paintY = clientArea.y;
- int paintX = clientArea.x;
- int width = clientArea.width;
- int page = startPage;
- int pageBottom = clientArea.y + clientArea.height;
- int orientation = gc.getStyle() & (SWT.RIGHT_TO_LEFT | SWT.LEFT_TO_RIGHT);
- TextLayout printLayout = null;
- if (printOptions.printLineNumbers || printOptions.header != null || printOptions.footer != null) {
- printLayout = new TextLayout(printer);
- printLayout.setFont(printerFont);
- }
- if (printOptions.printLineNumbers) {
- int numberingWidth = 0;
- int count = endLine - startLine + 1;
- String[] lineLabels = printOptions.lineLabels;
- if (lineLabels != null) {
- for (int i = startLine; i < Math.min(count, lineLabels.length); i++) {
- if (lineLabels[i] != null) {
- printLayout.setText(lineLabels[i]);
- int lineWidth = printLayout.getBounds().width;
- numberingWidth = Math.max(numberingWidth, lineWidth);
- }
- }
- } else {
- StringBuffer buffer = new StringBuffer("0");
- while ((count /= 10) > 0) buffer.append("0");
- printLayout.setText(buffer.toString());
- numberingWidth = printLayout.getBounds().width;
- }
- numberingWidth += printMargin;
- if (numberingWidth > width) numberingWidth = width;
- paintX += numberingWidth;
- width -= numberingWidth;
- }
- for (int i = startLine; i <= endLine && page <= endPage; i++) {
- if (paintY == clientArea.y) {
- printer.startPage();
- printDecoration(page, true, printLayout);
- }
- TextLayout layout = printerRenderer.getTextLayout(i, orientation, width, lineSpacing);
- Color lineBackground = printerRenderer.getLineBackground(i, background);
- int paragraphBottom = paintY + layout.getBounds().height;
- if (paragraphBottom <= pageBottom) {
- //normal case, the whole paragraph fits in the current page
- printLine(paintX, paintY, gc, foreground, lineBackground, layout, printLayout, i);
- paintY = paragraphBottom;
- } else {
- int lineCount = layout.getLineCount();
- while (paragraphBottom > pageBottom && lineCount > 0) {
- lineCount--;
- paragraphBottom -= layout.getLineBounds(lineCount).height + layout.getSpacing();
- }
- if (lineCount == 0) {
- //the whole paragraph goes to the next page
- printDecoration(page, false, printLayout);
- printer.endPage();
- page++;
- if (page <= endPage) {
- printer.startPage();
- printDecoration(page, true, printLayout);
- paintY = clientArea.y;
- printLine(paintX, paintY, gc, foreground, lineBackground, layout, printLayout, i);
- paintY += layout.getBounds().height;
- }
- } else {
- //draw paragraph top in the current page and paragraph bottom in the next
- int height = paragraphBottom - paintY;
- gc.setClipping(clientArea.x, paintY, clientArea.width, height);
- printLine(paintX, paintY, gc, foreground, lineBackground, layout, printLayout, i);
- gc.setClipping((Rectangle)null);
- printDecoration(page, false, printLayout);
- printer.endPage();
- page++;
- if (page <= endPage) {
- printer.startPage();
- printDecoration(page, true, printLayout);
- paintY = clientArea.y - height;
- int layoutHeight = layout.getBounds().height;
- gc.setClipping(clientArea.x, clientArea.y, clientArea.width, layoutHeight - height);
- printLine(paintX, paintY, gc, foreground, lineBackground, layout, printLayout, i);
- gc.setClipping((Rectangle)null);
- paintY += layoutHeight;
- }
- }
- }
- printerRenderer.disposeTextLayout(layout);
- }
- if (page <= endPage && paintY > clientArea.y) {
- // close partial page
- printDecoration(page, false, printLayout);
- printer.endPage();
- }
- if (printLayout != null) printLayout.dispose();
- }
- /**
- * Print header or footer decorations.
- *
- * @param page page number to print, if specified in the StyledTextPrintOptions header or footer.
- * @param header true = print the header, false = print the footer
- */
- void printDecoration(int page, boolean header, TextLayout layout) {
- String text = header ? printOptions.header : printOptions.footer;
- if (text == null) return;
- int lastSegmentIndex = 0;
- for (int i = 0; i < 3; i++) {
- int segmentIndex = text.indexOf(StyledTextPrintOptions.SEPARATOR, lastSegmentIndex);
- String segment;
- if (segmentIndex == -1) {
- segment = text.substring(lastSegmentIndex);
- printDecorationSegment(segment, i, page, header, layout);
- break;
- } else {
- segment = text.substring(lastSegmentIndex, segmentIndex);
- printDecorationSegment(segment, i, page, header, layout);
- lastSegmentIndex = segmentIndex + StyledTextPrintOptions.SEPARATOR.length();
- }
- }
- }
- /**
- * Print one segment of a header or footer decoration.
- * Headers and footers have three different segments.
- * One each for left aligned, centered, and right aligned text.
- *
- * @param segment decoration segment to print
- * @param alignment alignment of the segment. 0=left, 1=center, 2=right
- * @param page page number to print, if specified in the decoration segment.
- * @param header true = print the header, false = print the footer
- */
- void printDecorationSegment(String segment, int alignment, int page, boolean header, TextLayout layout) {
- int pageIndex = segment.indexOf(StyledTextPrintOptions.PAGE_TAG);
- if (pageIndex != -1) {
- int pageTagLength = StyledTextPrintOptions.PAGE_TAG.length();
- StringBuffer buffer = new StringBuffer(segment.substring (0, pageIndex));
- buffer.append (page);
- buffer.append (segment.substring(pageIndex + pageTagLength));
- segment = buffer.toString();
- }
- if (segment.length() > 0) {
- layout.setText(segment);
- int segmentWidth = layout.getBounds().width;
- int segmentHeight = printerRenderer.getLineHeight();
- int drawX = 0, drawY;
- if (alignment == LEFT) {
- drawX = clientArea.x;
- } else if (alignment == CENTER) {
- drawX = (pageWidth - segmentWidth) / 2;
- } else if (alignment == RIGHT) {
- drawX = clientArea.x + clientArea.width - segmentWidth;
- }
- if (header) {
- drawY = clientArea.y - segmentHeight * 2;
- } else {
- drawY = clientArea.y + clientArea.height + segmentHeight;
- }
- layout.draw(gc, drawX, drawY);
- }
- }
- void printLine(int x, int y, GC gc, Color foreground, Color background, TextLayout layout, TextLayout printLayout, int index) {
- if (background != null) {
- Rectangle rect = layout.getBounds();
- gc.setBackground(background);
- gc.fillRectangle(x, y, rect.width, rect.height);
-
-// int lineCount = layout.getLineCount();
-// for (int i = 0; i < lineCount; i++) {
-// Rectangle rect = layout.getLineBounds(i);
-// rect.x += paintX;
-// rect.y += paintY + layout.getSpacing();
-// rect.width = width;//layout bounds
-// gc.fillRectangle(rect);
-// }
- }
- if (printOptions.printLineNumbers) {
- FontMetrics metrics = layout.getLineMetrics(0);
- printLayout.setAscent(metrics.getAscent() + metrics.getLeading());
- printLayout.setDescent(metrics.getDescent());
- String[] lineLabels = printOptions.lineLabels;
- if (lineLabels != null) {
- if (0 <= index && index < lineLabels.length && lineLabels[index] != null) {
- printLayout.setText(lineLabels[index]);
- } else {
- printLayout.setText("");
- }
- } else {
- printLayout.setText(String.valueOf(index));
- }
- int paintX = x - printMargin - printLayout.getBounds().width;
- printLayout.draw(gc, paintX, y);
- printLayout.setAscent(-1);
- printLayout.setDescent(-1);
- }
- gc.setForeground(foreground);
- layout.draw(gc, x, y);
- }
- /**
- * Starts a print job and prints the pages specified in the constructor.
- */
- public void run() {
- String jobName = printOptions.jobName;
- if (jobName == null) {
- jobName = "Printing";
- }
- if (printer.startJob(jobName)) {
- init();
- print();
- dispose();
- printer.endJob();
- }
- }
- }
- /**
- * The RTFWriter
class is used to write widget content as
- * rich text. The implementation complies with the RTF specification
- * version 1.5.
- * - * toString() is guaranteed to return a valid RTF string only after - * close() has been called. - *
- * Whole and partial lines and line breaks can be written. Lines will be - * formatted using the styles queried from the LineStyleListener, if - * set, or those set directly in the widget. All styles are applied to - * the RTF stream like they are rendered by the widget. In addition, the - * widget font name and size is used for the whole text. - *
- */ - class RTFWriter extends TextWriter { - static final int DEFAULT_FOREGROUND = 0; - static final int DEFAULT_BACKGROUND = 1; - Vector colorTable, fontTable; - boolean WriteUnicode; - - /** - * Creates a RTF writer that writes content starting at offset "start" - * in the document.start
and length
can be set to specify partial
- * lines.
- *
- * @param start start offset of content to write, 0 based from
- * beginning of document
- * @param length length of content to write
- */
- public RTFWriter(int start, int length) {
- super(start, length);
- colorTable = new Vector();
- fontTable = new Vector();
- colorTable.addElement(getForeground());
- colorTable.addElement(getBackground());
- fontTable.addElement(getFont());
- setUnicode();
- }
- /**
- * Closes the RTF writer. Once closed no more content can be written.
- * NOTE: toString()
does not return a valid RTF string until
- * close()
has been called.
- */
- public void close() {
- if (!isClosed()) {
- writeHeader();
- write("\n}}\0");
- super.close();
- }
- }
- /**
- * Returns the index of the specified color in the RTF color table.
- *
- * @param color the color
- * @param defaultIndex return value if color is null
- * @return the index of the specified color in the RTF color table
- * or "defaultIndex" if "color" is null.
- */
- int getColorIndex(Color color, int defaultIndex) {
- if (color == null) return defaultIndex;
- int index = colorTable.indexOf(color);
- if (index == -1) {
- index = colorTable.size();
- colorTable.addElement(color);
- }
- return index;
- }
- /**
- * Returns the index of the specified color in the RTF color table.
- *
- * @param color the color
- * @param defaultIndex return value if color is null
- * @return the index of the specified color in the RTF color table
- * or "defaultIndex" if "color" is null.
- */
- int getFontIndex(Font font) {
- int index = fontTable.indexOf(font);
- if (index == -1) {
- index = fontTable.size();
- fontTable.addElement(font);
- }
- return index;
- }
- /**
- * Determines if Unicode RTF should be written.
- * Don't write Unicode RTF on Windows 95/98/ME or NT.
- */
- void setUnicode() {
- final String Win95 = "windows 95";
- final String Win98 = "windows 98";
- final String WinME = "windows me";
- final String WinNT = "windows nt";
- String osName = System.getProperty("os.name").toLowerCase();
- String osVersion = System.getProperty("os.version");
- int majorVersion = 0;
-
- if (osName.startsWith(WinNT) && osVersion != null) {
- int majorIndex = osVersion.indexOf('.');
- if (majorIndex != -1) {
- osVersion = osVersion.substring(0, majorIndex);
- try {
- majorVersion = Integer.parseInt(osVersion);
- } catch (NumberFormatException exception) {
- // ignore exception. version number remains unknown.
- // will write without Unicode
- }
- }
- }
- WriteUnicode = !osName.startsWith(Win95) &&
- !osName.startsWith(Win98) &&
- !osName.startsWith(WinME) &&
- (!osName.startsWith(WinNT) || majorVersion > 4);
- }
- /**
- * Appends the specified segment of "string" to the RTF data.
- * Copy from start
up to, but excluding, end
.
- *
- * @param string string to copy a segment from. Must not contain
- * line breaks. Line breaks should be written using writeLineDelimiter()
- * @param start start offset of segment. 0 based.
- * @param end end offset of segment
- */
- void write(String string, int start, int end) {
- for (int index = start; index < end; index++) {
- char ch = string.charAt(index);
- if (ch > 0xFF && WriteUnicode) {
- // write the sub string from the last escaped character
- // to the current one. Fixes bug 21698.
- if (index > start) {
- write(string.substring(start, index));
- }
- write("\\u");
- write(Integer.toString((short) ch));
- write('?'); // ANSI representation (1 byte long, \\uc1)
- start = index + 1;
- } else if (ch == '}' || ch == '{' || ch == '\\') {
- // write the sub string from the last escaped character
- // to the current one. Fixes bug 21698.
- if (index > start) {
- write(string.substring(start, index));
- }
- write('\\');
- write(ch);
- start = index + 1;
- }
- }
- // write from the last escaped character to the end.
- // Fixes bug 21698.
- if (start < end) {
- write(string.substring(start, end));
- }
- }
- /**
- * Writes the RTF header including font table and color table.
- */
- void writeHeader() {
- StringBuffer header = new StringBuffer();
- FontData fontData = getFont().getFontData()[0];
- header.append("{\\rtf1\\ansi");
- // specify code page, necessary for copy to work in bidi
- // systems that don't support Unicode RTF.
- String cpg = System.getProperty("file.encoding").toLowerCase();
- if (cpg.startsWith("cp") || cpg.startsWith("ms")) {
- cpg = cpg.substring(2, cpg.length());
- header.append("\\ansicpg");
- header.append(cpg);
- }
- header.append("\\uc1\\deff0{\\fonttbl{\\f0\\fnil ");
- header.append(fontData.getName());
- header.append(";");
- for (int i = 1; i < fontTable.size(); i++) {
- header.append("\\f");
- header.append(i);
- header.append(" ");
- FontData fd = ((Font)fontTable.elementAt(i)).getFontData()[0];
- header.append(fd.getName());
- header.append(";");
- }
- header.append("}}\n{\\colortbl");
- for (int i = 0; i < colorTable.size(); i++) {
- Color color = (Color) colorTable.elementAt(i);
- header.append("\\red");
- header.append(color.getRed());
- header.append("\\green");
- header.append(color.getGreen());
- header.append("\\blue");
- header.append(color.getBlue());
- header.append(";");
- }
- // some RTF readers ignore the deff0 font tag. Explicitly
- // set the font for the whole document to work around this.
- header.append("}\n{\\f0\\fs");
- // font size is specified in half points
- header.append(fontData.getHeight() * 2);
- header.append(" ");
- write(header.toString(), 0);
- }
- /**
- * Appends the specified line text to the RTF data. Lines will be formatted
- * using the styles queried from the LineStyleListener, if set, or those set
- * directly in the widget.
- *
- * @param line line text to write as RTF. Must not contain line breaks
- * Line breaks should be written using writeLineDelimiter()
- * @param lineOffset offset of the line. 0 based from the start of the
- * widget document. Any text occurring before the start offset or after the
- * end offset specified during object creation is ignored.
- * @exception SWTException - * Use the colors and font styles specified in "styles" and "lineBackground". - * Formatting is written to reflect the text rendering by the text widget. - * Style background colors take precedence over the line background color. - * Background colors are written using the \highlight tag (vs. the \cb tag). - *
- * - * @param line line text to write as RTF. Must not contain line breaks - * Line breaks should be written using writeLineDelimiter() - * @param lineOffset offset of the line. 0 based from the start of the - * widget document. Any text occurring before the start offset or after the - * end offset specified during object creation is ignored. - * @param styles styles to use for formatting. Must not be null. - * @param lineBackground line background color to use for formatting. - * May be null. - */ - void writeStyledLine(String line, int lineOffset, int ranges[], StyleRange[] styles, Color lineBackground, int indent, int alignment, boolean justify) { - int lineLength = line.length(); - int startOffset = getStart(); - int writeOffset = startOffset - lineOffset; - if (writeOffset >= lineLength) return; - int lineIndex = Math.max(0, writeOffset); - - write("\\fi"); - write(indent); - switch (alignment) { - case SWT.LEFT: write("\\ql"); break; - case SWT.CENTER: write("\\qc"); break; - case SWT.RIGHT: write("\\qr"); break; - } - if (justify) write("\\qj"); - write(" "); - - if (lineBackground != null) { - write("{\\highlight"); - write(getColorIndex(lineBackground, DEFAULT_BACKGROUND)); - write(" "); - } - int endOffset = startOffset + super.getCharCount(); - int lineEndOffset = Math.min(lineLength, endOffset - lineOffset); - for (int i = 0; i < styles.length; i++) { - StyleRange style = styles[i]; - int start, end; - if (ranges != null) { - start = ranges[i << 1] - lineOffset; - end = start + ranges[(i << 1) + 1]; - } else { - start = style.start - lineOffset; - end = start + style.length; - } - // skip over partial first line - if (end < writeOffset) { - continue; - } - // style starts beyond line end or RTF write end - if (start >= lineEndOffset) { - break; - } - // write any unstyled text - if (lineIndex < start) { - // copy to start of style - // style starting beyond end of write range or end of line - // is guarded against above. - write(line, lineIndex, start); - lineIndex = start; - } - // write styled text - write("{\\cf"); - write(getColorIndex(style.foreground, DEFAULT_FOREGROUND)); - int colorIndex = getColorIndex(style.background, DEFAULT_BACKGROUND); - if (colorIndex != DEFAULT_BACKGROUND) { - write("\\highlight"); - write(colorIndex); - } - Font font = style.font; - if (font != null) { - int fontIndex = getFontIndex(font); - write("\\f"); - write(fontIndex); - FontData fontData = font.getFontData()[0]; - write("\\fs"); - write(fontData.getHeight() * 2); - } else { - if ((style.fontStyle & SWT.BOLD) != 0) { - write("\\b"); - } - if ((style.fontStyle & SWT.ITALIC) != 0) { - write("\\i"); - } - } - if (style.underline) { - write("\\ul"); - } - if (style.strikeout) { - write("\\strike"); - } - write(" "); - // copy to end of style or end of write range or end of line - int copyEnd = Math.min(end, lineEndOffset); - // guard against invalid styles and let style processing continue - copyEnd = Math.max(copyEnd, lineIndex); - write(line, lineIndex, copyEnd); - if (font == null) { - if ((style.fontStyle & SWT.BOLD) != 0) { - write("\\b0"); - } - if ((style.fontStyle & SWT.ITALIC) != 0) { - write("\\i0"); - } - } - if (style.underline) { - write("\\ul0"); - } - if (style.strikeout) { - write("\\strike0"); - } - write("}"); - lineIndex = copyEnd; - } - // write unstyled text at the end of the line - if (lineIndex < lineEndOffset) { - write(line, lineIndex, lineEndOffset); - } - if (lineBackground != null) write("}"); - } - } - /** - * TheTextWriter
class is used to write widget content to
- * a string. Whole and partial lines and line breaks can be written. To write
- * partial lines, specify the start and length of the desired segment
- * during object creation.
- *
- * NOTE: toString()
is guaranteed to return a valid string only after close()
- * has been called.
- *
start
and length
can be set to specify partial lines.
- *
- * @param start start offset of content to write, 0 based from beginning of document
- * @param length length of content to write
- */
- public TextWriter(int start, int length) {
- buffer = new StringBuffer(length);
- startOffset = start;
- endOffset = start + length;
- }
- /**
- * Closes the writer. Once closed no more content can be written.
- * NOTE: toString()
is not guaranteed to return a valid string unless
- * the writer is closed.
- */
- public void close() {
- if (!isClosed) {
- isClosed = true;
- }
- }
- /**
- * Returns the number of characters to write.
- * @return the integer number of characters to write
- */
- public int getCharCount() {
- return endOffset - startOffset;
- }
- /**
- * Returns the offset where writing starts. 0 based from the start of
- * the widget text. Used to write partial lines.
- * @return the integer offset where writing starts
- */
- public int getStart() {
- return startOffset;
- }
- /**
- * Returns whether the writer is closed.
- * @return a boolean specifying whether or not the writer is closed
- */
- public boolean isClosed() {
- return isClosed;
- }
- /**
- * Returns the string. close()
must be called before toString()
- * is guaranteed to return a valid string.
- *
- * @return the string
- */
- public String toString() {
- return buffer.toString();
- }
- /**
- * Appends the given string to the data.
- */
- void write(String string) {
- buffer.append(string);
- }
- /**
- * Inserts the given string to the data at the specified offset.
- * - * Do nothing if "offset" is < 0 or > getCharCount() - *
- * - * @param string text to insert - * @param offset offset in the existing data to insert "string" at. - */ - void write(String string, int offset) { - if (offset < 0 || offset > buffer.length()) { - return; - } - buffer.insert(offset, string); - } - /** - * Appends the given int to the data. - */ - void write(int i) { - buffer.append(i); - } - /** - * Appends the given character to the data. - */ - void write(char i) { - buffer.append(i); - } - /** - * Appends the specified line text to the data. - * - * @param line line text to write. Must not contain line breaks - * Line breaks should be written using writeLineDelimiter() - * @param lineOffset offset of the line. 0 based from the start of the - * widget document. Any text occurring before the start offset or after the - * end offset specified during object creation is ignored. - * @exception SWTException
- * The style value is either one of the style constants defined in
- * class SWT
which is applicable to instances of this
- * class, or must be built by bitwise OR'ing together
- * (that is, using the int
"|" operator) two or more
- * of those SWT
style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- *
- * A BidiSegmentEvent is sent - * whenever a line of text is measured or rendered. The user can - * specify text ranges in the line that should be treated as if they - * had a different direction than the surrounding text. - * This may be used when adjacent segments of right-to-left text should - * not be reordered relative to each other. - * E.g., Multiple Java string literals in a right-to-left language - * should generally remain in logical order to each other, that is, the - * way they are stored. - *
- * - * @param listener the listener - * @exception SWTException
- * When widgetSelected
is called, the event x and y fields contain
- * the start and end caret indices of the selection.
- * widgetDefaultSelected
is not called for StyledTexts.
- *
DND.CLIPBOARD
clipboard.
- *
- * The text will be put on the clipboard in plain text format and RTF format.
- * The DND.CLIPBOARD
clipboard is used for data that is
- * transferred by keyboard accelerator (such as Ctrl+C/Ctrl+V) or
- * by menu action.
- *
- * The clipboardType is one of the clipboard constants defined in class
- * DND
. The DND.CLIPBOARD
clipboard is
- * used for data that is transferred by keyboard accelerator (such as Ctrl+C/Ctrl+V)
- * or by menu action. The DND.SELECTION_CLIPBOARD
- * clipboard is used for data that is transferred by selecting text and pasting
- * with the middle mouse button.
- *
- * Returns only the first line if the widget has the SWT.SINGLE style. - *
- * - * @param text the text that may have line delimiters that don't - * match the model line delimiter. Possible line delimiters - * are CR ('\r'), LF ('\n'), CR/LF ("\r\n") - * @return the converted text that only uses the line delimiter - * specified by the model. Returns only the first line if the widget - * has the SWT.SINGLE style. - */ -String getModelDelimitedText(String text) { - int length = text.length(); - if (length == 0) { - return text; - } - int crIndex = 0; - int lfIndex = 0; - int i = 0; - StringBuffer convertedText = new StringBuffer(length); - String delimiter = getLineDelimiter(); - while (i < length) { - if (crIndex != -1) { - crIndex = text.indexOf(SWT.CR, i); - } - if (lfIndex != -1) { - lfIndex = text.indexOf(SWT.LF, i); - } - if (lfIndex == -1 && crIndex == -1) { // no more line breaks? - break; - } else if ((crIndex < lfIndex && crIndex != -1) || lfIndex == -1) { - convertedText.append(text.substring(i, crIndex)); - if (lfIndex == crIndex + 1) { // CR/LF combination? - i = lfIndex + 1; - } else { - i = crIndex + 1; - } - } else { // LF occurs before CR! - convertedText.append(text.substring(i, lfIndex)); - i = lfIndex + 1; - } - if (isSingleLine()) { - break; - } - convertedText.append(delimiter); - } - // copy remaining text if any and if not in single line mode or no - // text copied thus far (because there only is one line) - if (i < length && (!isSingleLine() || convertedText.length() == 0)) { - convertedText.append(text.substring(i)); - } - return convertedText.toString(); -} -boolean checkDragDetect(Event event) { - if (!isListening(SWT.DragDetect)) return false; - if (IS_MOTIF) { - if (event.button != 2) return false; - } else { - if (event.button != 1) return false; - } - if (blockSelection && blockXLocation != -1) { - Rectangle rect = getBlockSelectionRectangle(); - if (rect.contains(event.x, event.y)) { - return dragDetect(event); - } - } else { - if (selection.x == selection.y) return false; - int offset = getOffsetAtPoint(event.x, event.y, null, true); - if (selection.x <= offset && offset < selection.y) { - return dragDetect(event); - } - } - return false; -} -/** - * Creates default key bindings. - */ -void createKeyBindings() { - int nextKey = isMirrored() ? SWT.ARROW_LEFT : SWT.ARROW_RIGHT; - int previousKey = isMirrored() ? SWT.ARROW_RIGHT : SWT.ARROW_LEFT; - - // Navigation - setKeyBinding(SWT.ARROW_UP, ST.LINE_UP); - setKeyBinding(SWT.ARROW_DOWN, ST.LINE_DOWN); - if (IS_MAC) { - setKeyBinding(previousKey | SWT.MOD1, ST.LINE_START); - setKeyBinding(nextKey | SWT.MOD1, ST.LINE_END); - setKeyBinding(SWT.HOME, ST.TEXT_START); - setKeyBinding(SWT.END, ST.TEXT_END); - setKeyBinding(SWT.ARROW_UP | SWT.MOD1, ST.TEXT_START); - setKeyBinding(SWT.ARROW_DOWN | SWT.MOD1, ST.TEXT_END); - setKeyBinding(nextKey | SWT.MOD3, ST.WORD_NEXT); - setKeyBinding(previousKey | SWT.MOD3, ST.WORD_PREVIOUS); - } else { - setKeyBinding(SWT.HOME, ST.LINE_START); - setKeyBinding(SWT.END, ST.LINE_END); - setKeyBinding(SWT.HOME | SWT.MOD1, ST.TEXT_START); - setKeyBinding(SWT.END | SWT.MOD1, ST.TEXT_END); - setKeyBinding(nextKey | SWT.MOD1, ST.WORD_NEXT); - setKeyBinding(previousKey | SWT.MOD1, ST.WORD_PREVIOUS); - } - setKeyBinding(SWT.PAGE_UP, ST.PAGE_UP); - setKeyBinding(SWT.PAGE_DOWN, ST.PAGE_DOWN); - setKeyBinding(SWT.PAGE_UP | SWT.MOD1, ST.WINDOW_START); - setKeyBinding(SWT.PAGE_DOWN | SWT.MOD1, ST.WINDOW_END); - setKeyBinding(nextKey, ST.COLUMN_NEXT); - setKeyBinding(previousKey, ST.COLUMN_PREVIOUS); - - // Selection - setKeyBinding(SWT.ARROW_UP | SWT.MOD2, ST.SELECT_LINE_UP); - setKeyBinding(SWT.ARROW_DOWN | SWT.MOD2, ST.SELECT_LINE_DOWN); - if (IS_MAC) { - setKeyBinding(previousKey | SWT.MOD1 | SWT.MOD2, ST.SELECT_LINE_START); - setKeyBinding(nextKey | SWT.MOD1 | SWT.MOD2, ST.SELECT_LINE_END); - setKeyBinding(SWT.HOME | SWT.MOD2, ST.SELECT_TEXT_START); - setKeyBinding(SWT.END | SWT.MOD2, ST.SELECT_TEXT_END); - setKeyBinding(SWT.ARROW_UP | SWT.MOD1 | SWT.MOD2, ST.SELECT_TEXT_START); - setKeyBinding(SWT.ARROW_DOWN | SWT.MOD1 | SWT.MOD2, ST.SELECT_TEXT_END); - setKeyBinding(nextKey | SWT.MOD2 | SWT.MOD3, ST.SELECT_WORD_NEXT); - setKeyBinding(previousKey | SWT.MOD2 | SWT.MOD3, ST.SELECT_WORD_PREVIOUS); - } else { - setKeyBinding(SWT.HOME | SWT.MOD2, ST.SELECT_LINE_START); - setKeyBinding(SWT.END | SWT.MOD2, ST.SELECT_LINE_END); - setKeyBinding(SWT.HOME | SWT.MOD1 | SWT.MOD2, ST.SELECT_TEXT_START); - setKeyBinding(SWT.END | SWT.MOD1 | SWT.MOD2, ST.SELECT_TEXT_END); - setKeyBinding(nextKey | SWT.MOD1 | SWT.MOD2, ST.SELECT_WORD_NEXT); - setKeyBinding(previousKey | SWT.MOD1 | SWT.MOD2, ST.SELECT_WORD_PREVIOUS); - } - setKeyBinding(SWT.PAGE_UP | SWT.MOD2, ST.SELECT_PAGE_UP); - setKeyBinding(SWT.PAGE_DOWN | SWT.MOD2, ST.SELECT_PAGE_DOWN); - setKeyBinding(SWT.PAGE_UP | SWT.MOD1 | SWT.MOD2, ST.SELECT_WINDOW_START); - setKeyBinding(SWT.PAGE_DOWN | SWT.MOD1 | SWT.MOD2, ST.SELECT_WINDOW_END); - setKeyBinding(nextKey | SWT.MOD2, ST.SELECT_COLUMN_NEXT); - setKeyBinding(previousKey | SWT.MOD2, ST.SELECT_COLUMN_PREVIOUS); - - // Modification - // Cut, Copy, Paste - setKeyBinding('X' | SWT.MOD1, ST.CUT); - setKeyBinding('C' | SWT.MOD1, ST.COPY); - setKeyBinding('V' | SWT.MOD1, ST.PASTE); - if (IS_MAC) { - setKeyBinding(SWT.DEL | SWT.MOD2, ST.DELETE_NEXT); - setKeyBinding(SWT.BS | SWT.MOD3, ST.DELETE_WORD_PREVIOUS); - setKeyBinding(SWT.DEL | SWT.MOD3, ST.DELETE_WORD_NEXT); - } else { - // Cut, Copy, Paste Wordstar style - setKeyBinding(SWT.DEL | SWT.MOD2, ST.CUT); - setKeyBinding(SWT.INSERT | SWT.MOD1, ST.COPY); - setKeyBinding(SWT.INSERT | SWT.MOD2, ST.PASTE); - } - setKeyBinding(SWT.BS | SWT.MOD2, ST.DELETE_PREVIOUS); - setKeyBinding(SWT.BS, ST.DELETE_PREVIOUS); - setKeyBinding(SWT.DEL, ST.DELETE_NEXT); - setKeyBinding(SWT.BS | SWT.MOD1, ST.DELETE_WORD_PREVIOUS); - setKeyBinding(SWT.DEL | SWT.MOD1, ST.DELETE_WORD_NEXT); - - // Miscellaneous - setKeyBinding(SWT.INSERT, ST.TOGGLE_OVERWRITE); -} -/** - * Create the bitmaps to use for the caret in bidi mode. This - * method only needs to be called upon widget creation and when the - * font changes (the caret bitmap height needs to match font height). - */ -void createCaretBitmaps() { - int caretWidth = BIDI_CARET_WIDTH; - Display display = getDisplay(); - if (leftCaretBitmap != null) { - if (defaultCaret != null && leftCaretBitmap.equals(defaultCaret.getImage())) { - defaultCaret.setImage(null); - } - leftCaretBitmap.dispose(); - } - int lineHeight = renderer.getLineHeight(); - leftCaretBitmap = new Image(display, caretWidth, lineHeight); - GC gc = new GC (leftCaretBitmap); - gc.setBackground(display.getSystemColor(SWT.COLOR_BLACK)); - gc.fillRectangle(0, 0, caretWidth, lineHeight); - gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE)); - gc.drawLine(0,0,0,lineHeight); - gc.drawLine(0,0,caretWidth-1,0); - gc.drawLine(0,1,1,1); - gc.dispose(); - - if (rightCaretBitmap != null) { - if (defaultCaret != null && rightCaretBitmap.equals(defaultCaret.getImage())) { - defaultCaret.setImage(null); - } - rightCaretBitmap.dispose(); - } - rightCaretBitmap = new Image(display, caretWidth, lineHeight); - gc = new GC (rightCaretBitmap); - gc.setBackground(display.getSystemColor(SWT.COLOR_BLACK)); - gc.fillRectangle(0, 0, caretWidth, lineHeight); - gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE)); - gc.drawLine(caretWidth-1,0,caretWidth-1,lineHeight); - gc.drawLine(0,0,caretWidth-1,0); - gc.drawLine(caretWidth-1,1,1,1); - gc.dispose(); -} -/** - * Moves the selected text to the clipboard. The text will be put in the - * clipboard in plain text format and RTF format. - * - * @exception SWTException- * If a carriage return was typed replace it with the line break character - * used by the widget on this platform. - *
- * - * @param key the character typed by the user - */ -void doContent(char key) { - if (blockSelection && blockXLocation != -1) { - insertBlockSelectionText(key, SWT.NULL); - return; - } - - Event event = new Event(); - event.start = selection.x; - event.end = selection.y; - // replace a CR line break with the widget line break - // CR does not make sense on Windows since most (all?) applications - // don't recognize CR as a line break. - if (key == SWT.CR || key == SWT.LF) { - if (!isSingleLine()) { - event.text = getLineDelimiter(); - } - } else if (selection.x == selection.y && overwrite && key != TAB) { - // no selection and overwrite mode is on and the typed key is not a - // tab character (tabs are always inserted without overwriting)? - int lineIndex = content.getLineAtOffset(event.end); - int lineOffset = content.getOffsetAtLine(lineIndex); - String line = content.getLine(lineIndex); - // replace character at caret offset if the caret is not at the - // end of the line - if (event.end < lineOffset + line.length()) { - event.end++; - } - event.text = new String(new char[] {key}); - } else { - event.text = new String(new char[] {key}); - } - if (event.text != null) { - if (textLimit > 0 && content.getCharCount() - (event.end - event.start) >= textLimit) { - return; - } - sendKeyEvent(event); - } -} -/** - * Moves the caret after the last character of the widget content. - */ -void doContentEnd() { - // place caret at end of first line if receiver is in single - // line mode. fixes 4820. - if (isSingleLine()) { - doLineEnd(); - } else { - int length = content.getCharCount(); - if (caretOffset < length) { - setCaretOffset(length, SWT.DEFAULT); - showCaret(); - } - } -} -/** - * Moves the caret in front of the first character of the widget content. - */ -void doContentStart() { - if (caretOffset > 0) { - setCaretOffset(0, SWT.DEFAULT); - showCaret(); - } -} -/** - * Moves the caret to the start of the selection if a selection exists. - * Otherwise, if no selection exists move the cursor according to the - * cursor selection rules. - * - * @see #doSelectionCursorPrevious - */ -void doCursorPrevious() { - if (selection.y - selection.x > 0) { - setCaretOffset(selection.x, OFFSET_LEADING); - showCaret(); - } else { - doSelectionCursorPrevious(); - } -} -/** - * Moves the caret to the end of the selection if a selection exists. - * Otherwise, if no selection exists move the cursor according to the - * cursor selection rules. - * - * @see #doSelectionCursorNext - */ -void doCursorNext() { - if (selection.y - selection.x > 0) { - setCaretOffset(selection.y, PREVIOUS_OFFSET_TRAILING); - showCaret(); - } else { - doSelectionCursorNext(); - } -} -/** - * Deletes the next character. Delete the selected text if any. - */ -void doDelete() { - Event event = new Event(); - event.text = ""; - if (selection.x != selection.y) { - event.start = selection.x; - event.end = selection.y; - sendKeyEvent(event); - } else if (caretOffset < content.getCharCount()) { - int line = content.getLineAtOffset(caretOffset); - int lineOffset = content.getOffsetAtLine(line); - int lineLength = content.getLine(line).length(); - if (caretOffset == lineOffset + lineLength) { - event.start = caretOffset; - event.end = content.getOffsetAtLine(line + 1); - } else { - event.start = caretOffset; - event.end = getClusterNext(caretOffset, line); - } - sendKeyEvent(event); - } -} -/** - * Deletes the next word. - */ -void doDeleteWordNext() { - if (selection.x != selection.y) { - // if a selection exists, treat the as if - // only the delete key was pressed - doDelete(); - } else { - Event event = new Event(); - event.text = ""; - event.start = caretOffset; - event.end = getWordNext(caretOffset, SWT.MOVEMENT_WORD); - sendKeyEvent(event); - } -} -/** - * Deletes the previous word. - */ -void doDeleteWordPrevious() { - if (selection.x != selection.y) { - // if a selection exists, treat as if - // only the backspace key was pressed - doBackspace(); - } else { - Event event = new Event(); - event.text = ""; - event.start = getWordPrevious(caretOffset, SWT.MOVEMENT_WORD); - event.end = caretOffset; - sendKeyEvent(event); - } -} -/** - * Moves the caret one line down and to the same character offset relative - * to the beginning of the line. Move the caret to the end of the new line - * if the new line is shorter than the character offset. - */ -void doLineDown(boolean select) { - int caretLine = getCaretLine(); - int lineCount = content.getLineCount(); - int y = 0; - boolean lastLine = false; - if (wordWrap) { - int lineOffset = content.getOffsetAtLine(caretLine); - int offsetInLine = caretOffset - lineOffset; - TextLayout layout = renderer.getTextLayout(caretLine); - int lineIndex = getVisualLineIndex(layout, offsetInLine); - int layoutLineCount = layout.getLineCount(); - if (lineIndex == layoutLineCount - 1) { - lastLine = caretLine == lineCount - 1; - caretLine++; - } else { - y = layout.getLineBounds(lineIndex + 1).y; - } - renderer.disposeTextLayout(layout); - } else { - lastLine = caretLine == lineCount - 1; - caretLine++; - } - if (lastLine) { - if (select) { - setCaretOffset(content.getCharCount(), SWT.DEFAULT); - } - } else { - int[] alignment = new int[1]; - int offset = getOffsetAtPoint(columnX, y, caretLine, alignment); - setCaretOffset(offset, alignment[0]); - } - int oldColumnX = columnX; - int oldHScrollOffset = horizontalScrollOffset; - if (select) { - setMouseWordSelectionAnchor(); - // select first and then scroll to reduce flash when key - // repeat scrolls lots of lines - doSelection(ST.COLUMN_NEXT); - } - showCaret(); - int hScrollChange = oldHScrollOffset - horizontalScrollOffset; - columnX = oldColumnX + hScrollChange; -} -/** - * Moves the caret to the end of the line. - */ -void doLineEnd() { - int caretLine = getCaretLine(); - int lineOffset = content.getOffsetAtLine(caretLine); - int lineEndOffset; - if (wordWrap) { - TextLayout layout = renderer.getTextLayout(caretLine); - int offsetInLine = caretOffset - lineOffset; - int lineIndex = getVisualLineIndex(layout, offsetInLine); - int[] offsets = layout.getLineOffsets(); - lineEndOffset = lineOffset + offsets[lineIndex + 1]; - renderer.disposeTextLayout(layout); - } else { - int lineLength = content.getLine(caretLine).length(); - lineEndOffset = lineOffset + lineLength; - } - if (caretOffset < lineEndOffset) { - setCaretOffset(lineEndOffset, PREVIOUS_OFFSET_TRAILING); - showCaret(); - } -} -/** - * Moves the caret to the beginning of the line. - */ -void doLineStart() { - int caretLine = getCaretLine(); - int lineOffset = content.getOffsetAtLine(caretLine); - if (wordWrap) { - TextLayout layout = renderer.getTextLayout(caretLine); - int offsetInLine = caretOffset - lineOffset; - int lineIndex = getVisualLineIndex(layout, offsetInLine); - int[] offsets = layout.getLineOffsets(); - lineOffset += offsets[lineIndex]; - renderer.disposeTextLayout(layout); - } - if (caretOffset > lineOffset) { - setCaretOffset(lineOffset, OFFSET_LEADING); - showCaret(); - } -} -/** - * Moves the caret one line up and to the same character offset relative - * to the beginning of the line. Move the caret to the end of the new line - * if the new line is shorter than the character offset. - */ -void doLineUp(boolean select) { - int caretLine = getCaretLine(), y = 0; - boolean firstLine = false; - if (wordWrap) { - int lineOffset = content.getOffsetAtLine(caretLine); - int offsetInLine = caretOffset - lineOffset; - TextLayout layout = renderer.getTextLayout(caretLine); - int lineIndex = getVisualLineIndex(layout, offsetInLine); - if (lineIndex == 0) { - firstLine = caretLine == 0; - if (!firstLine) { - caretLine--; - y = renderer.getLineHeight(caretLine) - 1; - } - } else { - y = layout.getLineBounds(lineIndex - 1).y; - } - renderer.disposeTextLayout(layout); - } else { - firstLine = caretLine == 0; - caretLine--; - } - if (firstLine) { - if (select) { - setCaretOffset(0, SWT.DEFAULT); - } - } else { - int[] alignment = new int[1]; - int offset = getOffsetAtPoint(columnX, y, caretLine, alignment); - setCaretOffset(offset, alignment[0]); - } - int oldColumnX = columnX; - int oldHScrollOffset = horizontalScrollOffset; - if (select) setMouseWordSelectionAnchor(); - showCaret(); - if (select) doSelection(ST.COLUMN_PREVIOUS); - int hScrollChange = oldHScrollOffset - horizontalScrollOffset; - columnX = oldColumnX + hScrollChange; -} -void doMouseLinkCursor() { - Display display = getDisplay(); - Point point = display.getCursorLocation(); - point = display.map(null, this, point); - doMouseLinkCursor(point.x, point.y); -} -void doMouseLinkCursor(int x, int y) { - int offset = getOffsetAtPoint(x, y, null, true); - Display display = getDisplay(); - Cursor newCursor = cursor; - if (renderer.hasLink(offset)) { - newCursor = display.getSystemCursor(SWT.CURSOR_HAND); - } else { - if (cursor == null) { - int type = blockSelection ? SWT.CURSOR_CROSS : SWT.CURSOR_IBEAM; - newCursor = display.getSystemCursor(type); - } - } - if (newCursor != getCursor()) super.setCursor(newCursor); -} -/** - * Moves the caret to the specified location. - * - * @param x x location of the new caret position - * @param y y location of the new caret position - * @param select the location change is a selection operation. - * include the line delimiter in the selection - */ -void doMouseLocationChange(int x, int y, boolean select) { - int line = getLineIndex(y); - - updateCaretDirection = true; - - if (blockSelection) { - x = Math.max(leftMargin, Math.min(x, clientAreaWidth - rightMargin)); - y = Math.max(topMargin, Math.min(y, clientAreaHeight - bottomMargin)); - if (doubleClickEnabled && clickCount > 1) { - boolean wordSelect = (clickCount & 1) == 0; - if (wordSelect) { - Point left = getPointAtOffset(doubleClickSelection.x); - int[] trailing = new int[1]; - int offset = getOffsetAtPoint(x, y, trailing, true); - if (offset != -1) { - if (x > left.x) { - offset = getWordNext(offset + trailing[0], SWT.MOVEMENT_WORD_END); - setBlockSelectionOffset(doubleClickSelection.x, offset, true); - } else { - offset = getWordPrevious(offset + trailing[0], SWT.MOVEMENT_WORD_START); - setBlockSelectionOffset(doubleClickSelection.y, offset, true); - } - } else { - if (x > left.x) { - setBlockSelectionLocation(left.x, left.y, x, y, true); - } else { - Point right = getPointAtOffset(doubleClickSelection.y); - setBlockSelectionLocation(right.x, right.y, x, y, true); - } - } - } else { - setBlockSelectionLocation(blockXLocation, y, true); - } - return; - } else { - if (select) { - if (blockXLocation == -1) { - setBlockSelectionOffset(caretOffset, false); - } - } else { - clearBlockSelection(true, false); - } - int[] trailing = new int[1]; - int offset = getOffsetAtPoint(x, y, trailing, true); - if (offset != -1) { - if (select) { - setBlockSelectionOffset(offset + trailing[0], true); - return; - } - } else { - if (isFixedLineHeight() && renderer.fixedPitch) { - int avg = renderer.averageCharWidth; - x = ((x + avg / 2 - leftMargin + horizontalScrollOffset) / avg * avg) + leftMargin - horizontalScrollOffset; - } - setBlockSelectionLocation(x, y, true); - return; - } - } - } - - // allow caret to be placed below first line only if receiver is - // not in single line mode. fixes 4820. - if (line < 0 || (isSingleLine() && line > 0)) { - return; - } - int[] alignment = new int[1]; - int newCaretOffset = getOffsetAtPoint(x, y, alignment); - int newCaretAlignemnt = alignment[0]; - - if (doubleClickEnabled && clickCount > 1) { - newCaretOffset = doMouseWordSelect(x, newCaretOffset, line); - } - - int newCaretLine = content.getLineAtOffset(newCaretOffset); - - // Is the mouse within the left client area border or on - // a different line? If not the autoscroll selection - // could be incorrectly reset. Fixes 1GKM3XS - boolean vchange = 0 <= y && y < clientAreaHeight || newCaretLine == 0 || newCaretLine == content.getLineCount() - 1; - boolean hchange = 0 <= x && x < clientAreaWidth || wordWrap || newCaretLine != content.getLineAtOffset(caretOffset); - if (vchange && hchange && (newCaretOffset != caretOffset || newCaretAlignemnt != caretAlignment)) { - setCaretOffset(newCaretOffset, newCaretAlignemnt); - if (select) doMouseSelection(); - showCaret(); - } - if (!select) { - setCaretOffset(newCaretOffset, newCaretAlignemnt); - clearSelection(true); - } -} -/** - * Updates the selection based on the caret position - */ -void doMouseSelection() { - if (caretOffset <= selection.x || - (caretOffset > selection.x && - caretOffset < selection.y && selectionAnchor == selection.x)) { - doSelection(ST.COLUMN_PREVIOUS); - } else { - doSelection(ST.COLUMN_NEXT); - } -} -/** - * Returns the offset of the word at the specified offset. - * If the current selection extends from high index to low index - * (i.e., right to left, or caret is at left border of selection on - * non-bidi platforms) the start offset of the word preceding the - * selection is returned. If the current selection extends from - * low index to high index the end offset of the word following - * the selection is returned. - * - * @param x mouse x location - * @param newCaretOffset caret offset of the mouse cursor location - * @param line line index of the mouse cursor location - */ -int doMouseWordSelect(int x, int newCaretOffset, int line) { - // flip selection anchor based on word selection direction from - // base double click. Always do this here (and don't rely on doAutoScroll) - // because auto scroll only does not cover all possible mouse selections - // (e.g., mouse x < 0 && mouse y > caret line y) - if (newCaretOffset < selectionAnchor && selectionAnchor == selection.x) { - selectionAnchor = doubleClickSelection.y; - } else if (newCaretOffset > selectionAnchor && selectionAnchor == selection.y) { - selectionAnchor = doubleClickSelection.x; - } - if (0 <= x && x < clientAreaWidth) { - boolean wordSelect = (clickCount & 1) == 0; - if (caretOffset == selection.x) { - if (wordSelect) { - newCaretOffset = getWordPrevious(newCaretOffset, SWT.MOVEMENT_WORD_START); - } else { - newCaretOffset = content.getOffsetAtLine(line); - } - } else { - if (wordSelect) { - newCaretOffset = getWordNext(newCaretOffset, SWT.MOVEMENT_WORD_END); - } else { - int lineEnd = content.getCharCount(); - if (line + 1 < content.getLineCount()) { - lineEnd = content.getOffsetAtLine(line + 1); - } - newCaretOffset = lineEnd; - } - } - } - return newCaretOffset; -} -/** - * Scrolls one page down so that the last line (truncated or whole) - * of the current page becomes the fully visible top line. - *- * The caret is scrolled the same number of lines so that its location - * relative to the top line remains the same. The exception is the end - * of the text where a full page scroll is not possible. In this case - * the caret is moved after the last character. - *
- * - * @param select whether or not to select the page - */ -void doPageDown(boolean select, int height) { - if (isSingleLine()) return; - int oldColumnX = columnX; - int oldHScrollOffset = horizontalScrollOffset; - if (isFixedLineHeight()) { - int lineCount = content.getLineCount(); - int caretLine = getCaretLine(); - if (caretLine < lineCount - 1) { - int lineHeight = renderer.getLineHeight(); - int lines = (height == -1 ? clientAreaHeight : height) / lineHeight; - int scrollLines = Math.min(lineCount - caretLine - 1, lines); - // ensure that scrollLines never gets negative and at least one - // line is scrolled. fixes bug 5602. - scrollLines = Math.max(1, scrollLines); - int[] alignment = new int[1]; - int offset = getOffsetAtPoint(columnX, getLinePixel(caretLine + scrollLines), alignment); - setCaretOffset(offset, alignment[0]); - if (select) { - doSelection(ST.COLUMN_NEXT); - } - // scroll one page down or to the bottom - int verticalMaximum = lineCount * getVerticalIncrement(); - int pageSize = clientAreaHeight; - int verticalScrollOffset = getVerticalScrollOffset(); - int scrollOffset = verticalScrollOffset + scrollLines * getVerticalIncrement(); - if (scrollOffset + pageSize > verticalMaximum) { - scrollOffset = verticalMaximum - pageSize; - } - if (scrollOffset > verticalScrollOffset) { - scrollVertical(scrollOffset - verticalScrollOffset, true); - } - } - } else { - int lineCount = content.getLineCount(); - int caretLine = getCaretLine(); - int lineIndex, lineHeight; - if (height == -1) { - lineIndex = getPartialBottomIndex(); - int topY = getLinePixel(lineIndex); - lineHeight = renderer.getLineHeight(lineIndex); - height = topY; - if (topY + lineHeight <= clientAreaHeight) { - height += lineHeight; - } else { - if (wordWrap) { - TextLayout layout = renderer.getTextLayout(lineIndex); - int y = clientAreaHeight - topY; - for (int i = 0; i < layout.getLineCount(); i++) { - Rectangle bounds = layout.getLineBounds(i); - if (bounds.contains(bounds.x, y)) { - height += bounds.y; - break; - } - } - renderer.disposeTextLayout(layout); - } - } - } else { - lineIndex = getLineIndex(height); - int topLineY = getLinePixel(lineIndex); - if (wordWrap) { - TextLayout layout = renderer.getTextLayout(lineIndex); - int y = height - topLineY; - for (int i = 0; i < layout.getLineCount(); i++) { - Rectangle bounds = layout.getLineBounds(i); - if (bounds.contains(bounds.x, y)) { - height = topLineY + bounds.y + bounds.height; - break; - } - } - renderer.disposeTextLayout(layout); - } else { - height = topLineY + renderer.getLineHeight(lineIndex); - } - } - int caretHeight = height; - if (wordWrap) { - TextLayout layout = renderer.getTextLayout(caretLine); - int offsetInLine = caretOffset - content.getOffsetAtLine(caretLine); - lineIndex = getVisualLineIndex(layout, offsetInLine); - caretHeight += layout.getLineBounds(lineIndex).y; - renderer.disposeTextLayout(layout); - } - lineIndex = caretLine; - lineHeight = renderer.getLineHeight(lineIndex); - while (caretHeight - lineHeight >= 0 && lineIndex < lineCount - 1) { - caretHeight -= lineHeight; - lineHeight = renderer.getLineHeight(++lineIndex); - } - int[] alignment = new int[1]; - int offset = getOffsetAtPoint(columnX, caretHeight, lineIndex, alignment); - setCaretOffset(offset, alignment[0]); - if (select) doSelection(ST.COLUMN_NEXT); - height = getAvailableHeightBellow(height); - scrollVertical(height, true); - if (height == 0) setCaretLocation(); - } - showCaret(); - int hScrollChange = oldHScrollOffset - horizontalScrollOffset; - columnX = oldColumnX + hScrollChange; -} -/** - * Moves the cursor to the end of the last fully visible line. - */ -void doPageEnd() { - // go to end of line if in single line mode. fixes 5673 - if (isSingleLine()) { - doLineEnd(); - } else { - int bottomOffset; - if (wordWrap) { - int lineIndex = getPartialBottomIndex(); - TextLayout layout = renderer.getTextLayout(lineIndex); - int y = (clientAreaHeight - bottomMargin) - getLinePixel(lineIndex); - int index = layout.getLineCount() - 1; - while (index >= 0) { - Rectangle bounds = layout.getLineBounds(index); - if (y >= bounds.y + bounds.height) break; - index--; - } - if (index == -1 && lineIndex > 0) { - bottomOffset = content.getOffsetAtLine(lineIndex - 1) + content.getLine(lineIndex - 1).length(); - } else { - bottomOffset = content.getOffsetAtLine(lineIndex) + Math.max(0, layout.getLineOffsets()[index + 1] - 1); - } - renderer.disposeTextLayout(layout); - } else { - int lineIndex = getBottomIndex(); - bottomOffset = content.getOffsetAtLine(lineIndex) + content.getLine(lineIndex).length(); - } - if (caretOffset < bottomOffset) { - setCaretOffset(bottomOffset, OFFSET_LEADING); - showCaret(); - } - } -} -/** - * Moves the cursor to the beginning of the first fully visible line. - */ -void doPageStart() { - int topOffset; - if (wordWrap) { - int y, lineIndex; - if (topIndexY > 0) { - lineIndex = topIndex - 1; - y = renderer.getLineHeight(lineIndex) - topIndexY; - } else { - lineIndex = topIndex; - y = -topIndexY; - } - TextLayout layout = renderer.getTextLayout(lineIndex); - int index = 0; - int lineCount = layout.getLineCount(); - while (index < lineCount) { - Rectangle bounds = layout.getLineBounds(index); - if (y <= bounds.y) break; - index++; - } - if (index == lineCount) { - topOffset = content.getOffsetAtLine(lineIndex + 1); - } else { - topOffset = content.getOffsetAtLine(lineIndex) + layout.getLineOffsets()[index]; - } - renderer.disposeTextLayout(layout); - } else { - topOffset = content.getOffsetAtLine(topIndex); - } - if (caretOffset > topOffset) { - setCaretOffset(topOffset, OFFSET_LEADING); - showCaret(); - } -} -/** - * Scrolls one page up so that the first line (truncated or whole) - * of the current page becomes the fully visible last line. - * The caret is scrolled the same number of lines so that its location - * relative to the top line remains the same. The exception is the beginning - * of the text where a full page scroll is not possible. In this case the - * caret is moved in front of the first character. - */ -void doPageUp(boolean select, int height) { - if (isSingleLine()) return; - int oldHScrollOffset = horizontalScrollOffset; - int oldColumnX = columnX; - if (isFixedLineHeight()) { - int caretLine = getCaretLine(); - if (caretLine > 0) { - int lineHeight = renderer.getLineHeight(); - int lines = (height == -1 ? clientAreaHeight : height) / lineHeight; - int scrollLines = Math.max(1, Math.min(caretLine, lines)); - caretLine -= scrollLines; - int[] alignment = new int[1]; - int offset = getOffsetAtPoint(columnX, getLinePixel(caretLine), alignment); - setCaretOffset(offset, alignment[0]); - if (select) { - doSelection(ST.COLUMN_PREVIOUS); - } - int verticalScrollOffset = getVerticalScrollOffset(); - int scrollOffset = Math.max(0, verticalScrollOffset - scrollLines * getVerticalIncrement()); - if (scrollOffset < verticalScrollOffset) { - scrollVertical(scrollOffset - verticalScrollOffset, true); - } - } - } else { - int caretLine = getCaretLine(); - int lineHeight, lineIndex; - if (height == -1) { - if (topIndexY == 0) { - height = clientAreaHeight; - } else { - int y; - if (topIndex > 0) { - lineIndex = topIndex - 1; - lineHeight = renderer.getLineHeight(lineIndex); - height = clientAreaHeight - topIndexY; - y = lineHeight - topIndexY; - } else { - lineIndex = topIndex; - lineHeight = renderer.getLineHeight(lineIndex); - height = clientAreaHeight - (lineHeight + topIndexY); - y = -topIndexY; - } - if (wordWrap) { - TextLayout layout = renderer.getTextLayout(lineIndex); - for (int i = 0; i < layout.getLineCount(); i++) { - Rectangle bounds = layout.getLineBounds(i); - if (bounds.contains(bounds.x, y)) { - height += lineHeight - (bounds.y + bounds.height); - break; - } - } - renderer.disposeTextLayout(layout); - } - } - } else { - lineIndex = getLineIndex(clientAreaHeight - height); - int topLineY = getLinePixel(lineIndex); - if (wordWrap) { - TextLayout layout = renderer.getTextLayout(lineIndex); - int y = topLineY; - for (int i = 0; i < layout.getLineCount(); i++) { - Rectangle bounds = layout.getLineBounds(i); - if (bounds.contains(bounds.x, y)) { - height = clientAreaHeight - (topLineY + bounds.y); - break; - } - } - renderer.disposeTextLayout(layout); - } else { - height = clientAreaHeight - topLineY; - } - } - int caretHeight = height; - if (wordWrap) { - TextLayout layout = renderer.getTextLayout(caretLine); - int offsetInLine = caretOffset - content.getOffsetAtLine(caretLine); - lineIndex = getVisualLineIndex(layout, offsetInLine); - caretHeight += layout.getBounds().height - layout.getLineBounds(lineIndex).y; - renderer.disposeTextLayout(layout); - } - lineIndex = caretLine; - lineHeight = renderer.getLineHeight(lineIndex); - while (caretHeight - lineHeight >= 0 && lineIndex > 0) { - caretHeight -= lineHeight; - lineHeight = renderer.getLineHeight(--lineIndex); - } - lineHeight = renderer.getLineHeight(lineIndex); - int[] alignment = new int[1]; - int offset = getOffsetAtPoint(columnX, lineHeight - caretHeight, lineIndex, alignment); - setCaretOffset(offset, alignment[0]); - if (select) doSelection(ST.COLUMN_PREVIOUS); - height = getAvailableHeightAbove(height); - scrollVertical(-height, true); - if (height == 0) setCaretLocation(); - } - showCaret(); - int hScrollChange = oldHScrollOffset - horizontalScrollOffset; - columnX = oldColumnX + hScrollChange; -} -/** - * Updates the selection to extend to the current caret position. - */ -void doSelection(int direction) { - int redrawStart = -1; - int redrawEnd = -1; - if (selectionAnchor == -1) { - selectionAnchor = selection.x; - } - if (direction == ST.COLUMN_PREVIOUS) { - if (caretOffset < selection.x) { - // grow selection - redrawEnd = selection.x; - redrawStart = selection.x = caretOffset; - // check if selection has reversed direction - if (selection.y != selectionAnchor) { - redrawEnd = selection.y; - selection.y = selectionAnchor; - } - // test whether selection actually changed. Fixes 1G71EO1 - } else if (selectionAnchor == selection.x && caretOffset < selection.y) { - // caret moved towards selection anchor (left side of selection). - // shrink selection - redrawEnd = selection.y; - redrawStart = selection.y = caretOffset; - } - } else { - if (caretOffset > selection.y) { - // grow selection - redrawStart = selection.y; - redrawEnd = selection.y = caretOffset; - // check if selection has reversed direction - if (selection.x != selectionAnchor) { - redrawStart = selection.x; - selection.x = selectionAnchor; - } - // test whether selection actually changed. Fixes 1G71EO1 - } else if (selectionAnchor == selection.y && caretOffset > selection.x) { - // caret moved towards selection anchor (right side of selection). - // shrink selection - redrawStart = selection.x; - redrawEnd = selection.x = caretOffset; - } - } - if (redrawStart != -1 && redrawEnd != -1) { - internalRedrawRange(redrawStart, redrawEnd - redrawStart); - sendSelectionEvent(); - } -} -/** - * Moves the caret to the next character or to the beginning of the - * next line if the cursor is at the end of a line. - */ -void doSelectionCursorNext() { - int caretLine = getCaretLine(); - int lineOffset = content.getOffsetAtLine(caretLine); - int offsetInLine = caretOffset - lineOffset; - int offset, alignment; - if (offsetInLine < content.getLine(caretLine).length()) { - TextLayout layout = renderer.getTextLayout(caretLine); - offsetInLine = layout.getNextOffset(offsetInLine, SWT.MOVEMENT_CLUSTER); - int lineStart = layout.getLineOffsets()[layout.getLineIndex(offsetInLine)]; - renderer.disposeTextLayout(layout); - offset = offsetInLine + lineOffset; - alignment = offsetInLine == lineStart ? OFFSET_LEADING : PREVIOUS_OFFSET_TRAILING; - setCaretOffset(offset, alignment); - showCaret(); - } else if (caretLine < content.getLineCount() - 1 && !isSingleLine()) { - caretLine++; - offset = content.getOffsetAtLine(caretLine); - alignment = PREVIOUS_OFFSET_TRAILING; - setCaretOffset(offset, alignment); - showCaret(); - } -} -/** - * Moves the caret to the previous character or to the end of the previous - * line if the cursor is at the beginning of a line. - */ -void doSelectionCursorPrevious() { - int caretLine = getCaretLine(); - int lineOffset = content.getOffsetAtLine(caretLine); - int offsetInLine = caretOffset - lineOffset; - if (offsetInLine > 0) { - int offset = getClusterPrevious(caretOffset, caretLine); - setCaretOffset(offset, OFFSET_LEADING); - showCaret(); - } else if (caretLine > 0) { - caretLine--; - lineOffset = content.getOffsetAtLine(caretLine); - int offset = lineOffset + content.getLine(caretLine).length(); - setCaretOffset(offset, OFFSET_LEADING); - showCaret(); - } -} -/** - * Moves the caret one line down and to the same character offset relative - * to the beginning of the line. Moves the caret to the end of the new line - * if the new line is shorter than the character offset. - * Moves the caret to the end of the text if the caret already is on the - * last line. - * Adjusts the selection according to the caret change. This can either add - * to or subtract from the old selection, depending on the previous selection - * direction. - */ -void doSelectionLineDown() { - int oldColumnX = columnX = getPointAtOffset(caretOffset).x; - doLineDown(true); - columnX = oldColumnX; -} -/** - * Moves the caret one line up and to the same character offset relative - * to the beginning of the line. Moves the caret to the end of the new line - * if the new line is shorter than the character offset. - * Moves the caret to the beginning of the document if it is already on the - * first line. - * Adjusts the selection according to the caret change. This can either add - * to or subtract from the old selection, depending on the previous selection - * direction. - */ -void doSelectionLineUp() { - int oldColumnX = columnX = getPointAtOffset(caretOffset).x; - doLineUp(true); - columnX = oldColumnX; -} -/** - * Scrolls one page down so that the last line (truncated or whole) - * of the current page becomes the fully visible top line. - *- * The caret is scrolled the same number of lines so that its location - * relative to the top line remains the same. The exception is the end - * of the text where a full page scroll is not possible. In this case - * the caret is moved after the last character. - *
- * Adjusts the selection according to the caret change. This can either add - * to or subtract from the old selection, depending on the previous selection - * direction. - * - */ -void doSelectionPageDown(int pixels) { - int oldColumnX = columnX = getPointAtOffset(caretOffset).x; - doPageDown(true, pixels); - columnX = oldColumnX; -} -/** - * Scrolls one page up so that the first line (truncated or whole) - * of the current page becomes the fully visible last line. - *- * The caret is scrolled the same number of lines so that its location - * relative to the top line remains the same. The exception is the beginning - * of the text where a full page scroll is not possible. In this case the - * caret is moved in front of the first character. - *
- * Adjusts the selection according to the caret change. This can either add - * to or subtract from the old selection, depending on the previous selection - * direction. - *
- */ -void doSelectionPageUp(int pixels) { - int oldColumnX = columnX = getPointAtOffset(caretOffset).x; - doPageUp(true, pixels); - columnX = oldColumnX; -} -/** - * Moves the caret to the end of the next word . - */ -void doSelectionWordNext() { - int offset = getWordNext(caretOffset, SWT.MOVEMENT_WORD); - // don't change caret position if in single line mode and the cursor - // would be on a different line. fixes 5673 - if (!isSingleLine() || - content.getLineAtOffset(caretOffset) == content.getLineAtOffset(offset)) { - // Force symmetrical movement for word next and previous. Fixes 14536 - setCaretOffset(offset, OFFSET_LEADING); - showCaret(); - } -} -/** - * Moves the caret to the start of the previous word. - */ -void doSelectionWordPrevious() { - int offset = getWordPrevious(caretOffset, SWT.MOVEMENT_WORD); - setCaretOffset(offset, OFFSET_LEADING); - showCaret(); -} -/** - * Moves the caret one character to the left. Do not go to the previous line. - * When in a bidi locale and at a R2L character the caret is moved to the - * beginning of the R2L segment (visually right) and then one character to the - * left (visually left because it's now in a L2R segment). - */ -void doVisualPrevious() { - int offset = getClusterPrevious(caretOffset, getCaretLine()); - setCaretOffset(offset, SWT.DEFAULT); - showCaret(); -} -/** - * Moves the caret one character to the right. Do not go to the next line. - * When in a bidi locale and at a R2L character the caret is moved to the - * end of the R2L segment (visually left) and then one character to the - * right (visually right because it's now in a L2R segment). - */ -void doVisualNext() { - int offset = getClusterNext(caretOffset, getCaretLine()); - setCaretOffset(offset, SWT.DEFAULT); - showCaret(); -} -/** - * Moves the caret to the end of the next word. - * If a selection exists, move the caret to the end of the selection - * and remove the selection. - */ -void doWordNext() { - if (selection.y - selection.x > 0) { - setCaretOffset(selection.y, SWT.DEFAULT); - showCaret(); - } else { - doSelectionWordNext(); - } -} -/** - * Moves the caret to the start of the previous word. - * If a selection exists, move the caret to the start of the selection - * and remove the selection. - */ -void doWordPrevious() { - if (selection.y - selection.x > 0) { - setCaretOffset(selection.x, SWT.DEFAULT); - showCaret(); - } else { - doSelectionWordPrevious(); - } -} -/** - * Ends the autoscroll process. - */ -void endAutoScroll() { - autoScrollDirection = SWT.NULL; -} -public Color getBackground() { - checkWidget(); - if (background == null) { - return getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND); - } - return background; -} -/** - * Returns the baseline, in pixels. - * - * Note: this API should not be used if a StyleRange attribute causes lines to - * have different heights (i.e. different fonts, rise, etc). - * - * @return baseline the baseline - * @exception SWTException- * - * @param lineIndex index of the line to return. - * @return the line text without delimiters - * - * @exception SWTException
- * Note: this API should not be used if a StyleRange attribute causes lines to - * have different heights (i.e. different fonts, rise, etc). - *
- * - * @return line height in pixel. - * @exception SWTException- * If there is a LineStyleListener but it does not set any styles, - * the StyledTextEvent.styles field will be initialized to an empty - * array. - *
- * - * @param lineOffset offset of the line start relative to the start of - * the content. - * @param line line to get line styles for - * @return line style data for the given line. Styles may start before - * line start and end after line end - */ -StyledTextEvent getLineStyleData(int lineOffset, String line) { - return sendLineEvent(LineGetStyle, lineOffset, line); -} -/** - * Returns the top pixel, relative to the client area, of a given line. - * Clamps out of ranges index. - * - * @param lineIndex the line index, the max value is lineCount. If - * lineIndex == lineCount it returns the bottom pixel of the last line. - * It means this function can be used to retrieve the bottom pixel of any line. - * - * @return the top pixel of a given line index - * - * @since 3.2 - */ -public int getLinePixel(int lineIndex) { - checkWidget(); - int lineCount = content.getLineCount(); - lineIndex = Math.max(0, Math.min(lineCount, lineIndex)); - if (isFixedLineHeight()) { - int lineHeight = renderer.getLineHeight(); - return lineIndex * lineHeight - getVerticalScrollOffset() + topMargin; - } - if (lineIndex == topIndex) return topIndexY + topMargin; - int height = topIndexY; - if (lineIndex > topIndex) { - for (int i = topIndex; i < lineIndex; i++) { - height += renderer.getLineHeight(i); - } - } else { - for (int i = topIndex - 1; i >= lineIndex; i--) { - height -= renderer.getLineHeight(i); - } - } - return height + topMargin; -} -/** - * Returns the line index for a y, relative to the client area. - * The line index returned is always in the range 0..lineCount - 1. - * - * @param y the y-coordinate pixel - * - * @return the line index for a given y-coordinate pixel - * - * @since 3.2 - */ -public int getLineIndex(int y) { - checkWidget(); - y -= topMargin; - if (isFixedLineHeight()) { - int lineHeight = renderer.getLineHeight(); - int lineIndex = (y + getVerticalScrollOffset()) / lineHeight; - int lineCount = content.getLineCount(); - lineIndex = Math.max(0, Math.min(lineCount - 1, lineIndex)); - return lineIndex; - } - if (y == topIndexY) return topIndex; - int line = topIndex; - if (y < topIndexY) { - while (y < topIndexY && line > 0) { - y += renderer.getLineHeight(--line); - } - } else { - int lineCount = content.getLineCount(); - int lineHeight = renderer.getLineHeight(line); - while (y - lineHeight >= topIndexY && line < lineCount - 1) { - y -= lineHeight; - lineHeight = renderer.getLineHeight(++line); - } - } - return line; -} -/** - * Returns the left margin. - * - * @return the left margin. - * @exception SWTException- * The return value reflects the character offset that the caret will - * be placed at if a mouse click occurred at the specified location. - * If the x coordinate of the location is beyond the center of a character - * the returned offset will be behind the character. - *
- * - * @param point the origin of character bounding box relative to - * the origin of the widget client area. - * @return offset of the character at the given location relative - * to the first character in the document. - * @exception SWTException
- * The ranges array contains start and length pairs. Each pair refers to
- * the corresponding style in the styles array. For example, the pair
- * that starts at ranges[n] with length ranges[n+1] uses the style
- * at styles[n/2] returned by getStyleRanges(int, int, boolean)
.
- *
- * The ranges array contains start and length pairs. Each pair refers to
- * the corresponding style in the styles array. For example, the pair
- * that starts at ranges[n] with length ranges[n+1] uses the style
- * at styles[n/2] returned by getStyleRanges(int, int, boolean)
.
- *
- * Text selections are specified in terms of caret positions. In a text - * widget that contains N characters, there are N+1 caret positions, - * ranging from 0..N - *
- * - * @return start and end of the selection, x is the offset of the first - * selected character, y is the offset after the last selected character. - * The selection values returned are visual (i.e., x will always always be - * <= y). To determine if a selection is right-to-left (RtoL) vs. left-to-right - * (LtoR), compare the caretOffset to the start and end of the selection - * (e.g., caretOffset == start of selection implies that the selection is RtoL). - * @see #getSelectionRange - * @exception SWTException- * The ranges array contains start and length pairs. When the receiver is not - * in block selection mode the return arrays contains the start and length of - * the regular selection. - * - * @return the ranges array - * - * @exception SWTException
- * Returns null if a LineStyleListener has been set or if a style is not set - * for the offset. - * Should not be called if a LineStyleListener has been set since the - * listener maintains the styles. - *
- * - * @param offset the offset to return the style for. - * 0 <= offset < getCharCount() must be true. - * @return a StyleRange with start == offset and length == 1, indicating - * the style at the given offset. null if a LineStyleListener has been set - * or if a style is not set for the given offset. - * @exception SWTException- * Returns an empty array if a LineStyleListener has been set. - * Should not be called if a LineStyleListener has been set since the - * listener maintains the styles. - *
- * Note: Because a StyleRange includes the start and length, the - * same instance cannot occur multiple times in the array of styles. - * If the same style attributes, such as font and color, occur in - * multiple StyleRanges,getStyleRanges(boolean)
- * can be used to get the styles without the ranges.
- *
- *
- * @return the styles or an empty array if a LineStyleListener has been set.
- *
- * @exception SWTException - * Returns an empty array if a LineStyleListener has been set. - * Should not be called if a LineStyleListener has been set since the - * listener maintains the styles. - *
- * Note: When includeRanges
is true, the start and length
- * fields of each StyleRange will be valid, however the StyleRange
- * objects may need to be cloned. When includeRanges
is
- * false, getRanges(int, int)
can be used to get the
- * associated ranges.
- *
- * Returns an empty array if a LineStyleListener has been set. - * Should not be called if a LineStyleListener has been set since the - * listener maintains the styles. - *
- * Note: Because the StyleRange includes the start and length, the
- * same instance cannot occur multiple times in the array of styles.
- * If the same style attributes, such as font and color, occur in
- * multiple StyleRanges, getStyleRanges(int, int, boolean)
- * can be used to get the styles without the ranges.
- *
StyleRange
will have a starting offset >= start
- * and the last returned StyleRange
will have an ending
- * offset <= start + length - 1
- *
- * @exception SWTException - * Returns an empty array if a LineStyleListener has been set. - * Should not be called if a LineStyleListener has been set since the - * listener maintains the styles. - *
- * Note: When includeRanges
is true, the start and length
- * fields of each StyleRange will be valid, however the StyleRange
- * objects may need to be cloned. When includeRanges
is
- * false, getRanges(int, int)
can be used to get the
- * associated ranges.
- *
StyleRange
will have a starting offset >= start
- * and the last returned StyleRange
will have an ending
- * offset <= start + length - 1
- *
- * @exception SWTException - * The top index is the index of the fully visible line that is currently - * at the top of the widget or the topmost partially visible line if no line is fully visible. - * The top index changes when the widget is scrolled. Indexing is zero based. - *
- * - * @return the index of the top line - * @exception SWTException- * The top pixel is the pixel position of the line that is - * currently at the top of the widget. The text widget can be scrolled by pixels - * by dragging the scroll thumb so that a partial line may be displayed at the top - * the widget. The top pixel changes when the widget is scrolled. The top pixel - * does not include the widget trimming. - *
- * - * @return pixel position of the top line - * @exception SWTException- * NOTE: Does not return correct values for true italic fonts (vs. slanted fonts). - *
- * - * @return location of the character at the given offset in the line. - */ -Point getPointAtOffset(int offset) { - int lineIndex = content.getLineAtOffset(offset); - String line = content.getLine(lineIndex); - int lineOffset = content.getOffsetAtLine(lineIndex); - int offsetInLine = offset - lineOffset; - int lineLength = line.length(); - if (lineIndex < content.getLineCount() - 1) { - int endLineOffset = content.getOffsetAtLine(lineIndex + 1) - 1; - if (lineLength < offsetInLine && offsetInLine <= endLineOffset) { - offsetInLine = lineLength; - } - } - Point point; - TextLayout layout = renderer.getTextLayout(lineIndex); - if (lineLength != 0 && offsetInLine <= lineLength) { - if (offsetInLine == lineLength) { - point = layout.getLocation(offsetInLine - 1, true); - } else { - switch (caretAlignment) { - case OFFSET_LEADING: - point = layout.getLocation(offsetInLine, false); - break; - case PREVIOUS_OFFSET_TRAILING: - default: - if (offsetInLine == 0) { - point = layout.getLocation(offsetInLine, false); - } else { - point = layout.getLocation(offsetInLine - 1, true); - } - break; - } - } - } else { - point = new Point(layout.getIndent(), 0); - } - renderer.disposeTextLayout(layout); - point.x += leftMargin - horizontalScrollOffset; - point.y += getLinePixel(lineIndex); - return point; -} -/** - * Inserts a string. The old selection is replaced with the new text. - * - * @param string the string - * @see #replaceTextRange(int,int,String) - * @exception SWTExceptionDND.CLIPBOARD
- * clipboard or, if there is no selection, inserts the text at the current
- * caret offset. If the widget has the SWT.SINGLE style and the
- * clipboard text contains more than one line, only the first line without
- * line delimiters is inserted in the widget.
- *
- * @exception SWTException - * The runnable may be run in a non-UI thread. - *
- * - * @param printer the printer to print to - * - * @return aRunnable
for printing the receiver's text
- *
- * @exception SWTException - * The runnable may be run in a non-UI thread. - *
- * - * @param printer the printer to print to - * @param options print options to use during printing - * - * @return aRunnable
for printing the receiver's text
- *
- * @exception SWTException
- * Recalculates the content width for all lines in the bounds.
- * When a LineStyleListener
is used a redraw call
- * is the only notification to the widget that styles have changed
- * and that the content width may have changed.
- *
all
flag
- * is true
, any children of the receiver which
- * intersect with the specified area will also paint their
- * intersecting areas. If the all
flag is
- * false
, the children will not be painted.
- *
- * Marks the content width of all lines in the specified rectangle
- * as unknown. Recalculates the content width of all visible lines.
- * When a LineStyleListener
is used a redraw call
- * is the only notification to the widget that styles have changed
- * and that the content width may have changed.
- *
true
if children should redraw, and false
otherwise
- *
- * @exception SWTException
- * Note: Because a StyleRange includes the start and length, the
- * same instance cannot occur multiple times in the array of styles.
- * If the same style attributes, such as font and color, occur in
- * multiple StyleRanges, setStyleRanges(int, int, int[], StyleRange[])
- * can be used to share styles and reduce memory usage.
- *
- * Should not be called if a LineStyleListener has been set since the - * listener maintains the styles. - *
- * - * @param start offset of first character where styles will be deleted - * @param length length of the range to delete styles in - * @param ranges StyleRange objects containing the new style information. - * The ranges should not overlap and should be within the specified start - * and length. The style rendering is undefined if the ranges do overlap - * or are ill-defined. Must not be null. - * @exception SWTException- * NOTE: During the replace operation the current selection is - * changed as follows: - *
- * The specified line may be a visual (wrapped) line if in word - * wrap mode. The returned object will always be for a logical - * (unwrapped) line. - *
- * - * @param lineOffset offset of the line. This may be the offset of - * a visual line if the widget is in word wrap mode. - * @param line line text. This may be the text of a visual line if - * the widget is in word wrap mode. - * @return StyledTextEvent that can be used to request line data - * for the given line. - */ -StyledTextEvent sendLineEvent(int eventType, int lineOffset, String line) { - StyledTextEvent event = null; - if (isListening(eventType)) { - event = new StyledTextEvent(content); - event.detail = lineOffset; - event.text = line; - event.alignment = alignment; - event.indent = indent; - event.justify = justify; - notifyListeners(eventType, event); - } - return event; -} -/** - * Sends the specified selection event. - */ -void sendSelectionEvent() { - getAccessible().textSelectionChanged(); - Event event = new Event(); - event.x = selection.x; - event.y = selection.y; - notifyListeners(SWT.Selection, event); -} -int sendTextEvent(int left, int right, int lineIndex, String text, boolean fillWithSpaces) { - int lineWidth = 0, start, end; - StringBuffer buffer = new StringBuffer(); - if (lineIndex < content.getLineCount()) { - int[] trailing = new int[1]; - start = getOffsetAtPoint(left, getLinePixel(lineIndex), trailing, true); - if (start == -1) { - int lineOffset = content.getOffsetAtLine(lineIndex); - int lineLegth = content.getLine(lineIndex).length(); - start = end = lineOffset + lineLegth; - if (fillWithSpaces) { - TextLayout layout = renderer.getTextLayout(lineIndex); - lineWidth = layout.getBounds().width; - renderer.disposeTextLayout(layout); - } - } else { - start += trailing[0]; - end = left == right ? start : getOffsetAtPoint(right, 0, lineIndex, null); - fillWithSpaces = false; - } - } else { - start = end = content.getCharCount(); - buffer.append(content.getLineDelimiter()); - } - if (start > end) { - int temp = start; - start = end; - end = temp; - } - if (fillWithSpaces) { - int spacesWidth = left - lineWidth + horizontalScrollOffset - leftMargin; - int spacesCount = spacesWidth / renderer.averageCharWidth; - for (int i = 0; i < spacesCount; i++) { - buffer.append(' '); - } - } - buffer.append(text); - Event event = new Event(); - event.start = start; - event.end = end; - event.text = buffer.toString(); - sendKeyEvent(event); - return event.start + event.text.length(); -} -int sendWordBoundaryEvent(int eventType, int movement, int offset, int newOffset, String lineText, int lineOffset) { - if (isListening(eventType)) { - StyledTextEvent event = new StyledTextEvent(content); - event.detail = lineOffset; - event.text = lineText; - event.count = movement; - event.start = offset; - event.end = newOffset; - notifyListeners(eventType, event); - offset = event.end; - if (offset != newOffset) { - int length = getCharCount(); - if (offset < 0) { - offset = 0; - } else if (offset > length) { - offset = length; - } else { - if (isLineDelimiter(offset)) { - SWT.error(SWT.ERROR_INVALID_ARGUMENT); - } - } - } - return offset; - } - return newOffset; -} -void setAlignment() { - if ((getStyle() & SWT.SINGLE) == 0) return; - int alignment = renderer.getLineAlignment(0, this.alignment); - int newAlignmentMargin = 0; - if (alignment != SWT.LEFT) { - renderer.calculate(0, 1); - int width = renderer.getWidth() - alignmentMargin; - newAlignmentMargin = clientAreaWidth - width; - if (newAlignmentMargin < 0) newAlignmentMargin = 0; - if (alignment == SWT.CENTER) newAlignmentMargin /= 2; - } - if (alignmentMargin != newAlignmentMargin) { - leftMargin -= alignmentMargin; - leftMargin += newAlignmentMargin; - alignmentMargin = newAlignmentMargin; - resetCache(0, 1); - setCaretLocation(); - super.redraw(); - } -} -/** - * Sets the alignment of the widget. The argument should be one ofSWT.LEFT
,
- * SWT.CENTER
or SWT.RIGHT
. The alignment applies for all lines.
- *
- * Note that if SWT.MULTI
is set, then SWT.WRAP
must also be set
- * in order to stabilize the right edge before setting alignment.
- *
- * NOTE: Italic fonts are not supported unless they have no overhang - * and the same baseline as regular fonts. - *
- * - * @param font new font - * @exception SWTException- * NOTE: The horizontal index is reset to 0 when new text is set in the - * widget. - *
- * - * @param offset horizontal scroll offset relative to the start - * of the line, measured in character increments starting at 0, if - * equal to 0 the content is not scrolled, if > 0 = the content is scrolled. - * @exception SWTException- * NOTE: The horizontal pixel offset is reset to 0 when new text - * is set in the widget. - *
- * - * @param pixel horizontal pixel offset relative to the start - * of the line. - * @exception SWTException- * It is the amount of blank space, in pixels, at the beginning of each line. - * When a line wraps in several lines only the first one is indented. - *
- * - * @param indent the new indent - * - * @exception SWTException- * One action can be associated with N keys. However, each key can only - * have one action (key:action is N:1 relation). - *
- * - * @param key a key code defined in SWT.java or a character. - * Optionally ORd with a state mask. Preferred state masks are one or more of - * SWT.MOD1, SWT.MOD2, SWT.MOD3, since these masks account for modifier platform - * differences. However, there may be cases where using the specific state masks - * (i.e., SWT.CTRL, SWT.SHIFT, SWT.ALT, SWT.COMMAND) makes sense. - * @param action one of the predefined actions defined in ST.java. - * Use SWT.NULL to remove a key binding. - * @exception SWTExceptionSWT.LEFT
,
- * SWT.CENTER
or SWT.RIGHT
.
- *
- * Note that if SWT.MULTI
is set, then SWT.WRAP
must also be set
- * in order to stabilize the right edge before setting alignment.
- *
- * All line attributes are maintained relative to the line text, not the - * line index that is specified in this method call. - * During text changes, when entire lines are inserted or removed, the line - * attributes that are associated with the lines after the change - * will "move" with their respective text. An entire line is defined as - * extending from the first character on a line to the last and including the - * line delimiter. - *
- * When two lines are joined by deleting a line delimiter, the top line - * attributes take precedence and the attributes of the bottom line are deleted. - * For all other text changes line attributes will remain unchanged. - * - * @param startLine first line the alignment is applied to, 0 based - * @param lineCount number of lines the alignment applies to. - * @param alignment line alignment - * - * @exception SWTException
- * The background color is drawn for the width of the widget. All - * line background colors are discarded when setText is called. - * The text background color if defined in a StyleRange overlays the - * line background color. - *
- * Should not be called if a LineBackgroundListener has been set since the - * listener maintains the line backgrounds. - *
- * All line attributes are maintained relative to the line text, not the - * line index that is specified in this method call. - * During text changes, when entire lines are inserted or removed, the line - * attributes that are associated with the lines after the change - * will "move" with their respective text. An entire line is defined as - * extending from the first character on a line to the last and including the - * line delimiter. - *
- * When two lines are joined by deleting a line delimiter, the top line - * attributes take precedence and the attributes of the bottom line are deleted. - * For all other text changes line attributes will remain unchanged. - *
- * - * @param startLine first line the color is applied to, 0 based - * @param lineCount number of lines the color applies to. - * @param background line background color - * @exception SWTException- * Should not be called if a LineStyleListener has been set since the listener - * maintains the line attributes. - *
- * All line attributes are maintained relative to the line text, not the - * line index that is specified in this method call. - * During text changes, when entire lines are inserted or removed, the line - * attributes that are associated with the lines after the change - * will "move" with their respective text. An entire line is defined as - * extending from the first character on a line to the last and including the - * line delimiter. - *
- * When two lines are joined by deleting a line delimiter, the top line - * attributes take precedence and the attributes of the bottom line are deleted. - * For all other text changes line attributes will remain unchanged. - *
- * - * @param startLine first line the bullet is applied to, 0 based - * @param lineCount number of lines the bullet applies to. - * @param bullet line bullet - * - * @exception SWTException- * Should not be called if a LineStyleListener has been set since the listener - * maintains the line attributes. - *
- * All line attributes are maintained relative to the line text, not the - * line index that is specified in this method call. - * During text changes, when entire lines are inserted or removed, the line - * attributes that are associated with the lines after the change - * will "move" with their respective text. An entire line is defined as - * extending from the first character on a line to the last and including the - * line delimiter. - *
- * When two lines are joined by deleting a line delimiter, the top line - * attributes take precedence and the attributes of the bottom line are deleted. - * For all other text changes line attributes will remain unchanged. - *
- * - * @param startLine first line the indent is applied to, 0 based - * @param lineCount number of lines the indent applies to. - * @param indent line indent - * - * @exception SWTException- * Should not be called if a LineStyleListener has been set since the listener - * maintains the line attributes. - *
- * All line attributes are maintained relative to the line text, not the - * line index that is specified in this method call. - * During text changes, when entire lines are inserted or removed, the line - * attributes that are associated with the lines after the change - * will "move" with their respective text. An entire line is defined as - * extending from the first character on a line to the last and including the - * line delimiter. - *
- * When two lines are joined by deleting a line delimiter, the top line - * attributes take precedence and the attributes of the bottom line are deleted. - * For all other text changes line attributes will remain unchanged. - *
- * - * @param startLine first line the justify is applied to, 0 based - * @param lineCount number of lines the justify applies to. - * @param justify true if lines should be justified - * - * @exception SWTExceptionSWT.LEFT_TO_RIGHT
or SWT.RIGHT_TO_LEFT
.
- *
- * @param orientation new orientation style
- *
- * @exception SWTException - * Indexing is zero based. Text selections are specified in terms of - * caret positions. In a text widget that contains N characters, there are - * N+1 caret positions, ranging from 0..N - *
- * - * @param point x=selection start offset, y=selection end offset - * The caret will be placed at the selection start when x > y. - * @see #setSelection(int,int) - * @exception SWTException- * Note that this is a HINT. Some platforms do not allow the application - * to change the selection foreground color. - *
- * @param color the new color (or null) - * - * @exception IllegalArgumentException- * Indexing is zero based. Text selections are specified in terms of - * caret positions. In a text widget that contains N characters, there are - * N+1 caret positions, ranging from 0..N - *
- * - * @param start selection start offset. The caret will be placed at the - * selection start when start > end. - * @param end selection end offset - * @see #setSelectionRange(int,int) - * @exception SWTException- * The new selection may not be visible. Call showSelection to scroll - * the selection into view. - *
- * - * @param start offset of the first selected character, start >= 0 must be true. - * @param length number of characters to select, 0 <= start + length - * <= getCharCount() must be true. - * A negative length places the caret at the selection start. - * @param sendEvent a Selection event is sent when set to true and when - * the selection is reset. - */ -void setSelection(int start, int length, boolean sendEvent, boolean doBlock) { - int end = start + length; - if (start > end) { - int temp = end; - end = start; - start = temp; - } - // is the selection range different or is the selection direction - // different? - if (selection.x != start || selection.y != end || - (length > 0 && selectionAnchor != selection.x) || - (length < 0 && selectionAnchor != selection.y)) { - if (blockSelection && doBlock) { - setBlockSelectionOffset(start, end, sendEvent); - } else { - clearSelection(sendEvent); - if (length < 0) { - selectionAnchor = selection.y = end; - selection.x = start; - setCaretOffset(start, PREVIOUS_OFFSET_TRAILING); - } else { - selectionAnchor = selection.x = start; - selection.y = end; - setCaretOffset(end, PREVIOUS_OFFSET_TRAILING); - } - internalRedrawRange(selection.x, selection.y - selection.x); - } - } -} -/** - * Sets the selection. - *- * The new selection may not be visible. Call showSelection to scroll the selection - * into view. A negative length places the caret at the visual start of the selection. - *
- * - * @param start offset of the first selected character - * @param length number of characters to select - * - * @exception SWTException- * The new style overwrites existing styles for the specified range. - * Existing style ranges are adjusted if they partially overlap with - * the new style. To clear an individual style, call setStyleRange - * with a StyleRange that has null attributes. - *
- * Should not be called if a LineStyleListener has been set since the - * listener maintains the styles. - *
- * - * @param range StyleRange object containing the style information. - * Overwrites the old style in the given range. May be null to delete - * all styles. - * @exception SWTExceptionstart
and
- * length
and adds the new styles.
- * - * The ranges array contains start and length pairs. Each pair refers to - * the corresponding style in the styles array. For example, the pair - * that starts at ranges[n] with length ranges[n+1] uses the style - * at styles[n/2]. The range fields within each StyleRange are ignored. - * If ranges or styles is null, the specified range is cleared. - *
- * Note: It is expected that the same instance of a StyleRange will occur - * multiple times within the styles array, reducing memory usage. - *
- * Should not be called if a LineStyleListener has been set since the - * listener maintains the styles. - *
- * - * @param start offset of first character where styles will be deleted - * @param length length of the range to delete styles in - * @param ranges the array of ranges. The ranges must not overlap and must be in order. - * @param styles the array of StyleRanges. The range fields within the StyleRange are unused. - * - * @exception SWTException- * All styles in the widget will be replaced with the given set of ranges and styles. - * The ranges array contains start and length pairs. Each pair refers to - * the corresponding style in the styles array. For example, the pair - * that starts at ranges[n] with length ranges[n+1] uses the style - * at styles[n/2]. The range fields within each StyleRange are ignored. - * If either argument is null, the styles are cleared. - *
- * Note: It is expected that the same instance of a StyleRange will occur - * multiple times within the styles array, reducing memory usage. - *
- * Should not be called if a LineStyleListener has been set since the - * listener maintains the styles. - *
- * - * @param ranges the array of ranges. The ranges must not overlap and must be in order. - * @param styles the array of StyleRanges. The range fields within the StyleRange are unused. - * - * @exception SWTException
- * Note: Because a StyleRange includes the start and length, the
- * same instance cannot occur multiple times in the array of styles.
- * If the same style attributes, such as font and color, occur in
- * multiple StyleRanges, setStyleRanges(int[], StyleRange[])
- * can be used to share styles and reduce memory usage.
- *
- * Should not be called if a LineStyleListener has been set since the - * listener maintains the styles. - *
- * - * @param ranges StyleRange objects containing the style information. - * The ranges should not overlap. The style rendering is undefined if - * the ranges do overlap. Must not be null. The styles need to be in order. - * @exception SWTException- * Note: Only a single line of text should be set when the SWT.SINGLE - * style is used. - *
- * - * @param text new widget content. Replaces existing content. Line styles - * that were set using StyledText API are discarded. The - * current selection is also discarded. - * @exception SWTException- * The text limit specifies the amount of text that - * the user can type into the widget. - *
- * - * @param limit the new text limit. - * @exception SWTException- * The top index is the index of the line that is currently at the top - * of the widget. The top index changes when the widget is scrolled. - * Indexing starts from zero. - * Note: The top index is reset to 0 when new text is set in the widget. - *
- * - * @param topIndex new top index. Must be between 0 and - * getLineCount() - fully visible lines per page. If no lines are fully - * visible the maximum value is getLineCount() - 1. An out of range - * index will be adjusted accordingly. - * @exception SWTException- * The top pixel offset is the vertical pixel offset of the widget. The - * widget is scrolled so that the given pixel position is at the top. - * The top index is adjusted to the corresponding top line. - * Note: The top pixel is reset to 0 when new text is set in the widget. - *
- * - * @param pixel new top pixel offset. Must be between 0 and - * (getLineCount() - visible lines per page) / getLineHeight()). An out - * of range offset will be adjusted accordingly. - * @exception SWTException- * This overrides the creation style bit SWT.WRAP. - *
- * - * @param wrap true=widget wraps lines, false=widget does not wrap lines - * @since 2.0 - */ -public void setWordWrap(boolean wrap) { - checkWidget(); - if ((getStyle() & SWT.SINGLE) != 0) return; - if (wordWrap == wrap) return; - if (wordWrap && blockSelection) setBlockSelection(false); - wordWrap = wrap; - setVariableLineHeight(); - resetCache(0, content.getLineCount()); - horizontalScrollOffset = 0; - ScrollBar horizontalBar = getHorizontalBar(); - if (horizontalBar != null) { - horizontalBar.setVisible(!wordWrap); - } - setScrollBars(true); - setCaretLocation(); - super.redraw(); -} -boolean showLocation(Rectangle rect, boolean scrollPage) { - boolean scrolled = false; - if (rect.y < topMargin) { - scrolled = scrollVertical(rect.y - topMargin, true); - } else if (rect.y + rect.height > clientAreaHeight - bottomMargin) { - if (clientAreaHeight - topMargin - bottomMargin <= 0) { - scrolled = scrollVertical(rect.y - topMargin, true); - } else { - scrolled = scrollVertical(rect.y + rect.height - (clientAreaHeight - bottomMargin), true); - } - } - int width = clientAreaWidth - rightMargin - leftMargin; - if (width > 0) { - int minScroll = scrollPage ? width / 4 : 0; - if (rect.x < leftMargin) { - int scrollWidth = Math.max(leftMargin - rect.x, minScroll); - int maxScroll = horizontalScrollOffset; - scrolled = scrollHorizontal(-Math.min(maxScroll, scrollWidth), true); - } else if (rect.x + rect.width > (clientAreaWidth - rightMargin)) { - int scrollWidth = Math.max(rect.x + rect.width - (clientAreaWidth - rightMargin), minScroll); - int maxScroll = renderer.getWidth() - horizontalScrollOffset - clientAreaWidth; - scrolled = scrollHorizontal(Math.min(maxScroll, scrollWidth), true); - } - } - return scrolled; -} -/** - * Sets the caret location and scrolls the caret offset into view. - */ -void showCaret() { - Rectangle bounds = getBoundsAtOffset(caretOffset); - if (!showLocation(bounds, true)) { - setCaretLocation(); - } -} -/** - * Scrolls the selection into view. - *- * The end of the selection will be scrolled into view. - * Note that if a right-to-left selection exists, the end of the selection is - * the visual beginning of the selection (i.e., where the caret is located). - *
- * - * @exception SWTException- * If the selection intersects with the replaced text, the selection is - * reset and the caret moved to the end of the new text. - * If the selection is behind the replaced text it is moved so that the - * same text remains selected. If the selection is before the replaced text - * it is left unchanged. - *
- * - * @param startOffset offset of the text change - * @param replacedLength length of text being replaced - * @param newLength length of new text - */ -void updateSelection(int startOffset, int replacedLength, int newLength) { - if (selection.y <= startOffset) { - // selection ends before text change - if (wordWrap) setCaretLocation(); - return; - } - if (selection.x < startOffset) { - // clear selection fragment before text change - internalRedrawRange(selection.x, startOffset - selection.x); - } - if (selection.y > startOffset + replacedLength && selection.x < startOffset + replacedLength) { - // clear selection fragment after text change. - // do this only when the selection is actually affected by the - // change. Selection is only affected if it intersects the change (1GDY217). - int netNewLength = newLength - replacedLength; - int redrawStart = startOffset + newLength; - internalRedrawRange(redrawStart, selection.y + netNewLength - redrawStart); - } - if (selection.y > startOffset && selection.x < startOffset + replacedLength) { - // selection intersects replaced text. set caret behind text change - setSelection(startOffset + newLength, 0, true, false); - } else { - // move selection to keep same text selected - setSelection(selection.x + newLength - replacedLength, selection.y - selection.x, true, false); - } - setCaretLocation(); -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextContent.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextContent.java deleted file mode 100755 index 0e6728cf34..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextContent.java +++ /dev/null @@ -1,207 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.custom; - - -/** - * Clients may implement the StyledTextContent interface to provide a - * custom store for the StyledText widget content. The StyledText widget - * interacts with its StyledTextContent in order to access and update - * the text that is being displayed and edited in the widget. - * A custom content implementation can be set in the widget using the - * StyledText.setContent API. - */ -public interface StyledTextContent { - -/** - * Called by StyledText to add itself as an Observer to content changes. - * See TextChangeListener for a description of the listener methods that - * are called when text changes occur. - *- * - * @param listener the listener - * @exception IllegalArgumentException
- * - * @return the number of characters in the content. - */ -public int getCharCount(); - -/** - * Return the line at the given line index without delimiters. - *
- * - * @param lineIndex index of the line to return. Does not include - * delimiters of preceding lines. Index 0 is the first line of the - * content. - * @return the line text without delimiters - */ -public String getLine(int lineIndex); - -/** - * Return the line index at the given character offset. - *
- * - * @param offset offset of the line to return. The first character of the - * document is at offset 0. An offset of getLength() is valid and should - * answer the number of lines. - * @return the line index. The first line is at index 0. If the character - * at offset is a delimiter character, answer the line index of the line - * that is delimited. - * For example, if text = "\r\n\r\n", and delimiter = "\r\n", then: - *
- * - * @return the number of lines. For example: - *
- * - * @return the line delimiter that should be used by the StyledText widget - * when inserting new lines. - */ -public String getLineDelimiter(); - -/** - * Return the character offset of the first character of the given line. - *
- * NOTE: When there is no text (i.e., no lines), getOffsetAtLine(0) - * is a valid call that should return 0. - *
- * - * @param lineIndex index of the line. The first line is at index 0. - * @return offset offset of the first character of the line. The first - * character of the document is at offset 0. The return value should - * include line delimiters. - * For example, if text = "\r\ntest\r\n" and delimiter = "\r\n", then: - *- * - * @param start the start offset of the text to return. Offset 0 is the - * first character of the document. - * @param length the length of the text to return - * @return the text at the given range - */ -public String getTextRange(int start, int length); - -/** - * Remove the specified text changed listener. - *
- * - * @param listener the listener which should no longer be notified - * - * @exception IllegalArgumentException
- * Implementors have to notify the TextChangeListeners that were added
- * using addTextChangeListener
before and after the content
- * is changed. A TextChangingEvent
has to be sent to the
- * textChanging method before the content is changed and a
- * TextChangedEvent
has to be sent to the textChanged method
- * after the content has changed.
- * The text change that occurs after the TextChangingEvent
- * has been sent has to be consistent with the data provided in the
- * TextChangingEvent
.
- * This data will be cached by the widget and will be used when the
- * TextChangedEvent
is received.
- *
- * The TextChangingEvent
should be set as follows:
- *
TextChangedEvent
to the
- * textSet method of the TextChangeListeners that were added using
- * addTextChangeListener
.
- *
- *
- * @param text the new text
- * @see TextChangeListener
- */
-public void setText(String text);
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextDropTargetEffect.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextDropTargetEffect.java
deleted file mode 100644
index ba6c2ff230..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextDropTargetEffect.java
+++ /dev/null
@@ -1,242 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.custom;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.dnd.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.widgets.*;
-
-/**
- * This adapter class provides a default drag under effect (eg. select and scroll)
- * when a drag occurs over a StyledText
.
- *
- *
Classes that wish to provide their own drag under effect for a StyledText
- * can extend this class, override the StyledTextDropTargetEffect.dragOver
- * method and override any other applicable methods in StyledTextDropTargetEffect
to
- * display their own drag under effect.
super
method to get the default drag under effect implementation.
- *
- * The feedback value is either one of the FEEDBACK constants defined in
- * class DND
which is applicable to instances of this class,
- * or it must be built by bitwise OR'ing together
- * (that is, using the int
"|" operator) two or more
- * of those DND
effect constants.
- *
- *
StyledTextDropTargetEffect
to handle the drag under effect on the specified
- * StyledText
.
- *
- * @param styledText the StyledText
over which the user positions the cursor to drop the data
- */
- public StyledTextDropTargetEffect(StyledText styledText) {
- super(styledText);
- paintListener = new Listener () {
- public void handleEvent (Event event) {
- if (currentOffset != -1) {
- StyledText text = (StyledText) getControl();
- Point position = text.getLocationAtOffset(currentOffset);
- int height = text.getLineHeight(currentOffset);
- event.gc.setBackground(event.display.getSystemColor (SWT.COLOR_BLACK));
- event.gc.fillRectangle(position.x, position.y, CARET_WIDTH, height);
- }
- }
- };
- }
-
- /**
- * This implementation of dragEnter
provides a default drag under effect
- * for the feedback specified in event.feedback
.
- *
- * For additional information see DropTargetAdapter.dragEnter
.
- *
- * Subclasses that override this method should call super.dragEnter(event)
- * to get the default drag under effect implementation.
- *
- * @param event the information associated with the drag start event
- *
- * @see DropTargetAdapter
- * @see DropTargetEvent
- */
- public void dragEnter(DropTargetEvent event) {
- currentOffset = -1;
- scrollBeginTime = 0;
- scrollX = -1;
- scrollY = -1;
- getControl().removeListener(SWT.Paint, paintListener);
- getControl().addListener (SWT.Paint, paintListener);
- }
-
- /**
- * This implementation of dragLeave
provides a default drag under effect
- * for the feedback specified in event.feedback
.
- *
- * For additional information see DropTargetAdapter.dragLeave
.
- *
- * Subclasses that override this method should call super.dragLeave(event)
- * to get the default drag under effect implementation.
- *
- * @param event the information associated with the drag leave event
- *
- * @see DropTargetAdapter
- * @see DropTargetEvent
- */
- public void dragLeave(DropTargetEvent event) {
- StyledText text = (StyledText) getControl();
- if (currentOffset != -1) {
- refreshCaret(text, currentOffset, -1);
- }
- text.removeListener(SWT.Paint, paintListener);
- scrollBeginTime = 0;
- scrollX = -1;
- scrollY = -1;
- }
-
- /**
- * This implementation of dragOver
provides a default drag under effect
- * for the feedback specified in event.feedback
.
- *
- * For additional information see DropTargetAdapter.dragOver
.
- *
- * Subclasses that override this method should call super.dragOver(event)
- * to get the default drag under effect implementation.
- *
- * @param event the information associated with the drag over event
- *
- * @see DropTargetAdapter
- * @see DropTargetEvent
- * @see DND#FEEDBACK_SELECT
- * @see DND#FEEDBACK_SCROLL
- */
- public void dragOver(DropTargetEvent event) {
- int effect = event.feedback;
- StyledText text = (StyledText) getControl();
-
- Point pt = text.getDisplay().map(null, text, event.x, event.y);
- if ((effect & DND.FEEDBACK_SCROLL) == 0) {
- scrollBeginTime = 0;
- scrollX = scrollY = -1;
- } else {
- if (text.getCharCount() == 0) {
- scrollBeginTime = 0;
- scrollX = scrollY = -1;
- } else {
- if (scrollX != -1 && scrollY != -1 && scrollBeginTime != 0 &&
- (pt.x >= scrollX && pt.x <= (scrollX + SCROLL_TOLERANCE) ||
- pt.y >= scrollY && pt.y <= (scrollY + SCROLL_TOLERANCE))) {
- if (System.currentTimeMillis() >= scrollBeginTime) {
- Rectangle area = text.getClientArea();
- GC gc = new GC(text);
- FontMetrics fm = gc.getFontMetrics();
- gc.dispose();
- int charWidth = fm.getAverageCharWidth();
- int scrollAmount = 10*charWidth;
- if (pt.x < area.x + 3*charWidth) {
- int leftPixel = text.getHorizontalPixel();
- text.setHorizontalPixel(leftPixel - scrollAmount);
- }
- if (pt.x > area.width - 3*charWidth) {
- int leftPixel = text.getHorizontalPixel();
- text.setHorizontalPixel(leftPixel + scrollAmount);
- }
- int lineHeight = text.getLineHeight();
- if (pt.y < area.y + lineHeight) {
- int topPixel = text.getTopPixel();
- text.setTopPixel(topPixel - lineHeight);
- }
- if (pt.y > area.height - lineHeight) {
- int topPixel = text.getTopPixel();
- text.setTopPixel(topPixel + lineHeight);
- }
- scrollBeginTime = 0;
- scrollX = scrollY = -1;
- }
- } else {
- scrollBeginTime = System.currentTimeMillis() + SCROLL_HYSTERESIS;
- scrollX = pt.x;
- scrollY = pt.y;
- }
- }
- }
-
- if ((effect & DND.FEEDBACK_SELECT) != 0) {
- int[] trailing = new int [1];
- int newOffset = text.getOffsetAtPoint(pt.x, pt.y, trailing, false);
- newOffset += trailing [0];
- if (newOffset != currentOffset) {
- refreshCaret(text, currentOffset, newOffset);
- currentOffset = newOffset;
- }
- }
- }
-
- void refreshCaret(StyledText text, int oldOffset, int newOffset) {
- if (oldOffset != newOffset) {
- if (oldOffset != -1) {
- Point oldPos = text.getLocationAtOffset(oldOffset);
- int oldHeight = text.getLineHeight(oldOffset);
- text.redraw (oldPos.x, oldPos.y, CARET_WIDTH, oldHeight, false);
- }
- if (newOffset != -1) {
- Point newPos = text.getLocationAtOffset(newOffset);
- int newHeight = text.getLineHeight(newOffset);
- text.redraw (newPos.x, newPos.y, CARET_WIDTH, newHeight, false);
- }
- }
- }
-
- /**
- * This implementation of dropAccept
provides a default drag under effect
- * for the feedback specified in event.feedback
.
- *
- * For additional information see DropTargetAdapter.dropAccept
.
- *
- * Subclasses that override this method should call super.dropAccept(event)
- * to get the default drag under effect implementation.
- *
- * @param event the information associated with the drop accept event
- *
- * @see DropTargetAdapter
- * @see DropTargetEvent
- */
- public void dropAccept(DropTargetEvent event) {
- if (currentOffset != -1) {
- StyledText text = (StyledText) getControl();
- text.setSelection(currentOffset);
- currentOffset = -1;
- }
- }
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextEvent.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextEvent.java
deleted file mode 100755
index 84e3331af8..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextEvent.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2007 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.custom;
-
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.widgets.*;
-
-/**
- *
- */
-class StyledTextEvent extends Event {
- // used by LineStyleEvent
- int[] ranges;
- StyleRange[] styles;
- int alignment;
- int indent;
- boolean justify;
- Bullet bullet;
- int bulletIndex;
- // used by LineBackgroundEvent
- Color lineBackground;
- // used by BidiSegmentEvent
- int[] segments;
- // used by TextChangedEvent
- int replaceCharCount;
- int newCharCount;
- int replaceLineCount;
- int newLineCount;
- // used by PaintObjectEvent
- int x;
- int y;
- int ascent;
- int descent;
- StyleRange style;
-
-StyledTextEvent (StyledTextContent content) {
- super();
- data = content;
-}
-}
-
-
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextListener.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextListener.java
deleted file mode 100755
index 166e911bce..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextListener.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.custom;
-
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.widgets.*;
-import org.eclipse.swt.internal.SWTEventListener;
-
-class StyledTextListener extends TypedListener {
-/**
- */
-StyledTextListener(SWTEventListener listener) {
- super(listener);
-}
-/**
- * Process StyledText events by invoking the event's handler.
- *
- * @param e the event to handle
- */
-public void handleEvent(Event e) {
-
- switch (e.type) {
- case StyledText.ExtendedModify:
- ExtendedModifyEvent extendedModifyEvent = new ExtendedModifyEvent((StyledTextEvent) e);
- ((ExtendedModifyListener) eventListener).modifyText(extendedModifyEvent);
- break;
- case StyledText.LineGetBackground:
- LineBackgroundEvent lineBgEvent = new LineBackgroundEvent((StyledTextEvent) e);
- ((LineBackgroundListener) eventListener).lineGetBackground(lineBgEvent);
- ((StyledTextEvent) e).lineBackground = lineBgEvent.lineBackground;
- break;
- case StyledText.LineGetSegments:
- BidiSegmentEvent segmentEvent = new BidiSegmentEvent((StyledTextEvent) e);
- ((BidiSegmentListener) eventListener).lineGetSegments(segmentEvent);
- ((StyledTextEvent) e).segments = segmentEvent.segments;
- break;
- case StyledText.LineGetStyle:
- LineStyleEvent lineStyleEvent = new LineStyleEvent((StyledTextEvent) e);
- ((LineStyleListener) eventListener).lineGetStyle(lineStyleEvent);
- ((StyledTextEvent) e).ranges = lineStyleEvent.ranges;
- ((StyledTextEvent) e).styles = lineStyleEvent.styles;
- ((StyledTextEvent) e).alignment = lineStyleEvent.alignment;
- ((StyledTextEvent) e).indent = lineStyleEvent.indent;
- ((StyledTextEvent) e).justify = lineStyleEvent.justify;
- ((StyledTextEvent) e).bullet = lineStyleEvent.bullet;
- ((StyledTextEvent) e).bulletIndex = lineStyleEvent.bulletIndex;
- break;
- case StyledText.PaintObject:
- PaintObjectEvent paintObjectEvent = new PaintObjectEvent((StyledTextEvent) e);
- ((PaintObjectListener) eventListener).paintObject(paintObjectEvent);
- break;
- case StyledText.VerifyKey:
- VerifyEvent verifyEvent = new VerifyEvent(e);
- ((VerifyKeyListener) eventListener).verifyKey(verifyEvent);
- e.doit = verifyEvent.doit;
- break;
- case StyledText.TextChanged: {
- TextChangedEvent textChangedEvent = new TextChangedEvent((StyledTextContent) e.data);
- ((TextChangeListener) eventListener).textChanged(textChangedEvent);
- break;
- }
- case StyledText.TextChanging:
- TextChangingEvent textChangingEvent = new TextChangingEvent((StyledTextContent) e.data, (StyledTextEvent) e);
- ((TextChangeListener) eventListener).textChanging(textChangingEvent);
- break;
- case StyledText.TextSet: {
- TextChangedEvent textChangedEvent = new TextChangedEvent((StyledTextContent) e.data);
- ((TextChangeListener) eventListener).textSet(textChangedEvent);
- break;
- }
- case StyledText.WordNext: {
- MovementEvent wordBoundaryEvent = new MovementEvent((StyledTextEvent) e);
- ((MovementListener) eventListener).getNextOffset(wordBoundaryEvent);
- ((StyledTextEvent) e).end = wordBoundaryEvent.newOffset;
- break;
- }
- case StyledText.WordPrevious: {
- MovementEvent wordBoundaryEvent = new MovementEvent((StyledTextEvent) e);
- ((MovementListener) eventListener).getPreviousOffset(wordBoundaryEvent);
- ((StyledTextEvent) e).end = wordBoundaryEvent.newOffset;
- break;
- }
- case StyledText.CaretMoved: {
- CaretEvent caretEvent = new CaretEvent((StyledTextEvent) e);
- ((CaretListener) eventListener).caretMoved(caretEvent);
- ((StyledTextEvent) e).end = caretEvent.caretOffset;
- break;
- }
- }
-}
-}
-
-
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextPrintOptions.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextPrintOptions.java
deleted file mode 100644
index 0daad1f85e..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextPrintOptions.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.custom;
-
-/**
- * Use StyledTextPrintOptions to specify printing options for the
- * StyledText.print(Printer, StyledTextPrintOptions) API.
- * - * The following example prints a right aligned page number in the footer, - * sets the job name to "Example" and prints line background colors but no other - * formatting: - *
- *- * StyledTextPrintOptions options = new StyledTextPrintOptions(); - * options.footer = "\t\t<page>"; - * options.jobName = "Example"; - * options.printLineBackground = true; - * - * Runnable runnable = styledText.print(new Printer(), options); - * runnable.run(); - *- * - * @see Sample code and further information - * - * @since 2.1 - */ -public class StyledTextPrintOptions { - /** - * Page number placeholder constant for use in
header
- * and footer
. Value is <page>
- */
- public static final String PAGE_TAG = "header
and
- * footer
. Value is \t
- */
- public static final String SEPARATOR = "\t";
- /**
- * Formatted text to print in the header of each page.
- * "left '\t' center '\t' right"
- *left, center, right = <page> | #CDATA
- *Header and footer are defined as three separate regions for arbitrary
- * text or the page number placeholder <page>
- * (StyledTextPrintOptions.PAGE_TAG
). The three regions are
- * left aligned, centered and right aligned. They are separated by a tab
- * character (StyledTextPrintOptions.SEPARATOR
).
- */
- public String header = null;
- /**
- * Formatted text to print in the footer of each page.
- *
"left '\t' center '\t' right"
- *left, center, right = <page> | #CDATA
- *Header and footer are defined as three separate regions for arbitrary
- * text or the page number placeholder <page>
- * (StyledTextPrintOptions.PAGE_TAG
). The three regions are
- * left aligned, centered and right aligned. They are separated by a tab
- * character (StyledTextPrintOptions.SEPARATOR
).
- */
- public String footer = null;
- /**
- * Name of the print job.
- */
- public String jobName = null;
-
- /**
- * Print the text foreground color. Default value is false
.
- */
- public boolean printTextForeground = false;
- /**
- * Print the text background color. Default value is false
.
- */
- public boolean printTextBackground = false;
- /**
- * Print the font styles. Default value is false
.
- */
- public boolean printTextFontStyle = false;
- /**
- * Print the line background color. Default value is false
.
- */
- public boolean printLineBackground = false;
-
- /**
- * Print line numbers. Default value is false
.
- *
- * @since 3.3
- */
- public boolean printLineNumbers = false;
-
- /**
- * Labels used for printing line numbers.
- *
- * @since 3.4
- */
- public String[] lineLabels = null;
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextRenderer.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextRenderer.java
deleted file mode 100644
index 86dcf4d905..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextRenderer.java
+++ /dev/null
@@ -1,1568 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.custom;
-
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.widgets.*;
-
-/**
- * A StyledTextRenderer renders the content of a StyledText widget.
- * This class can be used to render to the display or to a printer.
- */
-class StyledTextRenderer {
- Device device;
- StyledText styledText;
- StyledTextContent content;
-
- /* Font info */
- Font regularFont, boldFont, italicFont, boldItalicFont;
- int tabWidth;
- int ascent, descent;
- int averageCharWidth;
-
- /* Line data */
- int topIndex = -1;
- TextLayout[] layouts;
- int lineCount;
- int[] lineWidth;
- int[] lineHeight;
- LineInfo[] lines;
- int maxWidth;
- int maxWidthLineIndex;
- boolean idleRunning;
-
- /* Bullet */
- Bullet[] bullets;
- int[] bulletsIndices;
- int[] redrawLines;
-
- /* Style data */
- int[] ranges;
- int styleCount;
- StyleRange[] styles;
- StyleRange[] stylesSet;
- int stylesSetCount = 0;
- boolean hasLinks, fixedPitch;
- final static int BULLET_MARGIN = 8;
-
- final static boolean COMPACT_STYLES = true;
- final static boolean MERGE_STYLES = true;
-
- final static int GROW = 32;
- final static int IDLE_TIME = 50;
- final static int CACHE_SIZE = 128;
-
- final static int BACKGROUND = 1 << 0;
- final static int ALIGNMENT = 1 << 1;
- final static int INDENT = 1 << 2;
- final static int JUSTIFY = 1 << 3;
- final static int SEGMENTS = 1 << 5;
-
- static class LineInfo {
- int flags;
- Color background;
- int alignment;
- int indent;
- boolean justify;
- int[] segments;
-
- public LineInfo() {
- }
- public LineInfo(LineInfo info) {
- if (info != null) {
- flags = info.flags;
- background = info.background;
- alignment = info.alignment;
- indent = info.indent;
- justify = info.justify;
- segments = info.segments;
- }
- }
- }
-
-StyledTextRenderer(Device device, StyledText styledText) {
- this.device = device;
- this.styledText = styledText;
-}
-int addMerge(int[] mergeRanges, StyleRange[] mergeStyles, int mergeCount, int modifyStart, int modifyEnd) {
- int rangeCount = styleCount << 1;
- StyleRange endStyle = null;
- int endStart = 0, endLength = 0;
- if (modifyEnd < rangeCount) {
- endStyle = styles[modifyEnd >> 1];
- endStart = ranges[modifyEnd];
- endLength = ranges[modifyEnd + 1];
- }
- int grow = mergeCount - (modifyEnd - modifyStart);
- if (rangeCount + grow >= ranges.length) {
- int[] tmpRanges = new int[ranges.length + grow + (GROW << 1)];
- System.arraycopy(ranges, 0, tmpRanges, 0, modifyStart);
- StyleRange[] tmpStyles = new StyleRange[styles.length + (grow >> 1) + GROW];
- System.arraycopy(styles, 0, tmpStyles, 0, modifyStart >> 1);
- if (rangeCount > modifyEnd) {
- System.arraycopy(ranges, modifyEnd, tmpRanges, modifyStart + mergeCount, rangeCount - modifyEnd);
- System.arraycopy(styles, modifyEnd >> 1, tmpStyles, (modifyStart + mergeCount) >> 1, styleCount - (modifyEnd >> 1));
- }
- ranges = tmpRanges;
- styles = tmpStyles;
- } else {
- if (rangeCount > modifyEnd) {
- System.arraycopy(ranges, modifyEnd, ranges, modifyStart + mergeCount, rangeCount - modifyEnd);
- System.arraycopy(styles, modifyEnd >> 1, styles, (modifyStart + mergeCount) >> 1, styleCount - (modifyEnd >> 1));
- }
- }
- if (MERGE_STYLES) {
- int j = modifyStart;
- for (int i = 0; i < mergeCount; i += 2) {
- if (j > 0 && ranges[j - 2] + ranges[j - 1] == mergeRanges[i] && mergeStyles[i >> 1].similarTo(styles[(j - 2) >> 1])) {
- ranges[j - 1] += mergeRanges[i + 1];
- } else {
- styles[j >> 1] = mergeStyles[i >> 1];
- ranges[j++] = mergeRanges[i];
- ranges[j++] = mergeRanges[i + 1];
- }
- }
- if (endStyle != null && ranges[j - 2] + ranges[j - 1] == endStart && endStyle.similarTo(styles[(j - 2) >> 1])) {
- ranges[j - 1] += endLength;
- modifyEnd += 2;
- mergeCount += 2;
- }
- if (rangeCount > modifyEnd) {
- System.arraycopy(ranges, modifyStart + mergeCount, ranges, j, rangeCount - modifyEnd);
- System.arraycopy(styles, (modifyStart + mergeCount) >> 1, styles, j >> 1, styleCount - (modifyEnd >> 1));
- }
- grow = (j - modifyStart) - (modifyEnd - modifyStart);
- } else {
- System.arraycopy(mergeRanges, 0, ranges, modifyStart, mergeCount);
- System.arraycopy(mergeStyles, 0, styles, modifyStart >> 1, mergeCount >> 1);
- }
- styleCount += grow >> 1;
- return grow;
-}
-int addMerge(StyleRange[] mergeStyles, int mergeCount, int modifyStart, int modifyEnd) {
- int grow = mergeCount - (modifyEnd - modifyStart);
- StyleRange endStyle = null;
- if (modifyEnd < styleCount) endStyle = styles[modifyEnd];
- if (styleCount + grow >= styles.length) {
- StyleRange[] tmpStyles = new StyleRange[styles.length + grow + GROW];
- System.arraycopy(styles, 0, tmpStyles, 0, modifyStart);
- if (styleCount > modifyEnd) {
- System.arraycopy(styles, modifyEnd, tmpStyles, modifyStart + mergeCount, styleCount - modifyEnd);
- }
- styles = tmpStyles;
- } else {
- if (styleCount > modifyEnd) {
- System.arraycopy(styles, modifyEnd, styles, modifyStart + mergeCount, styleCount - modifyEnd);
- }
- }
- if (MERGE_STYLES) {
- int j = modifyStart;
- for (int i = 0; i < mergeCount; i++) {
- StyleRange newStyle = mergeStyles[i], style;
- if (j > 0 && (style = styles[j - 1]).start + style.length == newStyle.start && newStyle.similarTo(style)) {
- style.length += newStyle.length;
- } else {
- styles[j++] = newStyle;
- }
- }
- StyleRange style = styles[j - 1];
- if (endStyle != null && style.start + style.length == endStyle.start && endStyle.similarTo(style)) {
- style.length += endStyle.length;
- modifyEnd++;
- mergeCount++;
- }
- if (styleCount > modifyEnd) {
- System.arraycopy(styles, modifyStart + mergeCount, styles, j, styleCount - modifyEnd);
- }
- grow = (j - modifyStart) - (modifyEnd - modifyStart);
- } else {
- System.arraycopy(mergeStyles, 0, styles, modifyStart, mergeCount);
- }
- styleCount += grow;
- return grow;
-}
-void calculate(int startLine, int lineCount) {
- int endLine = startLine + lineCount;
- if (startLine < 0 || endLine > lineWidth.length) {
- return;
- }
- int hTrim = styledText.leftMargin + styledText.rightMargin + styledText.getCaretWidth();
- for (int i = startLine; i < endLine; i++) {
- if (lineWidth[i] == -1 || lineHeight[i] == -1) {
- TextLayout layout = getTextLayout(i);
- Rectangle rect = layout.getBounds();
- lineWidth[i] = rect.width + hTrim;
- lineHeight[i] = rect.height;
- disposeTextLayout(layout);
- }
- if (lineWidth[i] > maxWidth) {
- maxWidth = lineWidth[i];
- maxWidthLineIndex = i;
- }
- }
-}
-void calculateClientArea () {
- int index = styledText.getTopIndex();
- int lineCount = content.getLineCount();
- int height = styledText.getClientArea().height;
- int y = 0;
- while (height > y && lineCount > index) {
- calculate(index, 1);
- y += lineHeight[index++];
- }
-}
-void calculateIdle () {
- if (idleRunning) return;
- Runnable runnable = new Runnable() {
- public void run() {
- if (styledText == null) return;
- int i;
- long start = System.currentTimeMillis();
- for (i = 0; i < lineCount; i++) {
- if (lineHeight[i] == -1 || lineWidth[i] == -1) {
- calculate(i, 1);
- if (System.currentTimeMillis() - start > IDLE_TIME) break;
- }
- }
- if (i < lineCount) {
- Display display = styledText.getDisplay();
- display.asyncExec(this);
- } else {
- idleRunning = false;
- styledText.setScrollBars(true);
- ScrollBar bar = styledText.getVerticalBar();
- if (bar != null) {
- bar.setSelection(styledText.getVerticalScrollOffset());
- }
- }
- }
- };
- Display display = styledText.getDisplay();
- display.asyncExec(runnable);
- idleRunning = true;
-}
-void clearLineBackground(int startLine, int count) {
- if (lines == null) return;
- for (int i = startLine; i < startLine + count; i++) {
- LineInfo info = lines[i];
- if (info != null) {
- info.flags &= ~BACKGROUND;
- info.background = null;
- if (info.flags == 0) lines[i] = null;
- }
- }
-}
-void clearLineStyle(int startLine, int count) {
- if (lines == null) return;
- for (int i = startLine; i < startLine + count; i++) {
- LineInfo info = lines[i];
- if (info != null) {
- info.flags &= ~(ALIGNMENT | INDENT | JUSTIFY);
- if (info.flags == 0) lines[i] = null;
- }
- }
-}
-void copyInto(StyledTextRenderer renderer) {
- if (ranges != null) {
- int[] newRanges = renderer.ranges = new int[styleCount << 1];
- System.arraycopy(ranges, 0, newRanges, 0, newRanges.length);
- }
- if (styles != null) {
- StyleRange[] newStyles = renderer.styles = new StyleRange[styleCount];
- for (int i = 0; i < newStyles.length; i++) {
- newStyles[i] = (StyleRange)styles[i].clone();
- }
- renderer.styleCount = styleCount;
- }
- if (lines != null) {
- LineInfo[] newLines = renderer.lines = new LineInfo[lineCount];
- for (int i = 0; i < newLines.length; i++) {
- newLines[i] = new LineInfo(lines[i]);
- }
- renderer.lineCount = lineCount;
- }
-}
-void dispose() {
- if (boldFont != null) boldFont.dispose();
- if (italicFont != null) italicFont.dispose();
- if (boldItalicFont != null) boldItalicFont.dispose();
- boldFont = italicFont = boldItalicFont = null;
- reset();
- content = null;
- device = null;
- styledText = null;
-}
-void disposeTextLayout (TextLayout layout) {
- if (layouts != null) {
- for (int i = 0; i < layouts.length; i++) {
- if (layouts[i] == layout) return;
- }
- }
- layout.dispose();
-}
-void drawBullet(Bullet bullet, GC gc, int paintX, int paintY, int index, int lineAscent, int lineDescent) {
- StyleRange style = bullet.style;
- GlyphMetrics metrics = style.metrics;
- Color color = style.foreground;
- if (color != null) gc.setForeground(color);
- if ((bullet.type & ST.BULLET_DOT) != 0 && StyledText.IS_MOTIF) {
- int size = Math.max(4, (lineAscent + lineDescent) / 4);
- if ((size & 1) == 0) size++;
- if (color == null) {
- Display display = styledText.getDisplay();
- color = display.getSystemColor(SWT.COLOR_BLACK);
- }
- gc.setBackground(color);
- int x = paintX + Math.max(0, metrics.width - size - BULLET_MARGIN);
- gc.fillArc(x, paintY + size, size + 1, size + 1, 0, 360);
- return;
- }
- Font font = style.font;
- if (font != null) gc.setFont(font);
- String string = "";
- int type = bullet.type & (ST.BULLET_DOT|ST.BULLET_NUMBER|ST.BULLET_LETTER_LOWER|ST.BULLET_LETTER_UPPER);
- switch (type) {
- case ST.BULLET_DOT: string = "\u2022"; break;
- case ST.BULLET_NUMBER: string = String.valueOf(index); break;
- case ST.BULLET_LETTER_LOWER: string = String.valueOf((char) (index % 26 + 97)); break;
- case ST.BULLET_LETTER_UPPER: string = String.valueOf((char) (index % 26 + 65)); break;
- }
- if ((bullet.type & ST.BULLET_TEXT) != 0) string += bullet.text;
- Display display = styledText.getDisplay();
- TextLayout layout = new TextLayout(display);
- layout.setText(string);
- layout.setAscent(lineAscent);
- layout.setDescent(lineDescent);
- style = (StyleRange)style.clone();
- style.metrics = null;
- if (style.font == null) style.font = getFont(style.fontStyle);
- layout.setStyle(style, 0, string.length());
- int x = paintX + Math.max(0, metrics.width - layout.getBounds().width - BULLET_MARGIN);
- layout.draw(gc, x, paintY);
- layout.dispose();
-}
-int drawLine(int lineIndex, int paintX, int paintY, GC gc, Color widgetBackground, Color widgetForeground) {
- TextLayout layout = getTextLayout(lineIndex);
- String line = content.getLine(lineIndex);
- int lineOffset = content.getOffsetAtLine(lineIndex);
- int lineLength = line.length();
- Point selection = styledText.getSelection();
- int selectionStart = selection.x - lineOffset;
- int selectionEnd = selection.y - lineOffset;
- if (styledText.getBlockSelection()) {
- selectionStart = selectionEnd = 0;
- }
- Rectangle client = styledText.getClientArea();
- Color lineBackground = getLineBackground(lineIndex, null);
- StyledTextEvent event = styledText.getLineBackgroundData(lineOffset, line);
- if (event != null && event.lineBackground != null) lineBackground = event.lineBackground;
- int height = layout.getBounds().height;
- if (lineBackground != null) {
- gc.setBackground(lineBackground);
- gc.fillRectangle(client.x, paintY, client.width, height);
- } else {
- gc.setBackground(widgetBackground);
- styledText.drawBackground(gc, client.x, paintY, client.width, height);
- }
- gc.setForeground(widgetForeground);
- if (selectionStart == selectionEnd || (selectionEnd <= 0 && selectionStart > lineLength - 1)) {
- layout.draw(gc, paintX, paintY);
- } else {
- int start = Math.max(0, selectionStart);
- int end = Math.min(lineLength, selectionEnd);
- Color selectionFg = styledText.getSelectionForeground();
- Color selectionBg = styledText.getSelectionBackground();
- int flags;
- if ((styledText.getStyle() & SWT.FULL_SELECTION) != 0) {
- flags = SWT.FULL_SELECTION;
- } else {
- flags = SWT.DELIMITER_SELECTION;
- }
- if (selectionStart <= lineLength && lineLength < selectionEnd ) {
- flags |= SWT.LAST_LINE_SELECTION;
- }
- layout.draw(gc, paintX, paintY, start, end - 1, selectionFg, selectionBg, flags);
- }
-
- // draw objects
- Bullet bullet = null;
- int bulletIndex = -1;
- if (bullets != null) {
- if (bulletsIndices != null) {
- int index = lineIndex - topIndex;
- if (0 <= index && index < CACHE_SIZE) {
- bullet = bullets[index];
- bulletIndex = bulletsIndices[index];
- }
- } else {
- for (int i = 0; i < bullets.length; i++) {
- bullet = bullets[i];
- bulletIndex = bullet.indexOf(lineIndex);
- if (bulletIndex != -1) break;
- }
- }
- }
- if (bulletIndex != -1 && bullet != null) {
- FontMetrics metrics = layout.getLineMetrics(0);
- int lineAscent = metrics.getAscent() + metrics.getLeading();
- if (bullet.type == ST.BULLET_CUSTOM) {
- bullet.style.start = lineOffset;
- styledText.paintObject(gc, paintX, paintY, lineAscent, metrics.getDescent(), bullet.style, bullet, bulletIndex);
- } else {
- drawBullet(bullet, gc, paintX, paintY, bulletIndex, lineAscent, metrics.getDescent());
- }
- }
- TextStyle[] styles = layout.getStyles();
- int[] ranges = null;
- for (int i = 0; i < styles.length; i++) {
- if (styles[i].metrics != null) {
- if (ranges == null) ranges = layout.getRanges();
- int start = ranges[i << 1];
- int length = ranges[(i << 1) + 1] - start;
- Point point = layout.getLocation(start, false);
- FontMetrics metrics = layout.getLineMetrics(layout.getLineIndex(start));
- StyleRange style = (StyleRange)((StyleRange)styles[i]).clone();
- style.start = start + lineOffset;
- style.length = length;
- int lineAscent = metrics.getAscent() + metrics.getLeading();
- styledText.paintObject(gc, point.x + paintX, point.y + paintY, lineAscent, metrics.getDescent(), style, null, 0);
- }
- }
- disposeTextLayout(layout);
- return height;
-}
-int getBaseline() {
- return ascent;
-}
-Font getFont(int style) {
- switch (style) {
- case SWT.BOLD:
- if (boldFont != null) return boldFont;
- return boldFont = new Font(device, getFontData(style));
- case SWT.ITALIC:
- if (italicFont != null) return italicFont;
- return italicFont = new Font(device, getFontData(style));
- case SWT.BOLD | SWT.ITALIC:
- if (boldItalicFont != null) return boldItalicFont;
- return boldItalicFont = new Font(device, getFontData(style));
- default:
- return regularFont;
- }
-}
-FontData[] getFontData(int style) {
- FontData[] fontDatas = regularFont.getFontData();
- for (int i = 0; i < fontDatas.length; i++) {
- fontDatas[i].setStyle(style);
- }
- return fontDatas;
-}
-int getHeight () {
- int defaultLineHeight = getLineHeight();
- if (styledText.isFixedLineHeight()) {
- return lineCount * defaultLineHeight + styledText.topMargin + styledText.bottomMargin;
- }
- int totalHeight = 0;
- int width = styledText.getWrapWidth();
- for (int i = 0; i < lineCount; i++) {
- int height = lineHeight[i];
- if (height == -1) {
- if (width > 0) {
- int length = content.getLine(i).length();
- height = ((length * averageCharWidth / width) + 1) * defaultLineHeight;
- } else {
- height = defaultLineHeight;
- }
- }
- totalHeight += height;
- }
- return totalHeight + styledText.topMargin + styledText.bottomMargin;
-}
-boolean hasLink(int offset) {
- if (offset == -1) return false;
- int lineIndex = content.getLineAtOffset(offset);
- int lineOffset = content.getOffsetAtLine(lineIndex);
- String line = content.getLine(lineIndex);
- StyledTextEvent event = styledText.getLineStyleData(lineOffset, line);
- if (event != null) {
- StyleRange[] styles = event.styles;
- if (styles != null) {
- int[] ranges = event.ranges;
- if (ranges != null) {
- for (int i = 0; i < ranges.length; i+=2) {
- if (ranges[i] <= offset && offset < ranges[i] + ranges[i+1] && styles[i >> 1].underline && styles[i >> 1].underlineStyle == SWT.UNDERLINE_LINK) {
- return true;
- }
- }
- } else {
- for (int i = 0; i < styles.length; i++) {
- if (styles[i].start <= offset && offset < styles[i].start + styles[i].length && styles[i >> 1].underline && styles[i >> 1].underlineStyle == SWT.UNDERLINE_LINK) {
- return true;
- }
- }
- }
- }
- } else {
- if (ranges != null) {
- int rangeCount = styleCount << 1;
- int index = getRangeIndex(offset, -1, rangeCount);
- if (index >= rangeCount) return false;
- int rangeStart = ranges[index];
- int rangeLength = ranges[index + 1];
- StyleRange rangeStyle = styles[index >> 1];
- if (rangeStart <= offset && offset < rangeStart + rangeLength && rangeStyle.underline && rangeStyle.underlineStyle == SWT.UNDERLINE_LINK) {
- return true;
- }
- }
- }
- return false;
-}
-int getLineAlignment(int index, int defaultAlignment) {
- if (lines == null) return defaultAlignment;
- LineInfo info = lines[index];
- if (info != null && (info.flags & ALIGNMENT) != 0) {
- return info.alignment;
- }
- return defaultAlignment;
-}
-Color getLineBackground(int index, Color defaultBackground) {
- if (lines == null) return defaultBackground;
- LineInfo info = lines[index];
- if (info != null && (info.flags & BACKGROUND) != 0) {
- return info.background;
- }
- return defaultBackground;
-}
-Bullet getLineBullet (int index, Bullet defaultBullet) {
- if (bullets == null) return defaultBullet;
- if (bulletsIndices != null) return defaultBullet;
- for (int i = 0; i < bullets.length; i++) {
- Bullet bullet = bullets[i];
- if (bullet.indexOf(index) != -1) return bullet;
- }
- return defaultBullet;
-}
-int getLineHeight() {
- return ascent + descent;
-}
-int getLineHeight(int lineIndex) {
- if (lineHeight[lineIndex] == -1) {
- calculate(lineIndex, 1);
- }
- return lineHeight[lineIndex];
-}
-int getLineIndent(int index, int defaultIndent) {
- if (lines == null) return defaultIndent;
- LineInfo info = lines[index];
- if (info != null && (info.flags & INDENT) != 0) {
- return info.indent;
- }
- return defaultIndent;
-}
-boolean getLineJustify(int index, boolean defaultJustify) {
- if (lines == null) return defaultJustify;
- LineInfo info = lines[index];
- if (info != null && (info.flags & JUSTIFY) != 0) {
- return info.justify;
- }
- return defaultJustify;
-}
-int[] getLineSegments(int index, int[] defaultSegments) {
- if (lines == null) return defaultSegments;
- LineInfo info = lines[index];
- if (info != null && (info.flags & SEGMENTS) != 0) {
- return info.segments;
- }
- return defaultSegments;
-}
-int getRangeIndex(int offset, int low, int high) {
- if (styleCount == 0) return 0;
- if (ranges != null) {
- while (high - low > 2) {
- int index = ((high + low) / 2) / 2 * 2;
- int end = ranges[index] + ranges[index + 1];
- if (end > offset) {
- high = index;
- } else {
- low = index;
- }
- }
- } else {
- while (high - low > 1) {
- int index = ((high + low) / 2);
- int end = styles[index].start + styles[index].length;
- if (end > offset) {
- high = index;
- } else {
- low = index;
- }
- }
- }
- return high;
-}
-int[] getRanges(int start, int length) {
- if (length == 0) return null;
- int[] newRanges;
- int end = start + length - 1;
- if (ranges != null) {
- int rangeCount = styleCount << 1;
- int rangeStart = getRangeIndex(start, -1, rangeCount);
- if (rangeStart >= rangeCount) return null;
- if (ranges[rangeStart] > end) return null;
- int rangeEnd = Math.min(rangeCount - 2, getRangeIndex(end, rangeStart - 1, rangeCount));
- if (ranges[rangeEnd] > end) rangeEnd = Math.max(rangeStart, rangeEnd - 2);
- newRanges = new int[rangeEnd - rangeStart + 2];
- System.arraycopy(ranges, rangeStart, newRanges, 0, newRanges.length);
- } else {
- int rangeStart = getRangeIndex(start, -1, styleCount);
- if (rangeStart >= styleCount) return null;
- if (styles[rangeStart].start > end) return null;
- int rangeEnd = Math.min(styleCount - 1, getRangeIndex(end, rangeStart - 1, styleCount));
- if (styles[rangeEnd].start > end) rangeEnd = Math.max(rangeStart, rangeEnd - 1);
- newRanges = new int[(rangeEnd - rangeStart + 1) << 1];
- for (int i = rangeStart, j = 0; i <= rangeEnd; i++, j += 2) {
- StyleRange style = styles[i];
- newRanges[j] = style.start;
- newRanges[j + 1] = style.length;
- }
- }
- if (start > newRanges[0]) {
- newRanges[1] = newRanges[0] + newRanges[1] - start;
- newRanges[0] = start;
- }
- if (end < newRanges[newRanges.length - 2] + newRanges[newRanges.length - 1] - 1) {
- newRanges[newRanges.length - 1] = end - newRanges[newRanges.length - 2] + 1;
- }
- return newRanges;
-}
-StyleRange[] getStyleRanges(int start, int length, boolean includeRanges) {
- if (length == 0) return null;
- StyleRange[] newStyles;
- int end = start + length - 1;
- if (ranges != null) {
- int rangeCount = styleCount << 1;
- int rangeStart = getRangeIndex(start, -1, rangeCount);
- if (rangeStart >= rangeCount) return null;
- if (ranges[rangeStart] > end) return null;
- int rangeEnd = Math.min(rangeCount - 2, getRangeIndex(end, rangeStart - 1, rangeCount));
- if (ranges[rangeEnd] > end) rangeEnd = Math.max(rangeStart, rangeEnd - 2);
- newStyles = new StyleRange[((rangeEnd - rangeStart) >> 1) + 1];
- if (includeRanges) {
- for (int i = rangeStart, j = 0; i <= rangeEnd; i += 2, j++) {
- newStyles[j] = (StyleRange)styles[i >> 1].clone();
- newStyles[j].start = ranges[i];
- newStyles[j].length = ranges[i + 1];
- }
- } else {
- System.arraycopy(styles, rangeStart >> 1, newStyles, 0, newStyles.length);
- }
- } else {
- int rangeStart = getRangeIndex(start, -1, styleCount);
- if (rangeStart >= styleCount) return null;
- if (styles[rangeStart].start > end) return null;
- int rangeEnd = Math.min(styleCount - 1, getRangeIndex(end, rangeStart - 1, styleCount));
- if (styles[rangeEnd].start > end) rangeEnd = Math.max(rangeStart, rangeEnd - 1);
- newStyles = new StyleRange[rangeEnd - rangeStart + 1];
- System.arraycopy(styles, rangeStart, newStyles, 0, newStyles.length);
- }
- if (includeRanges || ranges == null) {
- StyleRange style = newStyles[0];
- if (start > style.start) {
- newStyles[0] = style = (StyleRange)style.clone();
- style.length = style.start + style.length - start;
- style.start = start;
- }
- style = newStyles[newStyles.length - 1];
- if (end < style.start + style.length - 1) {
- newStyles[newStyles.length - 1] = style = (StyleRange)style.clone();
- style.length = end - style.start + 1;
- }
- }
- return newStyles;
-}
-StyleRange getStyleRange(StyleRange style) {
- if (style.underline && style.underlineStyle == SWT.UNDERLINE_LINK) hasLinks = true;
- if (style.start == 0 && style.length == 0 && style.fontStyle == SWT.NORMAL) return style;
- StyleRange clone = (StyleRange)style.clone();
- clone.start = clone.length = 0;
- clone.fontStyle = SWT.NORMAL;
- if (clone.font == null) clone.font = getFont(style.fontStyle);
- return clone;
-}
-TextLayout getTextLayout(int lineIndex) {
- return getTextLayout(lineIndex, styledText.getOrientation(), styledText.getWrapWidth(), styledText.lineSpacing);
-}
-TextLayout getTextLayout(int lineIndex, int orientation, int width, int lineSpacing) {
- TextLayout layout = null;
- if (styledText != null) {
- int topIndex = styledText.topIndex > 0 ? styledText.topIndex - 1 : 0;
- if (layouts == null || topIndex != this.topIndex) {
- TextLayout[] newLayouts = new TextLayout[CACHE_SIZE];
- if (layouts != null) {
- for (int i = 0; i < layouts.length; i++) {
- if (layouts[i] != null) {
- int layoutIndex = (i + this.topIndex) - topIndex;
- if (0 <= layoutIndex && layoutIndex < newLayouts.length) {
- newLayouts[layoutIndex] = layouts[i];
- } else {
- layouts[i].dispose();
- }
- }
- }
- }
- if (bullets != null && bulletsIndices != null && topIndex != this.topIndex) {
- int delta = topIndex - this.topIndex;
- if (delta > 0) {
- if (delta < bullets.length) {
- System.arraycopy(bullets, delta, bullets, 0, bullets.length - delta);
- System.arraycopy(bulletsIndices, delta, bulletsIndices, 0, bulletsIndices.length - delta);
- }
- int startIndex = Math.max(0, bullets.length - delta);
- for (int i = startIndex; i < bullets.length; i++) bullets[i] = null;
- } else {
- if (-delta < bullets.length) {
- System.arraycopy(bullets, 0, bullets, -delta, bullets.length + delta);
- System.arraycopy(bulletsIndices, 0, bulletsIndices, -delta, bulletsIndices.length + delta);
- }
- int endIndex = Math.min(bullets.length, -delta);
- for (int i = 0; i < endIndex; i++) bullets[i] = null;
- }
- }
- this.topIndex = topIndex;
- layouts = newLayouts;
- }
- if (layouts != null) {
- int layoutIndex = lineIndex - topIndex;
- if (0 <= layoutIndex && layoutIndex < layouts.length) {
- layout = layouts[layoutIndex];
- if (layout != null) {
- if (lineWidth[lineIndex] != -1) return layout;
- } else {
- layout = layouts[layoutIndex] = new TextLayout(device);
- }
- }
- }
- }
- if (layout == null) layout = new TextLayout(device);
- String line = content.getLine(lineIndex);
- int lineOffset = content.getOffsetAtLine(lineIndex);
- int[] segments = null;
- int indent = 0;
- int alignment = SWT.LEFT;
- boolean justify = false;
- Bullet bullet = null;
- int[] ranges = null;
- StyleRange[] styles = null;
- int rangeStart = 0, styleCount = 0;
- StyledTextEvent event = null;
- if (styledText != null) {
- event = styledText.getLineStyleData(lineOffset, line);
- segments = styledText.getBidiSegments(lineOffset, line);
- indent = styledText.indent;
- alignment = styledText.alignment;
- justify = styledText.justify;
- }
- if (event != null) {
- indent = event.indent;
- alignment = event.alignment;
- justify = event.justify;
- bullet = event.bullet;
- ranges = event.ranges;
- styles = event.styles;
- if (styles != null) {
- styleCount = styles.length;
- if (styledText.isFixedLineHeight()) {
- for (int i = 0; i < styleCount; i++) {
- if (styles[i].isVariableHeight()) {
- styledText.verticalScrollOffset = -1;
- styledText.setVariableLineHeight();
- styledText.redraw();
- break;
- }
- }
- }
- }
- if (bullets == null || bulletsIndices == null) {
- bullets = new Bullet[CACHE_SIZE];
- bulletsIndices = new int[CACHE_SIZE];
- }
- int index = lineIndex - topIndex;
- if (0 <= index && index < CACHE_SIZE) {
- bullets[index] = bullet;
- bulletsIndices[index] = event.bulletIndex;
- }
- } else {
- if (lines != null) {
- LineInfo info = lines[lineIndex];
- if (info != null) {
- if ((info.flags & INDENT) != 0) indent = info.indent;
- if ((info.flags & ALIGNMENT) != 0) alignment = info.alignment;
- if ((info.flags & JUSTIFY) != 0) justify = info.justify;
- if ((info.flags & SEGMENTS) != 0) segments = info.segments;
- }
- }
- if (bulletsIndices != null) {
- bullets = null;
- bulletsIndices = null;
- }
- if (bullets != null) {
- for (int i = 0; i < bullets.length; i++) {
- if (bullets[i].indexOf(lineIndex) != -1) {
- bullet = bullets[i];
- break;
- }
- }
- }
- ranges = this.ranges;
- styles = this.styles;
- styleCount = this.styleCount;
- if (ranges != null) {
- rangeStart = getRangeIndex(lineOffset, -1, styleCount << 1);
- } else {
- rangeStart = getRangeIndex(lineOffset, -1, styleCount);
- }
- }
- if (bullet != null) {
- StyleRange style = bullet.style;
- GlyphMetrics metrics = style.metrics;
- indent += metrics.width;
- }
- layout.setFont(regularFont);
- layout.setAscent(ascent);
- layout.setDescent(descent);
- layout.setText(line);
- layout.setOrientation(orientation);
- layout.setSegments(segments);
- layout.setWidth(width);
- layout.setSpacing(lineSpacing);
- layout.setTabs(new int[]{tabWidth});
- layout.setIndent(indent);
- layout.setAlignment(alignment);
- layout.setJustify(justify);
-
- int lastOffset = 0;
- int length = line.length();
- if (styles != null) {
- if (ranges != null) {
- int rangeCount = styleCount << 1;
- for (int i = rangeStart; i < rangeCount; i += 2) {
- int start, end;
- if (lineOffset > ranges[i]) {
- start = 0;
- end = Math.min (length, ranges[i + 1] - lineOffset + ranges[i]);
- } else {
- start = ranges[i] - lineOffset;
- end = Math.min(length, start + ranges[i + 1]);
- }
- if (start >= length) break;
- if (lastOffset < start) {
- layout.setStyle(null, lastOffset, start - 1);
- }
- layout.setStyle(getStyleRange(styles[i >> 1]), start, end);
- lastOffset = Math.max(lastOffset, end);
- }
- } else {
- for (int i = rangeStart; i < styleCount; i++) {
- int start, end;
- if (lineOffset > styles[i].start) {
- start = 0;
- end = Math.min (length, styles[i].length - lineOffset + styles[i].start);
- } else {
- start = styles[i].start - lineOffset;
- end = Math.min(length, start + styles[i].length);
- }
- if (start >= length) break;
- if (lastOffset < start) {
- layout.setStyle(null, lastOffset, start - 1);
- }
- layout.setStyle(getStyleRange(styles[i]), start, end);
- lastOffset = Math.max(lastOffset, end);
- }
- }
- }
- if (lastOffset < length) layout.setStyle(null, lastOffset, length);
- if (styledText != null && styledText.ime != null) {
- IME ime = styledText.ime;
- int compositionOffset = ime.getCompositionOffset();
- if (compositionOffset != -1) {
- int commitCount = ime.getCommitCount();
- int compositionLength = ime.getText().length();
- if (compositionLength != commitCount) {
- int compositionLine = content.getLineAtOffset(compositionOffset);
- if (compositionLine == lineIndex) {
- int[] imeRanges = ime.getRanges();
- TextStyle[] imeStyles = ime.getStyles();
- if (imeRanges.length > 0) {
- for (int i = 0; i < imeStyles.length; i++) {
- int start = imeRanges[i*2] - lineOffset;
- int end = imeRanges[i*2+1] - lineOffset;
- TextStyle imeStyle = imeStyles[i], userStyle;
- for (int j = start; j <= end; j++) {
- userStyle = layout.getStyle(j);
- if (userStyle == null && j > 0) userStyle = layout.getStyle(j - 1);
- if (userStyle == null && j + 1 < length) userStyle = layout.getStyle(j + 1);
- if (userStyle == null) {
- layout.setStyle(imeStyle, j, j);
- } else {
- TextStyle newStyle = new TextStyle(imeStyle);
- if (newStyle.font == null) newStyle.font = userStyle.font;
- if (newStyle.foreground == null) newStyle.foreground = userStyle.foreground;
- if (newStyle.background == null) newStyle.background = userStyle.background;
- layout.setStyle(newStyle, j, j);
- }
- }
- }
- } else {
- int start = compositionOffset - lineOffset;
- int end = start + compositionLength - 1;
- TextStyle userStyle = layout.getStyle(start);
- if (userStyle == null) {
- if (start > 0) userStyle = layout.getStyle(start - 1);
- if (userStyle == null && end + 1 < length) userStyle = layout.getStyle(end + 1);
- if (userStyle != null) {
- TextStyle newStyle = new TextStyle();
- newStyle.font = userStyle.font;
- newStyle.foreground = userStyle.foreground;
- newStyle.background = userStyle.background;
- layout.setStyle(newStyle, start, end);
- }
- }
- }
- }
- }
- }
- }
-
- if (styledText != null && styledText.isFixedLineHeight()) {
- int index = -1;
- int lineCount = layout.getLineCount();
- int height = getLineHeight();
- for (int i = 0; i < lineCount; i++) {
- int lineHeight = layout.getLineBounds(i).height;
- if (lineHeight > height) {
- height = lineHeight;
- index = i;
- }
- }
- if (index != -1) {
- FontMetrics metrics = layout.getLineMetrics(index);
- ascent = metrics.getAscent() + metrics.getLeading();
- descent = metrics.getDescent();
- if (layouts != null) {
- for (int i = 0; i < layouts.length; i++) {
- if (layouts[i] != null && layouts[i] != layout) {
- layouts[i].setAscent(ascent);
- layouts[i].setDescent(descent);
- }
- }
- }
- if (styledText.verticalScrollOffset != 0) {
- int topIndex = styledText.topIndex;
- int topIndexY = styledText.topIndexY;
- int lineHeight = getLineHeight();
- if (topIndexY >= 0) {
- styledText.verticalScrollOffset = (topIndex - 1) * lineHeight + lineHeight - topIndexY;
- } else {
- styledText.verticalScrollOffset = topIndex * lineHeight - topIndexY;
- }
- }
- styledText.calculateScrollBars();
- if (styledText.isBidiCaret()) styledText.createCaretBitmaps();
- styledText.caretDirection = SWT.NULL;
- styledText.setCaretLocation();
- styledText.redraw();
- }
- }
- return layout;
-}
-int getWidth() {
- return maxWidth;
-}
-void reset() {
- if (layouts != null) {
- for (int i = 0; i < layouts.length; i++) {
- TextLayout layout = layouts[i];
- if (layout != null) layout.dispose();
- }
- layouts = null;
- }
- topIndex = -1;
- stylesSetCount = styleCount = lineCount = 0;
- ranges = null;
- styles = null;
- stylesSet = null;
- lines = null;
- lineWidth = null;
- lineHeight = null;
- bullets = null;
- bulletsIndices = null;
- redrawLines = null;
- hasLinks = false;
-}
-void reset(int startLine, int lineCount) {
- int endLine = startLine + lineCount;
- if (startLine < 0 || endLine > lineWidth.length) return;
- for (int i = startLine; i < endLine; i++) {
- lineWidth[i] = -1;
- lineHeight[i] = -1;
- }
- if (startLine <= maxWidthLineIndex && maxWidthLineIndex < endLine) {
- maxWidth = 0;
- maxWidthLineIndex = -1;
- if (lineCount != this.lineCount) {
- for (int i = 0; i < this.lineCount; i++) {
- if (lineWidth[i] > maxWidth) {
- maxWidth = lineWidth[i];
- maxWidthLineIndex = i;
- }
- }
- }
- }
-}
-void setContent(StyledTextContent content) {
- reset();
- this.content = content;
- lineCount = content.getLineCount();
- lineWidth = new int[lineCount];
- lineHeight = new int[lineCount];
- reset(0, lineCount);
-}
-void setFont(Font font, int tabs) {
- TextLayout layout = new TextLayout(device);
- layout.setFont(regularFont);
- if (font != null) {
- if (boldFont != null) boldFont.dispose();
- if (italicFont != null) italicFont.dispose();
- if (boldItalicFont != null) boldItalicFont.dispose();
- boldFont = italicFont = boldItalicFont = null;
- regularFont = font;
- layout.setText(" ");
- layout.setFont(font);
- layout.setStyle(new TextStyle(getFont(SWT.NORMAL), null, null), 0, 0);
- layout.setStyle(new TextStyle(getFont(SWT.BOLD), null, null), 1, 1);
- layout.setStyle(new TextStyle(getFont(SWT.ITALIC), null, null), 2, 2);
- layout.setStyle(new TextStyle(getFont(SWT.BOLD | SWT.ITALIC), null, null), 3, 3);
- FontMetrics metrics = layout.getLineMetrics(0);
- ascent = metrics.getAscent() + metrics.getLeading();
- descent = metrics.getDescent();
- boldFont.dispose();
- italicFont.dispose();
- boldItalicFont.dispose();
- boldFont = italicFont = boldItalicFont = null;
- }
- layout.dispose();
- layout = new TextLayout(device);
- layout.setFont(regularFont);
- StringBuffer tabBuffer = new StringBuffer(tabs);
- for (int i = 0; i < tabs; i++) {
- tabBuffer.append(' ');
- }
- layout.setText(tabBuffer.toString());
- tabWidth = layout.getBounds().width;
- layout.dispose();
- if (styledText != null) {
- GC gc = new GC(styledText);
- averageCharWidth = gc.getFontMetrics().getAverageCharWidth();
- fixedPitch = gc.stringExtent("l").x == gc.stringExtent("W").x; //$NON-NLS-1$ //$NON-NLS-2$
- gc.dispose();
- }
-}
-void setLineAlignment(int startLine, int count, int alignment) {
- if (lines == null) lines = new LineInfo[lineCount];
- for (int i = startLine; i < startLine + count; i++) {
- if (lines[i] == null) {
- lines[i] = new LineInfo();
- }
- lines[i].flags |= ALIGNMENT;
- lines[i].alignment = alignment;
- }
-}
-void setLineBackground(int startLine, int count, Color background) {
- if (lines == null) lines = new LineInfo[lineCount];
- for (int i = startLine; i < startLine + count; i++) {
- if (lines[i] == null) {
- lines[i] = new LineInfo();
- }
- lines[i].flags |= BACKGROUND;
- lines[i].background = background;
- }
-}
-void setLineBullet(int startLine, int count, Bullet bullet) {
- if (bulletsIndices != null) {
- bulletsIndices = null;
- bullets = null;
- }
- if (bullets == null) {
- if (bullet == null) return;
- bullets = new Bullet[1];
- bullets[0] = bullet;
- }
- int index = 0;
- while (index < bullets.length) {
- if (bullet == bullets[index]) break;
- index++;
- }
- if (bullet != null) {
- if (index == bullets.length) {
- Bullet[] newBulletsList = new Bullet[bullets.length + 1];
- System.arraycopy(bullets, 0, newBulletsList, 0, bullets.length);
- newBulletsList[index] = bullet;
- bullets = newBulletsList;
- }
- bullet.addIndices(startLine, count);
- } else {
- updateBullets(startLine, count, 0, false);
- styledText.redrawLinesBullet(redrawLines);
- redrawLines = null;
- }
-}
-void setLineIndent(int startLine, int count, int indent) {
- if (lines == null) lines = new LineInfo[lineCount];
- for (int i = startLine; i < startLine + count; i++) {
- if (lines[i] == null) {
- lines[i] = new LineInfo();
- }
- lines[i].flags |= INDENT;
- lines[i].indent = indent;
- }
-}
-void setLineJustify(int startLine, int count, boolean justify) {
- if (lines == null) lines = new LineInfo[lineCount];
- for (int i = startLine; i < startLine + count; i++) {
- if (lines[i] == null) {
- lines[i] = new LineInfo();
- }
- lines[i].flags |= JUSTIFY;
- lines[i].justify = justify;
- }
-}
-void setLineSegments(int startLine, int count, int[] segments) {
- if (lines == null) lines = new LineInfo[lineCount];
- for (int i = startLine; i < startLine + count; i++) {
- if (lines[i] == null) {
- lines[i] = new LineInfo();
- }
- lines[i].flags |= SEGMENTS;
- lines[i].segments = segments;
- }
-}
-void setStyleRanges (int[] newRanges, StyleRange[] newStyles) {
- if (newStyles == null) {
- stylesSetCount = styleCount = 0;
- ranges = null;
- styles = null;
- stylesSet = null;
- hasLinks = false;
- return;
- }
- if (newRanges == null && COMPACT_STYLES) {
- newRanges = new int[newStyles.length << 1];
- StyleRange[] tmpStyles = new StyleRange[newStyles.length];
- if (stylesSet == null) stylesSet = new StyleRange[4];
- for (int i = 0, j = 0; i < newStyles.length; i++) {
- StyleRange newStyle = newStyles[i];
- newRanges[j++] = newStyle.start;
- newRanges[j++] = newStyle.length;
- int index = 0;
- while (index < stylesSetCount) {
- if (stylesSet[index].similarTo(newStyle)) break;
- index++;
- }
- if (index == stylesSetCount) {
- if (stylesSetCount == stylesSet.length) {
- StyleRange[] tmpStylesSet = new StyleRange[stylesSetCount + 4];
- System.arraycopy(stylesSet, 0, tmpStylesSet, 0, stylesSetCount);
- stylesSet = tmpStylesSet;
- }
- stylesSet[stylesSetCount++] = newStyle;
- }
- tmpStyles[i] = stylesSet[index];
- }
- newStyles = tmpStyles;
- }
-
- if (styleCount == 0) {
- if (newRanges != null) {
- ranges = new int[newRanges.length];
- System.arraycopy(newRanges, 0, ranges, 0, ranges.length);
- }
- styles = new StyleRange[newStyles.length];
- System.arraycopy(newStyles, 0, styles, 0, styles.length);
- styleCount = newStyles.length;
- return;
- }
- if (newRanges != null && ranges == null) {
- ranges = new int[styles.length << 1];
- for (int i = 0, j = 0; i < styleCount; i++) {
- ranges[j++] = styles[i].start;
- ranges[j++] = styles[i].length;
- }
- }
- if (newRanges == null && ranges != null) {
- newRanges = new int[newStyles.length << 1];
- for (int i = 0, j = 0; i < newStyles.length; i++) {
- newRanges[j++] = newStyles[i].start;
- newRanges[j++] = newStyles[i].length;
- }
- }
- if (ranges != null) {
- int rangeCount = styleCount << 1;
- int start = newRanges[0];
- int modifyStart = getRangeIndex(start, -1, rangeCount), modifyEnd;
- boolean insert = modifyStart == rangeCount;
- if (!insert) {
- int end = newRanges[newRanges.length - 2] + newRanges[newRanges.length - 1];
- modifyEnd = getRangeIndex(end, modifyStart - 1, rangeCount);
- insert = modifyStart == modifyEnd && ranges[modifyStart] >= end;
- }
- if (insert) {
- addMerge(newRanges, newStyles, newRanges.length, modifyStart, modifyStart);
- return;
- }
- modifyEnd = modifyStart;
- int[] mergeRanges = new int[6];
- StyleRange[] mergeStyles = new StyleRange[3];
- for (int i = 0; i < newRanges.length; i += 2) {
- int newStart = newRanges[i];
- int newEnd = newStart + newRanges[i + 1];
- if (newStart == newEnd) continue;
- int modifyLast = 0, mergeCount = 0;
- while (modifyEnd < rangeCount) {
- if (newStart >= ranges[modifyStart] + ranges[modifyStart + 1]) modifyStart += 2;
- if (ranges[modifyEnd] + ranges[modifyEnd + 1] > newEnd) break;
- modifyEnd += 2;
- }
- if (ranges[modifyStart] < newStart && newStart < ranges[modifyStart] + ranges[modifyStart + 1]) {
- mergeStyles[mergeCount >> 1] = styles[modifyStart >> 1];
- mergeRanges[mergeCount] = ranges[modifyStart];
- mergeRanges[mergeCount + 1] = newStart - ranges[modifyStart];
- mergeCount += 2;
- }
- mergeStyles[mergeCount >> 1] = newStyles[i >> 1];
- mergeRanges[mergeCount] = newStart;
- mergeRanges[mergeCount + 1] = newRanges[i + 1];
- mergeCount += 2;
- if (modifyEnd < rangeCount && ranges[modifyEnd] < newEnd && newEnd < ranges[modifyEnd] + ranges[modifyEnd + 1]) {
- mergeStyles[mergeCount >> 1] = styles[modifyEnd >> 1];
- mergeRanges[mergeCount] = newEnd;
- mergeRanges[mergeCount + 1] = ranges[modifyEnd] + ranges[modifyEnd + 1] - newEnd;
- mergeCount += 2;
- modifyLast = 2;
- }
- int grow = addMerge(mergeRanges, mergeStyles, mergeCount, modifyStart, modifyEnd + modifyLast);
- rangeCount += grow;
- modifyStart = modifyEnd += grow;
- }
- } else {
- int start = newStyles[0].start;
- int modifyStart = getRangeIndex(start, -1, styleCount), modifyEnd;
- boolean insert = modifyStart == styleCount;
- if (!insert) {
- int end = newStyles[newStyles.length - 1].start + newStyles[newStyles.length - 1].length;
- modifyEnd = getRangeIndex(end, modifyStart - 1, styleCount);
- insert = modifyStart == modifyEnd && styles[modifyStart].start >= end;
- }
- if (insert) {
- addMerge(newStyles, newStyles.length, modifyStart, modifyStart);
- return;
- }
- modifyEnd = modifyStart;
- StyleRange[] mergeStyles = new StyleRange[3];
- for (int i = 0; i < newStyles.length; i++) {
- StyleRange newStyle = newStyles[i], style;
- int newStart = newStyle.start;
- int newEnd = newStart + newStyle.length;
- if (newStart == newEnd) continue;
- int modifyLast = 0, mergeCount = 0;
- while (modifyEnd < styleCount) {
- if (newStart >= styles[modifyStart].start + styles[modifyStart].length) modifyStart++;
- if (styles[modifyEnd].start + styles[modifyEnd].length > newEnd) break;
- modifyEnd++;
- }
- style = styles[modifyStart];
- if (style.start < newStart && newStart < style.start + style.length) {
- style = mergeStyles[mergeCount++] = (StyleRange)style.clone();
- style.length = newStart - style.start;
- }
- mergeStyles[mergeCount++] = newStyle;
- if (modifyEnd < styleCount) {
- style = styles[modifyEnd];
- if (style.start < newEnd && newEnd < style.start + style.length) {
- style = mergeStyles[mergeCount++] = (StyleRange)style.clone();
- style.length += style.start - newEnd;
- style.start = newEnd;
- modifyLast = 1;
- }
- }
- int grow = addMerge(mergeStyles, mergeCount, modifyStart, modifyEnd + modifyLast);
- modifyStart = modifyEnd += grow;
- }
- }
-}
-void textChanging(TextChangingEvent event) {
- int start = event.start;
- int newCharCount = event.newCharCount, replaceCharCount = event.replaceCharCount;
- int newLineCount = event.newLineCount, replaceLineCount = event.replaceLineCount;
-
- updateRanges(start, replaceCharCount, newCharCount);
-
- int startLine = content.getLineAtOffset(start);
- if (replaceCharCount == content.getCharCount()) lines = null;
- if (replaceLineCount == lineCount) {
- lineCount = newLineCount;
- lineWidth = new int[lineCount];
- lineHeight = new int[lineCount];
- reset(0, lineCount);
- } else {
- int delta = newLineCount - replaceLineCount;
- if (lineCount + delta > lineWidth.length) {
- int[] newWidths = new int[lineCount + delta + GROW];
- System.arraycopy(lineWidth, 0, newWidths, 0, lineCount);
- lineWidth = newWidths;
- int[] newHeights = new int[lineCount + delta + GROW];
- System.arraycopy(lineHeight, 0, newHeights, 0, lineCount);
- lineHeight = newHeights;
- }
- if (lines != null) {
- if (lineCount + delta > lines.length) {
- LineInfo[] newLines = new LineInfo[lineCount + delta + GROW];
- System.arraycopy(lines, 0, newLines, 0, lineCount);
- lines = newLines;
- }
- }
- int startIndex = startLine + replaceLineCount + 1;
- int endIndex = startLine + newLineCount + 1;
- System.arraycopy(lineWidth, startIndex, lineWidth, endIndex, lineCount - startIndex);
- System.arraycopy(lineHeight, startIndex, lineHeight, endIndex, lineCount - startIndex);
- for (int i = startLine; i < endIndex; i++) {
- lineWidth[i] = lineHeight[i] = -1;
- }
- for (int i = lineCount + delta; i < lineCount; i++) {
- lineWidth[i] = lineHeight[i] = -1;
- }
- if (layouts != null) {
- int layoutStartLine = startLine - topIndex;
- int layoutEndLine = layoutStartLine + replaceLineCount + 1;
- for (int i = layoutStartLine; i < layoutEndLine; i++) {
- if (0 <= i && i < layouts.length) {
- if (layouts[i] != null) layouts[i].dispose();
- layouts[i] = null;
- if (bullets != null && bulletsIndices != null) bullets[i] = null;
- }
- }
- if (delta > 0) {
- for (int i = layouts.length - 1; i >= layoutEndLine; i--) {
- if (0 <= i && i < layouts.length) {
- endIndex = i + delta;
- if (0 <= endIndex && endIndex < layouts.length) {
- layouts[endIndex] = layouts[i];
- layouts[i] = null;
- if (bullets != null && bulletsIndices != null) {
- bullets[endIndex] = bullets[i];
- bulletsIndices[endIndex] = bulletsIndices[i];
- bullets[i] = null;
- }
- } else {
- if (layouts[i] != null) layouts[i].dispose();
- layouts[i] = null;
- if (bullets != null && bulletsIndices != null) bullets[i] = null;
- }
- }
- }
- } else if (delta < 0) {
- for (int i = layoutEndLine; i < layouts.length; i++) {
- if (0 <= i && i < layouts.length) {
- endIndex = i + delta;
- if (0 <= endIndex && endIndex < layouts.length) {
- layouts[endIndex] = layouts[i];
- layouts[i] = null;
- if (bullets != null && bulletsIndices != null) {
- bullets[endIndex] = bullets[i];
- bulletsIndices[endIndex] = bulletsIndices[i];
- bullets[i] = null;
- }
- } else {
- if (layouts[i] != null) layouts[i].dispose();
- layouts[i] = null;
- if (bullets != null && bulletsIndices != null) bullets[i] = null;
- }
- }
- }
- }
- }
- if (replaceLineCount != 0 || newLineCount != 0) {
- int startLineOffset = content.getOffsetAtLine(startLine);
- if (startLineOffset != start) startLine++;
- updateBullets(startLine, replaceLineCount, newLineCount, true);
- if (lines != null) {
- startIndex = startLine + replaceLineCount;
- endIndex = startLine + newLineCount;
- System.arraycopy(lines, startIndex, lines, endIndex, lineCount - startIndex);
- for (int i = startLine; i < endIndex; i++) {
- lines[i] = null;
- }
- for (int i = lineCount + delta; i < lineCount; i++) {
- lines[i] = null;
- }
- }
- }
- lineCount += delta;
- if (maxWidthLineIndex != -1 && startLine <= maxWidthLineIndex && maxWidthLineIndex <= startLine + replaceLineCount) {
- maxWidth = 0;
- maxWidthLineIndex = -1;
- for (int i = 0; i < lineCount; i++) {
- if (lineWidth[i] > maxWidth) {
- maxWidth = lineWidth[i];
- maxWidthLineIndex = i;
- }
- }
- }
- }
-}
-void updateBullets(int startLine, int replaceLineCount, int newLineCount, boolean update) {
- if (bullets == null) return;
- if (bulletsIndices != null) return;
- for (int i = 0; i < bullets.length; i++) {
- Bullet bullet = bullets[i];
- int[] lines = bullet.removeIndices(startLine, replaceLineCount, newLineCount, update);
- if (lines != null) {
- if (redrawLines == null) {
- redrawLines = lines;
- } else {
- int[] newRedrawBullets = new int[redrawLines.length + lines.length];
- System.arraycopy(redrawLines, 0, newRedrawBullets, 0, redrawLines.length);
- System.arraycopy(lines, 0, newRedrawBullets, redrawLines.length, lines.length);
- redrawLines = newRedrawBullets;
- }
- }
- }
- int removed = 0;
- for (int i = 0; i < bullets.length; i++) {
- if (bullets[i].size() == 0) removed++;
- }
- if (removed > 0) {
- if (removed == bullets.length) {
- bullets = null;
- } else {
- Bullet[] newBulletsList = new Bullet[bullets.length - removed];
- for (int i = 0, j = 0; i < bullets.length; i++) {
- Bullet bullet = bullets[i];
- if (bullet.size() > 0) newBulletsList[j++] = bullet;
- }
- bullets = newBulletsList;
- }
- }
-}
-void updateRanges(int start, int replaceCharCount, int newCharCount) {
- if (styleCount == 0 || (replaceCharCount == 0 && newCharCount == 0)) return;
- if (ranges != null) {
- int rangeCount = styleCount << 1;
- int modifyStart = getRangeIndex(start, -1, rangeCount);
- if (modifyStart == rangeCount) return;
- int end = start + replaceCharCount;
- int modifyEnd = getRangeIndex(end, modifyStart - 1, rangeCount);
- int offset = newCharCount - replaceCharCount;
- if (modifyStart == modifyEnd && ranges[modifyStart] < start && end < ranges[modifyEnd] + ranges[modifyEnd + 1]) {
- if (newCharCount == 0) {
- ranges[modifyStart + 1] -= replaceCharCount;
- modifyEnd += 2;
- } else {
- if (rangeCount + 2 > ranges.length) {
- int[] newRanges = new int[ranges.length + (GROW << 1)];
- System.arraycopy(ranges, 0, newRanges, 0, rangeCount);
- ranges = newRanges;
- StyleRange[] newStyles = new StyleRange[styles.length + GROW];
- System.arraycopy(styles, 0, newStyles, 0, styleCount);
- styles = newStyles;
- }
- System.arraycopy(ranges, modifyStart + 2, ranges, modifyStart + 4, rangeCount - (modifyStart + 2));
- System.arraycopy(styles, (modifyStart + 2) >> 1, styles, (modifyStart + 4) >> 1, styleCount - ((modifyStart + 2) >> 1));
- ranges[modifyStart + 3] = ranges[modifyStart] + ranges[modifyStart + 1] - end;
- ranges[modifyStart + 2] = start + newCharCount;
- ranges[modifyStart + 1] = start - ranges[modifyStart];
- styles[(modifyStart >> 1) + 1] = styles[modifyStart >> 1];
- rangeCount += 2;
- styleCount++;
- modifyEnd += 4;
- }
- if (offset != 0) {
- for (int i = modifyEnd; i < rangeCount; i += 2) {
- ranges[i] += offset;
- }
- }
- } else {
- if (ranges[modifyStart] < start && start < ranges[modifyStart] + ranges[modifyStart + 1]) {
- ranges[modifyStart + 1] = start - ranges[modifyStart];
- modifyStart += 2;
- }
- if (modifyEnd < rangeCount && ranges[modifyEnd] < end && end < ranges[modifyEnd] + ranges[modifyEnd + 1]) {
- ranges[modifyEnd + 1] = ranges[modifyEnd] + ranges[modifyEnd + 1] - end;
- ranges[modifyEnd] = end;
- }
- if (offset != 0) {
- for (int i = modifyEnd; i < rangeCount; i += 2) {
- ranges[i] += offset;
- }
- }
- System.arraycopy(ranges, modifyEnd, ranges, modifyStart, rangeCount - modifyEnd);
- System.arraycopy(styles, modifyEnd >> 1, styles, modifyStart >> 1, styleCount - (modifyEnd >> 1));
- styleCount -= (modifyEnd - modifyStart) >> 1;
- }
- } else {
- int modifyStart = getRangeIndex(start, -1, styleCount);
- if (modifyStart == styleCount) return;
- int end = start + replaceCharCount;
- int modifyEnd = getRangeIndex(end, modifyStart - 1, styleCount);
- int offset = newCharCount - replaceCharCount;
- if (modifyStart == modifyEnd && styles[modifyStart].start < start && end < styles[modifyEnd].start + styles[modifyEnd].length) {
- if (newCharCount == 0) {
- styles[modifyStart].length -= replaceCharCount;
- modifyEnd++;
- } else {
- if (styleCount + 1 > styles.length) {
- StyleRange[] newStyles = new StyleRange[styles.length + GROW];
- System.arraycopy(styles, 0, newStyles, 0, styleCount);
- styles = newStyles;
- }
- System.arraycopy(styles, modifyStart + 1, styles, modifyStart + 2, styleCount - (modifyStart + 1));
- styles[modifyStart + 1] = (StyleRange)styles[modifyStart].clone();
- styles[modifyStart + 1].length = styles[modifyStart].start + styles[modifyStart].length - end;
- styles[modifyStart + 1].start = start + newCharCount;
- styles[modifyStart].length = start - styles[modifyStart].start;
- styleCount++;
- modifyEnd += 2;
- }
- if (offset != 0) {
- for (int i = modifyEnd; i < styleCount; i++) {
- styles[i].start += offset;
- }
- }
- } else {
- if (styles[modifyStart].start < start && start < styles[modifyStart].start + styles[modifyStart].length) {
- styles[modifyStart].length = start - styles[modifyStart].start;
- modifyStart++;
- }
- if (modifyEnd < styleCount && styles[modifyEnd].start < end && end < styles[modifyEnd].start + styles[modifyEnd].length) {
- styles[modifyEnd].length = styles[modifyEnd].start + styles[modifyEnd].length - end;
- styles[modifyEnd].start = end;
- }
- if (offset != 0) {
- for (int i = modifyEnd; i < styleCount; i++) {
- styles[i].start += offset;
- }
- }
- System.arraycopy(styles, modifyEnd, styles, modifyStart, styleCount - modifyEnd);
- styleCount -= modifyEnd - modifyStart;
- }
- }
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/TableCursor.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/TableCursor.java
deleted file mode 100644
index 0408aa5fd7..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/TableCursor.java
+++ /dev/null
@@ -1,778 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.custom;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.widgets.*;
-import org.eclipse.swt.accessibility.*;
-import org.eclipse.swt.events.*;
-
-/**
- * A TableCursor provides a way for the user to navigate around a Table
- * using the keyboard. It also provides a mechanism for selecting an
- * individual cell in a table.
- *
- *
Here is an example of using a TableCursor to navigate to a cell and then edit it.
- *
- *
- *
- *
- * public static void main(String[] args) {
- * Display display = new Display();
- * Shell shell = new Shell(display);
- * shell.setLayout(new GridLayout());
- *
- * // create a a table with 3 columns and fill with data
- * final Table table = new Table(shell, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
- * table.setLayoutData(new GridData(GridData.FILL_BOTH));
- * TableColumn column1 = new TableColumn(table, SWT.NONE);
- * TableColumn column2 = new TableColumn(table, SWT.NONE);
- * TableColumn column3 = new TableColumn(table, SWT.NONE);
- * for (int i = 0; i < 100; i++) {
- * TableItem item = new TableItem(table, SWT.NONE);
- * item.setText(new String[] { "cell "+i+" 0", "cell "+i+" 1", "cell "+i+" 2"});
- * }
- * column1.pack();
- * column2.pack();
- * column3.pack();
- *
- * // create a TableCursor to navigate around the table
- * final TableCursor cursor = new TableCursor(table, SWT.NONE);
- * // create an editor to edit the cell when the user hits "ENTER"
- * // while over a cell in the table
- * final ControlEditor editor = new ControlEditor(cursor);
- * editor.grabHorizontal = true;
- * editor.grabVertical = true;
- *
- * cursor.addSelectionListener(new SelectionAdapter() {
- * // when the TableEditor is over a cell, select the corresponding row in
- * // the table
- * public void widgetSelected(SelectionEvent e) {
- * table.setSelection(new TableItem[] {cursor.getRow()});
- * }
- * // when the user hits "ENTER" in the TableCursor, pop up a text editor so that
- * // they can change the text of the cell
- * public void widgetDefaultSelected(SelectionEvent e){
- * final Text text = new Text(cursor, SWT.NONE);
- * TableItem row = cursor.getRow();
- * int column = cursor.getColumn();
- * text.setText(row.getText(column));
- * text.addKeyListener(new KeyAdapter() {
- * public void keyPressed(KeyEvent e) {
- * // close the text editor and copy the data over
- * // when the user hits "ENTER"
- * if (e.character == SWT.CR) {
- * TableItem row = cursor.getRow();
- * int column = cursor.getColumn();
- * row.setText(column, text.getText());
- * text.dispose();
- * }
- * // close the text editor when the user hits "ESC"
- * if (e.character == SWT.ESC) {
- * text.dispose();
- * }
- * }
- * });
- * editor.setEditor(text);
- * text.setFocus();
- * }
- * });
- * // Hide the TableCursor when the user hits the "MOD1" or "MOD2" key.
- * // This allows the user to select multiple items in the table.
- * cursor.addKeyListener(new KeyAdapter() {
- * public void keyPressed(KeyEvent e) {
- * if (e.keyCode == SWT.MOD1 ||
- * e.keyCode == SWT.MOD2 ||
- * (e.stateMask & SWT.MOD1) != 0 ||
- * (e.stateMask & SWT.MOD2) != 0) {
- * cursor.setVisible(false);
- * }
- * }
- * });
- * // Show the TableCursor when the user releases the "MOD2" or "MOD1" key.
- * // This signals the end of the multiple selection task.
- * table.addKeyListener(new KeyAdapter() {
- * public void keyReleased(KeyEvent e) {
- * if (e.keyCode == SWT.MOD1 && (e.stateMask & SWT.MOD2) != 0) return;
- * if (e.keyCode == SWT.MOD2 && (e.stateMask & SWT.MOD1) != 0) return;
- * if (e.keyCode != SWT.MOD1 && (e.stateMask & SWT.MOD1) != 0) return;
- * if (e.keyCode != SWT.MOD2 && (e.stateMask & SWT.MOD2) != 0) return;
- *
- * TableItem[] selection = table.getSelection();
- * TableItem row = (selection.length == 0) ? table.getItem(table.getTopIndex()) : selection[0];
- * table.showItem(row);
- * cursor.setSelection(row, 0);
- * cursor.setVisible(true);
- * cursor.setFocus();
- * }
- * });
- *
- * shell.open();
- * while (!shell.isDisposed()) {
- * if (!display.readAndDispatch())
- * display.sleep();
- * }
- * display.dispose();
- * }
- *
- * The style value is either one of the style constants defined in
- * class SWT
which is applicable to instances of this
- * class, or must be built by bitwise OR'ing together
- * (that is, using the int
"|" operator) two or more
- * of those SWT
style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- *
SelectionListener
- * interface.
- *
- * When widgetSelected
is called, the item field of the event object is valid.
- * If the receiver has SWT.CHECK
style set and the check selection changes,
- * the event object detail field contains the value SWT.CHECK
.
- * widgetDefaultSelected
is typically called when an item is double-clicked.
- *
- * Note: This operation is a hint and may be overridden by the platform. - * For example, on Windows the background of a Button cannot be changed. - *
- * @param color the new color (or null) - * - * @exception IllegalArgumentException- * Note: This operation is a hint and may be overridden by the platform. - *
- * @param color the new color (or null) - * - * @exception IllegalArgumentException Here is an example of using a TableEditor:
-*
-*
-* @see TableEditor snippets
-* @see Sample code and further information
-*/
-public class TableEditor extends ControlEditor {
- Table table;
- TableItem item;
- int column = -1;
- ControlListener columnListener;
- Runnable timer;
- static final int TIMEOUT = 1500;
-/**
-* Creates a TableEditor for the specified Table.
-*
-* @param table the Table Control above which this editor will be displayed
-*
-*/
-public TableEditor (Table table) {
- super(table);
- this.table = table;
-
- columnListener = new ControlListener() {
- public void controlMoved(ControlEvent e){
- layout ();
- }
- public void controlResized(ControlEvent e){
- layout ();
- }
- };
- timer = new Runnable () {
- public void run() {
- layout ();
- }
- };
-
- // To be consistent with older versions of SWT, grabVertical defaults to true
- grabVertical = true;
-}
-Rectangle computeBounds () {
- if (item == null || column == -1 || item.isDisposed()) return new Rectangle(0, 0, 0, 0);
- Rectangle cell = item.getBounds(column);
- Rectangle rect = item.getImageBounds(column);
- cell.x = rect.x + rect.width;
- cell.width -= rect.width;
- Rectangle area = table.getClientArea();
- if (cell.x < area.x + area.width) {
- if (cell.x + cell.width > area.x + area.width) {
- cell.width = area.x + area.width - cell.x;
- }
- }
- Rectangle editorRect = new Rectangle(cell.x, cell.y, minimumWidth, minimumHeight);
-
- if (grabHorizontal) {
- editorRect.width = Math.max(cell.width, minimumWidth);
- }
-
- if (grabVertical) {
- editorRect.height = Math.max(cell.height, minimumHeight);
- }
-
- if (horizontalAlignment == SWT.RIGHT) {
- editorRect.x += cell.width - editorRect.width;
- } else if (horizontalAlignment == SWT.LEFT) {
- // do nothing - cell.x is the right answer
- } else { // default is CENTER
- editorRect.x += (cell.width - editorRect.width)/2;
- }
-
- if (verticalAlignment == SWT.BOTTOM) {
- editorRect.y += cell.height - editorRect.height;
- } else if (verticalAlignment == SWT.TOP) {
- // do nothing - cell.y is the right answer
- } else { // default is CENTER
- editorRect.y += (cell.height - editorRect.height)/2;
- }
- return editorRect;
-}
-/**
- * Removes all associations between the TableEditor and the cell in the table. The
- * Table and the editor Control are not disposed.
- */
-public void dispose () {
- if (table != null && !table.isDisposed()) {
- if (this.column > -1 && this.column < table.getColumnCount()){
- TableColumn tableColumn = table.getColumn(this.column);
- tableColumn.removeControlListener(columnListener);
- }
- }
- columnListener = null;
- table = null;
- item = null;
- column = -1;
- timer = null;
- super.dispose();
-}
-/**
-* Returns the zero based index of the column of the cell being tracked by this editor.
-*
-* @return the zero based index of the column of the cell being tracked by this editor
-*/
-public int getColumn () {
- return column;
-}
-/**
-* Returns the TableItem for the row of the cell being tracked by this editor.
-*
-* @return the TableItem for the row of the cell being tracked by this editor
-*/
-public TableItem getItem () {
- return item;
-}
-void resize () {
- layout();
- /*
- * On some platforms, the table scrolls when an item that
- * is partially visible at the bottom of the table is
- * selected. Ensure that the correct row is edited by
- * laying out one more time in a timerExec().
- */
- if (table != null) {
- Display display = table.getDisplay();
- display.timerExec(-1, timer);
- display.timerExec(TIMEOUT, timer);
- }
-}
-/**
-* Sets the zero based index of the column of the cell being tracked by this editor.
-*
-* @param column the zero based index of the column of the cell being tracked by this editor
-*/
-public void setColumn(int column) {
- int columnCount = table.getColumnCount();
- // Separately handle the case where the table has no TableColumns.
- // In this situation, there is a single default column.
- if (columnCount == 0) {
- this.column = (column == 0) ? 0 : -1;
- resize();
- return;
- }
- if (this.column > -1 && this.column < columnCount){
- TableColumn tableColumn = table.getColumn(this.column);
- tableColumn.removeControlListener(columnListener);
- this.column = -1;
- }
-
- if (column < 0 || column >= table.getColumnCount()) return;
-
- this.column = column;
- TableColumn tableColumn = table.getColumn(this.column);
- tableColumn.addControlListener(columnListener);
- resize();
-}
-/**
-* Specifies the
-* final Table table = new Table(shell, SWT.FULL_SELECTION | SWT.HIDE_SELECTION);
-* TableColumn column1 = new TableColumn(table, SWT.NONE);
-* TableColumn column2 = new TableColumn(table, SWT.NONE);
-* for (int i = 0; i < 10; i++) {
-* TableItem item = new TableItem(table, SWT.NONE);
-* item.setText(new String[] {"item " + i, "edit this value"});
-* }
-* column1.pack();
-* column2.pack();
-*
-* final TableEditor editor = new TableEditor(table);
-* //The editor must have the same size as the cell and must
-* //not be any smaller than 50 pixels.
-* editor.horizontalAlignment = SWT.LEFT;
-* editor.grabHorizontal = true;
-* editor.minimumWidth = 50;
-* // editing the second column
-* final int EDITABLECOLUMN = 1;
-*
-* table.addSelectionListener(new SelectionAdapter() {
-* public void widgetSelected(SelectionEvent e) {
-* // Clean up any previous editor control
-* Control oldEditor = editor.getEditor();
-* if (oldEditor != null) oldEditor.dispose();
-*
-* // Identify the selected row
-* TableItem item = (TableItem)e.item;
-* if (item == null) return;
-*
-* // The control that will be the editor must be a child of the Table
-* Text newEditor = new Text(table, SWT.NONE);
-* newEditor.setText(item.getText(EDITABLECOLUMN));
-* newEditor.addModifyListener(new ModifyListener() {
-* public void modifyText(ModifyEvent e) {
-* Text text = (Text)editor.getEditor();
-* editor.getItem().setText(EDITABLECOLUMN, text.getText());
-* }
-* });
-* newEditor.selectAll();
-* newEditor.setFocus();
-* editor.setEditor(newEditor, item, EDITABLECOLUMN);
-* }
-* });
-*
TableItem
that is to be edited.
-*
-* @param item the item to be edited
-*/
-public void setItem (TableItem item) {
- this.item = item;
- resize();
-}
-public void setEditor (Control editor) {
- super.setEditor(editor);
- resize();
-}
-/**
-* Specify the Control that is to be displayed and the cell in the table that it is to be positioned above.
-*
-*
Note: The Control provided as the editor must be created with its parent being the Table control -* specified in the TableEditor constructor. -* -* @param editor the Control that is displayed above the cell being edited -* @param item the TableItem for the row of the cell being tracked by this editor -* @param column the zero based index of the column of the cell being tracked by this editor -*/ -public void setEditor (Control editor, TableItem item, int column) { - setItem(item); - setColumn(column); - setEditor(editor); -} -public void layout () { - if (table == null || table.isDisposed()) return; - if (item == null || item.isDisposed()) return; - int columnCount = table.getColumnCount(); - if (columnCount == 0 && column != 0) return; - if (columnCount > 0 && (column < 0 || column >= columnCount)) return; - super.layout(); -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/TableTree.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/TableTree.java deleted file mode 100755 index 4ac4da4a09..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/TableTree.java +++ /dev/null @@ -1,818 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.custom; - - -import org.eclipse.swt.*; -import org.eclipse.swt.events.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.widgets.*; - -/** - * A TableTree is a selectable user interface object - * that displays a hierarchy of items, and issues - * notification when an item is selected. - * A TableTree may be single or multi select. - *
- * The item children that may be added to instances of this class
- * must be of type TableTreeItem
.
- *
- * Note that although this class is a subclass of Composite
,
- * it does not make sense to add Control
children to it,
- * or set a layout on it.
- *
- *
- * Note: Only one of the styles SINGLE, and MULTI may be specified. - *
- * - * @deprecated As of 3.1 use Tree, TreeItem and TreeColumn - */ -public class TableTree extends Composite { - Table table; - TableTreeItem[] items = EMPTY_ITEMS; - Image plusImage, minusImage, sizeImage; - Listener listener; - - /* - * TableTreeItems are not treated as children but rather as items. - * When the TableTree is disposed, all children are disposed because - * TableTree inherits this behaviour from Composite. The items - * must be disposed separately. Because TableTree is not part of - * the org.eclipse.swt.widgets package, the method releaseWidget can - * not be overridden (this is how items are disposed of in Table and Tree). - * Instead, the items are disposed of in response to the dispose event on the - * TableTree. The "inDispose" flag is used to distinguish between disposing - * one TableTreeItem (e.g. when removing an entry from the TableTree) and - * disposing the entire TableTree. - */ - boolean inDispose = false; - - static final TableTreeItem[] EMPTY_ITEMS = new TableTreeItem [0]; - static final String[] EMPTY_TEXTS = new String [0]; - static final Image[] EMPTY_IMAGES = new Image [0]; - static final String ITEMID = "TableTreeItemID"; //$NON-NLS-1$ - -/** - * Constructs a new instance of this class given its parent - * and a style value describing its behavior and appearance. - *
- * The style value is either one of the style constants defined in
- * class SWT
which is applicable to instances of this
- * class, or must be built by bitwise OR'ing together
- * (that is, using the int
"|" operator) two or more
- * of those SWT
style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- *
SelectionListener
- * interface.
- *
- * When widgetSelected
is called, the item field of the event object is valid.
- * If the receiver has SWT.CHECK
style set and the check selection changes,
- * the event object detail field contains the value SWT.CHECK
.
- * widgetDefaultSelected
is typically called when an item is double-clicked.
- * The item field of the event object is valid for default selection, but the detail field is not used.
- *
TreeListener
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException - * If an item is selected, it is deselected. - * If an item is not selected, it remains unselected. - * - * @exception SWTException
- * @return the number of items in the widget - */ -public int getItemCount () { - //checkWidget(); - return items.length; -} - -/** - * Gets the height of one item. - *
- * This operation will fail if the height of - * one item could not be queried from the OS. - * - * @return the height of one item in the widget - * - * @exception SWTException
- * @return the items in the widget - */ -public TableTreeItem [] getItems () { - //checkWidget(); - TableTreeItem[] newItems = new TableTreeItem[items.length]; - System.arraycopy(items, 0, newItems, 0, items.length); - return newItems; -} - -/** - * Gets the selected items. - *
- * This operation will fail if the selected - * items cannot be queried from the OS. - * - * @return the selected items in the widget - * - * @exception SWTException
- * This operation will fail if the number of selected - * items cannot be queried from the OS. - * - * @return the number of selected items in the widget - * - * @exception SWTException
The widget is searched starting at 0 until an - * item is found that is equal to the search item. - * If no item is found, -1 is returned. Indexing - * is zero based. This index is relative to the parent only. - * - * @param item the search item - * @return the index of the item or -1 - */ -public int indexOf (TableTreeItem item) { - //checkWidget(); - for (int i = 0; i < items.length; i++) { - if (item == items[i]) return i; - } - return -1; -} - -void onDispose(Event e) { - removeListener(SWT.Dispose, listener); - notifyListeners(SWT.Dispose, e); - e.type = SWT.None; - /* - * Usually when an item is disposed, destroyItem will change the size of the items array - * and dispose of the underlying table items. - * Since the whole table tree is being disposed, this is not necessary. For speed - * the inDispose flag is used to skip over this part of the item dispose. - */ - inDispose = true; - for (int i = 0; i < items.length; i++) { - items[i].dispose(); - } - inDispose = false; - if (plusImage != null) plusImage.dispose(); - if (minusImage != null) minusImage.dispose(); - if (sizeImage != null) sizeImage.dispose(); - plusImage = minusImage = sizeImage = null; -} - -void onResize(Event e) { - Point size = getSize(); - table.setBounds(0, 0, size.x, size.y); -} - -void onSelection(Event e) { - Event event = new Event(); - TableItem tableItem = (TableItem)e.item; - TableTreeItem item = getItem(tableItem); - event.item = item; - - if (e.type == SWT.Selection && e.detail == SWT.CHECK && item != null) { - event.detail = SWT.CHECK; - item.checked = tableItem.getChecked(); - } - notifyListeners(e.type, event); -} -/** - * 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
- * This operation will fail when an item - * could not be removed in the OS. - * - * @exception SWTException
- * If the receiver is single-select, do nothing. - * - * @exception SWTException
- * Items that are not in the receiver are ignored. - * If the receiver is single-select and multiple items are specified, - * then all items are ignored. - * - * @param items the array of items - * - * @exception IllegalArgumentException
- * If there is no selection or the selection - * is already visible, this method does nothing. - * If the selection is scrolled out of view, - * the top index of the widget is changed such - * that selection becomes visible. - * - * @exception SWTException
Here is an example of using a TableTreeEditor:
-*
-*
-* @deprecated As of 3.1 use TreeEditor with Tree, TreeItem and TreeColumn
-*/
-public class TableTreeEditor extends ControlEditor {
-
- TableTree tableTree;
- TableTreeItem item;
- int column = -1;
- ControlListener columnListener;
- TreeListener treeListener;
-/**
-* Creates a TableTreeEditor for the specified TableTree.
-*
-* @param tableTree the TableTree Control above which this editor will be displayed
-*
-*/
-public TableTreeEditor (TableTree tableTree) {
- super(tableTree.getTable());
- this.tableTree = tableTree;
-
- treeListener = new TreeListener () {
- final Runnable runnable = new Runnable() {
- public void run() {
- if (editor == null || editor.isDisposed()) return;
- if (TableTreeEditor.this.tableTree.isDisposed()) return;
- layout();
- editor.setVisible(true);
- }
- };
- public void treeCollapsed(TreeEvent e) {
- if (editor == null || editor.isDisposed ()) return;
- editor.setVisible(false);
- e.display.asyncExec(runnable);
- }
- public void treeExpanded(TreeEvent e) {
- if (editor == null || editor.isDisposed ()) return;
- editor.setVisible(false);
- e.display.asyncExec(runnable);
- }
- };
- tableTree.addTreeListener(treeListener);
-
- columnListener = new ControlListener() {
- public void controlMoved(ControlEvent e){
- layout ();
- }
- public void controlResized(ControlEvent e){
- layout ();
- }
- };
-
- // To be consistent with older versions of SWT, grabVertical defaults to true
- grabVertical = true;
-}
-Rectangle computeBounds () {
- if (item == null || column == -1 || item.isDisposed() || item.tableItem == null) return new Rectangle(0, 0, 0, 0);
- Rectangle cell = item.getBounds(column);
- Rectangle area = tableTree.getClientArea();
- if (cell.x < area.x + area.width) {
- if (cell.x + cell.width > area.x + area.width) {
- cell.width = area.x + area.width - cell.x;
- }
- }
- Rectangle editorRect = new Rectangle(cell.x, cell.y, minimumWidth, minimumHeight);
-
- if (grabHorizontal) {
- editorRect.width = Math.max(cell.width, minimumWidth);
- }
-
- if (grabVertical) {
- editorRect.height = Math.max(cell.height, minimumHeight);
- }
-
- if (horizontalAlignment == SWT.RIGHT) {
- editorRect.x += cell.width - editorRect.width;
- } else if (horizontalAlignment == SWT.LEFT) {
- // do nothing - cell.x is the right answer
- } else { // default is CENTER
- editorRect.x += (cell.width - editorRect.width)/2;
- }
-
- if (verticalAlignment == SWT.BOTTOM) {
- editorRect.y += cell.height - editorRect.height;
- } else if (verticalAlignment == SWT.TOP) {
- // do nothing - cell.y is the right answer
- } else { // default is CENTER
- editorRect.y += (cell.height - editorRect.height)/2;
- }
- return editorRect;
-}
-/**
- * Removes all associations between the TableTreeEditor and the cell in the table tree. The
- * TableTree and the editor Control are not disposed.
- */
-public void dispose () {
- if (tableTree != null && !tableTree.isDisposed()) {
- Table table = tableTree.getTable();
- if (table != null && !table.isDisposed()) {
- if (this.column > -1 && this.column < table.getColumnCount()){
- TableColumn tableColumn = table.getColumn(this.column);
- tableColumn.removeControlListener(columnListener);
- }
- }
- if (treeListener != null) tableTree.removeTreeListener(treeListener);
- }
- treeListener = null;
- columnListener = null;
- tableTree = null;
- item = null;
- column = -1;
- super.dispose();
-}
-/**
-* Returns the zero based index of the column of the cell being tracked by this editor.
-*
-* @return the zero based index of the column of the cell being tracked by this editor
-*/
-public int getColumn () {
- return column;
-}
-/**
-* Returns the TableTreeItem for the row of the cell being tracked by this editor.
-*
-* @return the TableTreeItem for the row of the cell being tracked by this editor
-*/
-public TableTreeItem getItem () {
- return item;
-}
-public void setColumn(int column) {
- Table table = tableTree.getTable();
- int columnCount = table.getColumnCount();
- // Separately handle the case where the table has no TableColumns.
- // In this situation, there is a single default column.
- if (columnCount == 0) {
- this.column = (column == 0) ? 0 : -1;
- layout();
- return;
- }
- if (this.column > -1 && this.column < columnCount){
- TableColumn tableColumn = table.getColumn(this.column);
- tableColumn.removeControlListener(columnListener);
- this.column = -1;
- }
-
- if (column < 0 || column >= table.getColumnCount()) return;
-
- this.column = column;
- TableColumn tableColumn = table.getColumn(this.column);
- tableColumn.addControlListener(columnListener);
- layout();
-}
-public void setItem (TableTreeItem item) {
- this.item = item;
- layout();
-}
-
-/**
-* Specify the Control that is to be displayed and the cell in the table that it is to be positioned above.
-*
-*
-* final TableTree tableTree = new TableTree(shell, SWT.FULL_SELECTION | SWT.HIDE_SELECTION);
-* final Table table = tableTree.getTable();
-* TableColumn column1 = new TableColumn(table, SWT.NONE);
-* TableColumn column2 = new TableColumn(table, SWT.NONE);
-* for (int i = 0; i < 10; i++) {
-* TableTreeItem item = new TableTreeItem(tableTree, SWT.NONE);
-* item.setText(0, "item " + i);
-* item.setText(1, "edit this value");
-* for (int j = 0; j < 3; j++) {
-* TableTreeItem subitem = new TableTreeItem(item, SWT.NONE);
-* subitem.setText(0, "subitem " + i + " " + j);
-* subitem.setText(1, "edit this value");
-* }
-* }
-* column1.setWidth(100);
-* column2.pack();
-*
-* final TableTreeEditor editor = new TableTreeEditor(tableTree);
-* //The editor must have the same size as the cell and must
-* //not be any smaller than 50 pixels.
-* editor.horizontalAlignment = SWT.LEFT;
-* editor.grabHorizontal = true;
-* editor.minimumWidth = 50;
-* // editing the second column
-* final int EDITABLECOLUMN = 1;
-*
-* tableTree.addSelectionListener(new SelectionAdapter() {
-* public void widgetSelected(SelectionEvent e) {
-* // Clean up any previous editor control
-* Control oldEditor = editor.getEditor();
-* if (oldEditor != null) oldEditor.dispose();
-*
-* // Identify the selected row
-* TableTreeItem item = (TableTreeItem)e.item;
-* if (item == null) return;
-*
-* // The control that will be the editor must be a child of the Table
-* Text newEditor = new Text(table, SWT.NONE);
-* newEditor.setText(item.getText(EDITABLECOLUMN));
-* newEditor.addModifyListener(new ModifyListener() {
-* public void modifyText(ModifyEvent e) {
-* Text text = (Text)editor.getEditor();
-* editor.getItem().setText(EDITABLECOLUMN, text.getText());
-* }
-* });
-* newEditor.selectAll();
-* newEditor.setFocus();
-* editor.setEditor(newEditor, item, EDITABLECOLUMN);
-* }
-* });
-*
Note: The Control provided as the editor must be created with its parent being the Table control
-* specified in the TableEditor constructor.
-*
-* @param editor the Control that is displayed above the cell being edited
-* @param item the TableItem for the row of the cell being tracked by this editor
-* @param column the zero based index of the column of the cell being tracked by this editor
-*/
-public void setEditor (Control editor, TableTreeItem item, int column) {
- setItem(item);
- setColumn(column);
- setEditor(editor);
-}
-public void layout () {
- if (tableTree == null || tableTree.isDisposed()) return;
- if (item == null || item.isDisposed()) return;
- Table table = tableTree.getTable();
- int columnCount = table.getColumnCount();
- if (columnCount == 0 && column != 0) return;
- if (columnCount > 0 && (column < 0 || column >= columnCount)) return;
- super.layout();
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/TableTreeItem.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/TableTreeItem.java
deleted file mode 100755
index 83c2fc8422..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/TableTreeItem.java
+++ /dev/null
@@ -1,876 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.custom;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.widgets.*;
-
-/**
- * A TableTreeItem is a selectable user interface object
- * that represents an item in a hierarchy of items in a
- * TableTree.
- *
- * @deprecated As of 3.1 use Tree, TreeItem and TreeColumn
- */
-public class TableTreeItem extends Item {
- TableItem tableItem;
- TableTree parent;
- TableTreeItem parentItem;
- TableTreeItem [] items = TableTree.EMPTY_ITEMS;
- String[] texts = TableTree.EMPTY_TEXTS;
- Image[] images = TableTree.EMPTY_IMAGES;
- Color background;
- Color foreground;
- Font font;
- boolean expanded;
- boolean checked;
- boolean grayed;
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a TableTree
)
- * and a style value describing its behavior and appearance.
- * The item is added to the end of the items maintained by its parent.
- *
- * The style value is either one of the style constants defined in
- * class SWT
which is applicable to instances of this
- * class, or must be built by bitwise OR'ing together
- * (that is, using the int
"|" operator) two or more
- * of those SWT
style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- *
TableTree
,
- * a style value describing its behavior and appearance, and the index
- * at which to place it in the items maintained by its parent.
- *
- * The style value is either one of the style constants defined in
- * class SWT
which is applicable to instances of this
- * class, or must be built by bitwise OR'ing together
- * (that is, using the int
"|" operator) two or more
- * of those SWT
style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- *
TableTreeItem
)
- * and a style value describing its behavior and appearance.
- * The item is added to the end of the items maintained by its parent.
- *
- * The style value is either one of the style constants defined in
- * class SWT
which is applicable to instances of this
- * class, or must be built by bitwise OR'ing together
- * (that is, using the int
"|" operator) two or more
- * of those SWT
style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- *
TableTreeItem
),
- * a style value describing its behavior and appearance, and the index
- * at which to place it in the items maintained by its parent.
- *
- * The style value is either one of the style constants defined in
- * class SWT
which is applicable to instances of this
- * class, or must be built by bitwise OR'ing together
- * (that is, using the int
"|" operator) two or more
- * of those SWT
style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- *
true
if the receiver is checked,
- * and false otherwise. When the parent does not have
- * the CHECK style, return false.
- *
- * @return the checked state of the checkbox
- *
- * @exception SWTException
- * - ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- * - ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- *
- */
-public boolean getChecked () {
- checkWidget();
- if (tableItem == null) return checked;
- return tableItem.getChecked();
-}
-
-/**
- * Returns true
if the receiver is grayed,
- * and false otherwise. When the parent does not have
- * the CHECK
style, return false.
- *
- * @return the grayed state of the checkbox
- *
- * @exception SWTException
- * - ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- * - ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- *
- *
- * @since 2.1
- */
-public boolean getGrayed () {
- checkWidget();
- if (tableItem == null) return grayed;
- return tableItem.getGrayed();
-}
-
-/**
- * Returns true
if the receiver is expanded,
- * and false otherwise.
- *
- *
- * @return the expanded state
- */
-public boolean getExpanded () {
- //checkWidget();
- return expanded;
-}
-
-/**
- * Returns the font that the receiver will use to paint textual information for this item.
- *
- * @return the receiver's font
- *
- * @exception SWTException
- * - ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- * - ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- *
- *
- * @since 3.0
- */
-public Font getFont () {
- checkWidget ();
- return (font == null) ? parent.getFont() : font;
-}
-/**
- * Returns the foreground color that the receiver will use to draw.
- *
- * @return the receiver's foreground color
- *
- * @exception SWTException
- * - ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- * - ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- *
- *
- * @since 2.0
- *
- */
-public Color getForeground () {
- checkWidget ();
- return (foreground == null) ? parent.getForeground() : foreground;
-}
-/**
- * Gets the first image.
- *
- * The image in column 0 is reserved for the [+] and [-]
- * images of the tree, therefore getImage(0) will return null.
- *
- * @return the image at index 0
- *
- * @exception SWTException
- * - ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- * - ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- *
- */
-public Image getImage () {
- checkWidget();
- return getImage(0);
-}
-
-/**
- * Gets the image at the specified index.
- *
- * Indexing is zero based. The image can be null.
- * The image in column 0 is reserved for the [+] and [-]
- * images of the tree, therefore getImage(0) will return null.
- * Return null if the index is out of range.
- *
- * @param index the index of the image
- * @return the image at the specified index or null
- */
-public Image getImage (int index) {
- //checkWidget();
- if (0 < index && index < images.length) return images[index];
- return null;
-}
-
-int getIndent() {
- if (parentItem == null) return 0;
- return parentItem.getIndent() + 1;
-}
-
-/**
- * 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
- * - ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)
- *
- * @exception SWTException
- * - ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- * - ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- *
- *
- * @since 3.1
- */
-public TableTreeItem getItem (int index) {
- checkWidget();
- int count = items.length;
- if (!(0 <= index && index < count)) SWT.error (SWT.ERROR_INVALID_RANGE);
- return items [index];
-}
-
-/**
- * Returns the number of items contained in the receiver
- * that are direct item children of the receiver.
- *
- * @return the number of items
- */
-public int getItemCount () {
- //checkWidget();
- return items.length;
-}
-
-/**
- * Returns an array of TableTreeItem
s which are the
- * direct item children of the receiver.
- *
- * 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.
- *
- *
- * @return the receiver's items
- */
-public TableTreeItem[] getItems () {
- //checkWidget();
- TableTreeItem[] newItems = new TableTreeItem[items.length];
- System.arraycopy(items, 0, newItems, 0, items.length);
- return newItems;
-}
-
-TableTreeItem getItem(TableItem tableItem) {
- if (tableItem == null) return null;
- if (this.tableItem == tableItem) return this;
- for (int i = 0; i < items.length; i++) {
- TableTreeItem item = items[i].getItem(tableItem);
- if (item != null) return item;
- }
- return null;
-}
-
-/**
- * Returns the receiver's parent, which must be a TableTree
.
- *
- * @return the receiver's parent
- */
-public TableTree getParent () {
- //checkWidget();
- return parent;
-}
-
-/**
- * Returns the receiver's parent item, which must be a
- * TableTreeItem
or null when the receiver is a
- * root.
- *
- * @return the receiver's parent item
- */
-public TableTreeItem getParentItem () {
- //checkWidget();
- return parentItem;
-}
-public String getText () {
- checkWidget();
- return getText(0);
-}
-
-/**
- * Gets the item text at the specified index.
- *
- * Indexing is zero based.
- *
- * This operation will fail when the index is out
- * of range or an item could not be queried from
- * the OS.
- *
- * @param index the index of the item
- * @return the item text at the specified index, which can be null
- */
-public String getText(int index) {
- //checkWidget();
- if (0 <= index && index < texts.length) return texts[index];
- return null;
-}
-
-boolean getVisible () {
- return tableItem != null;
-}
-
-/**
- * Gets the index of the specified item.
- *
- *
The widget is searched starting at 0 until an
- * item is found that is equal to the search item.
- * If no item is found, -1 is returned. Indexing
- * is zero based. This index is relative to the parent only.
- *
- * @param item the search item
- * @return the index of the item or -1 if the item is not found
- *
- */
-public int indexOf (TableTreeItem item) {
- //checkWidget();
- for (int i = 0; i < items.length; i++) {
- if (items[i] == item) return i;
- }
- return -1;
-}
-
-void expandAll(boolean notify) {
- if (items.length == 0) return;
- if (!expanded) {
- setExpanded(true);
- if (notify) {
- Event event = new Event();
- event.item = this;
- parent.notifyListeners(SWT.Expand, event);
- }
- }
- for (int i = 0; i < items.length; i++) {
- items[i].expandAll(notify);
- }
-}
-int expandedIndexOf (TableTreeItem item) {
- int index = 0;
- for (int i = 0; i < items.length; i++) {
- if (items[i] == item) return index;
- if (items[i].expanded) index += items[i].visibleChildrenCount ();
- index++;
- }
- return -1;
-}
-
-int visibleChildrenCount () {
- int count = 0;
- for (int i = 0; i < items.length; i++) {
- if (items[i].getVisible ()) {
- count += 1 + items[i].visibleChildrenCount ();
- }
- }
- return count;
-}
-
-public void dispose () {
- if (isDisposed()) return;
- for (int i = items.length - 1; i >= 0; i--) {
- items[i].dispose();
- }
- super.dispose();
- if (!parent.inDispose) {
- if (parentItem != null) {
- parentItem.removeItem(this);
- } else {
- parent.removeItem(this);
- }
- if (tableItem != null) tableItem.dispose();
- }
- items = null;
- parentItem = null;
- parent = null;
- images = null;
- texts = null;
- tableItem = null;
- foreground = null;
- background = null;
- font = null;
-}
-
-void removeItem(TableTreeItem item) {
- int index = 0;
- while (index < items.length && items[index] != item) index++;
- if (index == items.length) return;
- TableTreeItem[] newItems = new TableTreeItem[items.length - 1];
- System.arraycopy(items, 0, newItems, 0, index);
- System.arraycopy(items, index + 1, newItems, index, items.length - index - 1);
- items = newItems;
- if (items.length == 0) {
- if (tableItem != null) tableItem.setImage(0, null);
- }
-}
-
-/**
- * Sets the receiver's background color to the color specified
- * by the argument, or to the default system color for the item
- * if the argument is null.
- *
- * @param color the new color (or null)
- *
- * @exception IllegalArgumentException
- * - ERROR_INVALID_ARGUMENT - if the argument has been disposed
- *
- * @exception SWTException
- * - ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- * - ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- *
- *
- * @since 2.0
- *
- */
-public void setBackground (Color color) {
- checkWidget ();
- if (color != null && color.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- if (tableItem != null) {
- tableItem.setBackground(color);
- }
- background = color;
-}
-
-/**
- * Sets the checked state of the checkbox for this item. This state change
- * only applies if the Table was created with the SWT.CHECK style.
- *
- * @param checked the new checked state of the checkbox
- *
- * @exception SWTException
- * - ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- * - ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- *
- */
-public void setChecked (boolean checked) {
- checkWidget();
- Table table = parent.getTable();
- if ((table.getStyle() & SWT.CHECK) == 0) return;
- if (tableItem != null) {
- tableItem.setChecked(checked);
- }
- this.checked = checked;
-}
-
-/**
- * Sets the grayed state of the checkbox for this item. This state change
- * only applies if the Table was created with the SWT.CHECK style.
- *
- * @param grayed the new grayed state of the checkbox;
- *
- * @exception SWTException
- * - ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- * - ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- *
- *
- * @since 2.1
- */
-public void setGrayed (boolean grayed) {
- checkWidget();
- Table table = parent.getTable();
- if ((table.getStyle() & SWT.CHECK) == 0) return;
- if (tableItem != null) {
- tableItem.setGrayed(grayed);
- }
- this.grayed = grayed;
-}
-
-/**
- * Sets the expanded state.
- *
- * @param expanded the new expanded state.
- *
- * @exception SWTException
- * - ERROR_THREAD_INVALID_ACCESS when called from the wrong thread
- * - ERROR_WIDGET_DISPOSED when the widget has been disposed
- *
- */
-public void setExpanded (boolean expanded) {
- checkWidget();
- if (items.length == 0) return;
- if (this.expanded == expanded) return;
- this.expanded = expanded;
- if (tableItem == null) return;
- parent.setRedraw(false);
- for (int i = 0; i < items.length; i++) {
- items[i].setVisible(expanded);
- }
- Image image = expanded ? parent.getMinusImage() : parent.getPlusImage();
- tableItem.setImage(0, image);
- parent.setRedraw(true);
-}
-
-/**
- * Sets the font that the receiver will use to paint textual information
- * for this item 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
- * - ERROR_INVALID_ARGUMENT - if the argument has been disposed
- *
- * @exception SWTException
- * - ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- * - ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- *
- *
- * @since 3.0
- */
-public void setFont (Font font){
- checkWidget ();
- if (font != null && font.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- if (tableItem != null) {
- tableItem.setFont(font);
- }
- this.font = font;
-}
-/**
- * Sets the receiver's foreground color to the color specified
- * by the argument, or to the default system color for the item
- * if the argument is null.
- *
- * @param color the new color (or null)
- *
- * @since 2.0
- *
- * @exception IllegalArgumentException
- * - ERROR_INVALID_ARGUMENT - if the argument has been disposed
- *
- * @exception SWTException
- * - ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- * - ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- *
- *
- * @since 2.0
- *
- */
-public void setForeground (Color color) {
- checkWidget ();
- if (color != null && color.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- if (tableItem != null) {
- tableItem.setForeground(color);
- }
- foreground = color;
-}
-
-/**
- * Sets the image at an index.
- *
- * The image can be null.
- * The image in column 0 is reserved for the [+] and [-]
- * images of the tree, therefore do nothing if index is 0.
- *
- * @param image the new image or null
- *
- * @exception SWTException
- * - ERROR_THREAD_INVALID_ACCESS when called from the wrong thread
- * - ERROR_WIDGET_DISPOSED when the widget has been disposed
- *
- */
-public void setImage (int index, Image image) {
- checkWidget();
- int columnCount = Math.max(parent.getTable().getColumnCount(), 1);
- if (index <= 0 || index >= columnCount) return;
- if (images.length < columnCount) {
- Image[] newImages = new Image[columnCount];
- System.arraycopy(images, 0, newImages, 0, images.length);
- images = newImages;
- }
- images[index] = image;
- if (tableItem != null) tableItem.setImage(index, image);
-}
-
-/**
- * Sets the first image.
- *
- * The image can be null.
- * The image in column 0 is reserved for the [+] and [-]
- * images of the tree, therefore do nothing.
- *
- * @param image the new image or null
- *
- * @exception SWTException
- * - ERROR_THREAD_INVALID_ACCESS when called from the wrong thread
- * - ERROR_WIDGET_DISPOSED when the widget has been disposed
- *
- */
-public void setImage (Image image) {
- setImage(0, image);
-}
-
-/**
- * Sets the widget text.
- *
- *
- * The widget text for an item is the label of the
- * item or the label of the text specified by a column
- * number.
- *
- * @param index the column number
- * @param text the new text
- *
- * @exception IllegalArgumentException
- * - ERROR_NULL_ARGUMENT - if the text is null
- *
- * @exception SWTException
- * - ERROR_THREAD_INVALID_ACCESS when called from the wrong thread
- * - ERROR_WIDGET_DISPOSED when the widget has been disposed
- *
- */
-public void setText(int index, String text) {
- checkWidget();
- if (text == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- int columnCount = Math.max(parent.getTable().getColumnCount(), 1);
- if (index < 0 || index >= columnCount) return;
- if (texts.length < columnCount) {
- String[] newTexts = new String[columnCount];
- System.arraycopy(texts, 0, newTexts, 0, texts.length);
- texts = newTexts;
- }
- texts[index] = text;
- if (tableItem != null) tableItem.setText(index, text);
-}
-public void setText (String string) {
- setText(0, string);
-}
-
-void setVisible (boolean show) {
- if (parentItem == null) return; // this is a root and can not be toggled between visible and hidden
- if (getVisible() == show) return;
-
- if (show) {
- if (!parentItem.getVisible()) return; // parentItem must already be visible
- // create underlying table item and set data in table item to stored data
- Table table = parent.getTable();
- int parentIndex = table.indexOf(parentItem.tableItem);
- int index = parentItem.expandedIndexOf(this) + parentIndex + 1;
- if (index < 0) return;
- tableItem = new TableItem(table, getStyle(), index);
- tableItem.setData(TableTree.ITEMID, this);
- tableItem.setImageIndent(getIndent());
- if (background != null) tableItem.setBackground(background);
- if (foreground != null) tableItem.setForeground(foreground);
- if (font != null) tableItem.setFont(font);
- addCheck();
-
- // restore fields to item
- // ignore any images in the first column
- int columnCount = Math.max(table.getColumnCount(), 1);
- for (int i = 0; i < columnCount; i++) {
- if (i < texts.length && texts[i] != null) setText(i, texts[i]);
- if (i < images.length && images[i] != null) setImage(i, images[i]);
- }
-
- // display the children and the appropriate [+]/[-] symbol as required
- if (items.length != 0) {
- if (expanded) {
- tableItem.setImage(0, parent.getMinusImage());
- for (int i = 0, length = items.length; i < length; i++) {
- items[i].setVisible(true);
- }
- } else {
- tableItem.setImage(0, parent.getPlusImage());
- }
- }
-
- } else {
-
- for (int i = 0, length = items.length; i < length; i++) {
- items[i].setVisible(false);
- }
- // remove row from table
- tableItem.dispose();
- tableItem = null;
- }
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/TextChangeListener.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/TextChangeListener.java
deleted file mode 100755
index a7c53a855c..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/TextChangeListener.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.custom;
-
-
-import org.eclipse.swt.internal.SWTEventListener;
-
-/**
- * The StyledText widget implements this listener to receive
- * notifications when changes to the model occur.
- * It is not intended to be implemented by clients or by
- * implementors of StyledTextContent.
- * Clients should listen to the ModifyEvent or ExtendedModifyEvent
- * that is sent by the StyledText widget to receive text change
- * notifications.
- * Implementors of StyledTextContent should call the textChanging
- * and textChanged methods when text changes occur as described
- * below. If the entire text is replaced the textSet method
- * should be called instead.
- */
-public interface TextChangeListener extends SWTEventListener {
-
-/**
- * This method is called when the content is about to be changed.
- * Callers also need to call the textChanged method after the
- * content change has been applied. The widget only updates the
- * screen properly when it receives both events.
- *
- * @param event the text changing event. All event fields need
- * to be set by the sender.
- * @see TextChangingEvent
- */
-public void textChanging(TextChangingEvent event);
-/**
- * This method is called when the content has changed.
- * Callers need to have called the textChanging method prior to
- * applying the content change and calling this method. The widget
- * only updates the screen properly when it receives both events.
- *
- * @param event the text changed event
- */
-public void textChanged(TextChangedEvent event);
-/**
- * This method is called instead of the textChanging/textChanged
- * combination when the entire old content has been replaced
- * (e.g., by a call to StyledTextContent.setText()).
- *
- * @param event the text changed event
- */
-public void textSet(TextChangedEvent event);
-}
-
-
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/TextChangedEvent.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/TextChangedEvent.java
deleted file mode 100755
index 0cacf8a6f7..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/TextChangedEvent.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.custom;
-
-import org.eclipse.swt.events.*;
-
-/**
- * This event is sent by the StyledTextContent implementor when a change to
- * the text occurs.
- *
- * @see Sample code and further information
- */
-public class TextChangedEvent extends TypedEvent {
-
- static final long serialVersionUID = 3258696524257835065L;
-
-/**
- * Create the TextChangedEvent to be used by the StyledTextContent implementor.
- *
- *
- * @param source the object that will be sending the TextChangedEvent,
- * cannot be null
- */
-public TextChangedEvent(StyledTextContent source) {
- super(source);
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/TextChangingEvent.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/TextChangingEvent.java
deleted file mode 100755
index cf109a27dc..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/TextChangingEvent.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.custom;
-
-
-import org.eclipse.swt.events.*;
-
-/**
- * This event is sent by the StyledTextContent implementor when a change
- * to the text is about to occur.
- *
- * @see Sample code and further information
- */
-public class TextChangingEvent extends TypedEvent {
- /**
- * Start offset of the text that is going to be replaced
- */
- public int start;
- /**
- * Text that is going to be inserted or empty string
- * if no text will be inserted
- */
- public String newText;
- /**
- * Length of text that is going to be replaced
- */
- public int replaceCharCount;
- /**
- * Length of text that is going to be inserted
- */
- public int newCharCount;
- /**
- * Number of lines that are going to be replaced
- */
- public int replaceLineCount;
- /**
- * Number of new lines that are going to be inserted
- */
- public int newLineCount;
-
- static final long serialVersionUID = 3257290210114352439L;
-
-/**
- * Create the TextChangedEvent to be used by the StyledTextContent implementor.
- *
- *
- * @param source the object that will be sending the new TextChangingEvent,
- * cannot be null
- */
-public TextChangingEvent(StyledTextContent source) {
- super(source);
-}
-TextChangingEvent(StyledTextContent source, StyledTextEvent e) {
- super(source);
- start = e.start;
- replaceCharCount = e.replaceCharCount;
- newCharCount = e.newCharCount;
- replaceLineCount = e.replaceLineCount;
- newLineCount = e.newLineCount;
- newText = e.text;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/TreeEditor.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/TreeEditor.java
deleted file mode 100755
index de4f7b2f4f..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/TreeEditor.java
+++ /dev/null
@@ -1,319 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.custom;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.widgets.*;
-
-/**
-*
-* A TreeEditor is a manager for a Control that appears above a cell in a Tree and tracks with the
-* moving and resizing of that cell. It can be used to display a text widget above a cell
-* in a Tree so that the user can edit the contents of that cell. It can also be used to display
-* a button that can launch a dialog for modifying the contents of the associated cell.
-*
-*
Here is an example of using a TreeEditor:
-*
-* final Tree tree = new Tree(shell, SWT.BORDER);
-* for (int i = 0; i < 3; i++) {
-* TreeItem item = new TreeItem(tree, SWT.NONE);
-* item.setText("item " + i);
-* for (int j = 0; j < 3; j++) {
-* TreeItem subItem = new TreeItem(item, SWT.NONE);
-* subItem.setText("item " + i + " " + j);
-* }
-* }
-*
-* final TreeEditor editor = new TreeEditor(tree);
-* //The editor must have the same size as the cell and must
-* //not be any smaller than 50 pixels.
-* editor.horizontalAlignment = SWT.LEFT;
-* editor.grabHorizontal = true;
-* editor.minimumWidth = 50;
-*
-* tree.addSelectionListener(new SelectionAdapter() {
-* public void widgetSelected(SelectionEvent e) {
-* // Clean up any previous editor control
-* Control oldEditor = editor.getEditor();
-* if (oldEditor != null) oldEditor.dispose();
-*
-* // Identify the selected row
-* TreeItem item = (TreeItem)e.item;
-* if (item == null) return;
-*
-* // The control that will be the editor must be a child of the Tree
-* Text newEditor = new Text(tree, SWT.NONE);
-* newEditor.setText(item.getText());
-* newEditor.addModifyListener(new ModifyListener() {
-* public void modifyText(ModifyEvent e) {
-* Text text = (Text)editor.getEditor();
-* editor.getItem().setText(text.getText());
-* }
-* });
-* newEditor.selectAll();
-* newEditor.setFocus();
-* editor.setEditor(newEditor, item);
-* }
-* });
-*
-*
-* @see TreeEditor snippets
-* @see Sample code and further information
-*/
-public class TreeEditor extends ControlEditor {
- Tree tree;
- TreeItem item;
- int column = 0;
- ControlListener columnListener;
- TreeListener treeListener;
- Runnable timer;
- static final int TIMEOUT = 1500;
-
-/**
-* Creates a TreeEditor for the specified Tree.
-*
-* @param tree the Tree Control above which this editor will be displayed
-*
-*/
-public TreeEditor (Tree tree) {
- super(tree);
- this.tree = tree;
-
- columnListener = new ControlListener() {
- public void controlMoved(ControlEvent e){
- layout();
- }
- public void controlResized(ControlEvent e){
- layout();
- }
- };
- timer = new Runnable () {
- public void run() {
- layout ();
- }
- };
- treeListener = new TreeListener () {
- final Runnable runnable = new Runnable() {
- public void run() {
- if (editor == null || editor.isDisposed()) return;
- if (TreeEditor.this.tree.isDisposed()) return;
- layout();
- editor.setVisible(true);
- }
- };
- public void treeCollapsed(TreeEvent e) {
- if (editor == null || editor.isDisposed ()) return;
- editor.setVisible(false);
- e.display.asyncExec(runnable);
- }
- public void treeExpanded(TreeEvent e) {
- if (editor == null || editor.isDisposed ()) return;
- editor.setVisible(false);
- e.display.asyncExec(runnable);
- }
- };
- tree.addTreeListener(treeListener);
-
- // To be consistent with older versions of SWT, grabVertical defaults to true
- grabVertical = true;
-}
-
-Rectangle computeBounds () {
- if (item == null || column == -1 || item.isDisposed()) return new Rectangle(0, 0, 0, 0);
- Rectangle cell = item.getBounds(column);
- Rectangle rect = item.getImageBounds(column);
- cell.x = rect.x + rect.width;
- cell.width -= rect.width;
- Rectangle area = tree.getClientArea();
- if (cell.x < area.x + area.width) {
- if (cell.x + cell.width > area.x + area.width) {
- cell.width = area.x + area.width - cell.x;
- }
- }
- Rectangle editorRect = new Rectangle(cell.x, cell.y, minimumWidth, minimumHeight);
-
- if (grabHorizontal) {
- if (tree.getColumnCount() == 0) {
- // Bounds of tree item only include the text area - stretch out to include
- // entire client area
- cell.width = area.x + area.width - cell.x;
- }
- editorRect.width = Math.max(cell.width, minimumWidth);
- }
-
- if (grabVertical) {
- editorRect.height = Math.max(cell.height, minimumHeight);
- }
-
- if (horizontalAlignment == SWT.RIGHT) {
- editorRect.x += cell.width - editorRect.width;
- } else if (horizontalAlignment == SWT.LEFT) {
- // do nothing - cell.x is the right answer
- } else { // default is CENTER
- editorRect.x += (cell.width - editorRect.width)/2;
- }
- // don't let the editor overlap with the +/- of the tree
- editorRect.x = Math.max(cell.x, editorRect.x);
-
- if (verticalAlignment == SWT.BOTTOM) {
- editorRect.y += cell.height - editorRect.height;
- } else if (verticalAlignment == SWT.TOP) {
- // do nothing - cell.y is the right answer
- } else { // default is CENTER
- editorRect.y += (cell.height - editorRect.height)/2;
- }
- return editorRect;
-}
-
-/**
- * Removes all associations between the TreeEditor and the row in the tree. The
- * tree and the editor Control are not disposed.
- */
-public void dispose () {
- if (tree != null && !tree.isDisposed()) {
- if (this.column > -1 && this.column < tree.getColumnCount()){
- TreeColumn treeColumn = tree.getColumn(this.column);
- treeColumn.removeControlListener(columnListener);
- }
- if (treeListener != null) tree.removeTreeListener(treeListener);
- }
- columnListener = null;
- treeListener = null;
- tree = null;
- item = null;
- column = 0;
- timer = null;
- super.dispose();
-}
-
-/**
-* Returns the zero based index of the column of the cell being tracked by this editor.
-*
-* @return the zero based index of the column of the cell being tracked by this editor
-*
-* @since 3.1
-*/
-public int getColumn () {
- return column;
-}
-
-/**
-* Returns the TreeItem for the row of the cell being tracked by this editor.
-*
-* @return the TreeItem for the row of the cell being tracked by this editor
-*/
-public TreeItem getItem () {
- return item;
-}
-
-void resize () {
- layout();
- /*
- * On some platforms, the table scrolls when an item that
- * is partially visible at the bottom of the table is
- * selected. Ensure that the correct row is edited by
- * laying out one more time in a timerExec().
- */
- if (tree != null) {
- Display display = tree.getDisplay();
- display.timerExec(-1, timer);
- display.timerExec(TIMEOUT, timer);
- }
-}
-
-/**
-* Sets the zero based index of the column of the cell being tracked by this editor.
-*
-* @param column the zero based index of the column of the cell being tracked by this editor
-*
-* @since 3.1
-*/
-public void setColumn(int column) {
- int columnCount = tree.getColumnCount();
- // Separately handle the case where the tree has no TreeColumns.
- // In this situation, there is a single default column.
- if (columnCount == 0) {
- this.column = (column == 0) ? 0 : -1;
- resize();
- return;
- }
- if (this.column > -1 && this.column < columnCount){
- TreeColumn treeColumn = tree.getColumn(this.column);
- treeColumn.removeControlListener(columnListener);
- this.column = -1;
- }
-
- if (column < 0 || column >= tree.getColumnCount()) return;
-
- this.column = column;
- TreeColumn treeColumn = tree.getColumn(this.column);
- treeColumn.addControlListener(columnListener);
- resize();
-}
-
-/**
-* Specifies the TreeItem
that is to be edited.
-*
-* @param item the item to be edited
-*/
-public void setItem (TreeItem item) {
- this.item = item;
- resize();
-}
-
-/**
-* Specify the Control that is to be displayed and the cell in the tree that it is to be positioned above.
-*
-*
Note: The Control provided as the editor must be created with its parent being the Tree control
-* specified in the TreeEditor constructor.
-*
-* @param editor the Control that is displayed above the cell being edited
-* @param item the TreeItem for the row of the cell being tracked by this editor
-* @param column the zero based index of the column of the cell being tracked by this editor
-*
-* @since 3.1
-*/
-public void setEditor (Control editor, TreeItem item, int column) {
- setItem(item);
- setColumn(column);
- setEditor(editor);
-}
-public void setEditor (Control editor) {
- super.setEditor(editor);
- resize();
-}
-
-/**
-* Specify the Control that is to be displayed and the cell in the tree that it is to be positioned above.
-*
-*
Note: The Control provided as the editor must be created with its parent being the Tree control
-* specified in the TreeEditor constructor.
-*
-* @param editor the Control that is displayed above the cell being edited
-* @param item the TreeItem for the row of the cell being tracked by this editor
-*/
-public void setEditor (Control editor, TreeItem item) {
- setItem(item);
- setEditor(editor);
-}
-
-public void layout () {
- if (tree == null || tree.isDisposed()) return;
- if (item == null || item.isDisposed()) return;
- int columnCount = tree.getColumnCount();
- if (columnCount == 0 && column != 0) return;
- if (columnCount > 0 && (column < 0 || column >= columnCount)) return;
- super.layout();
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/VerifyKeyListener.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/VerifyKeyListener.java
deleted file mode 100755
index 6d308aecf0..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/VerifyKeyListener.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.custom;
-
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.internal.SWTEventListener;
-
-/**
- * Classes which implement this interface provide a method
- * that deals with the event that is generated when a
- * key is pressed.
- *
- * @see VerifyEvent
- * @see Sample code and further information
- */
-public interface VerifyKeyListener extends SWTEventListener {
-/**
- * The following event fields are used:
- * - event.character is the character that was typed (input)
- * - event.keyCode is the key code that was typed (input)
- * - event.stateMask is the state of the keyboard (input)
- * - event.doit is processed or not (output)
- *
- * @param event the verify event
- * @see VerifyEvent
- */
-public void verifyKey (VerifyEvent event);
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/ViewForm.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/ViewForm.java
deleted file mode 100755
index 55c1915ff3..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/ViewForm.java
+++ /dev/null
@@ -1,476 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.custom;
-
-
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.widgets.*;
-import org.eclipse.swt.*;
-
-/**
- * Instances of this class implement a Composite that positions and sizes
- * children and allows programmatic control of layout and border parameters.
- * ViewForm is used in the workbench to lay out a view's label/menu/toolbar
- * local bar.
- *
- * Note that although this class is a subclass of Composite
,
- * it does not make sense to set a layout on it.
- *
- *
- * - Styles:
- * - BORDER, FLAT
- * - Events:
- * - (None)
- *
- *
- * IMPORTANT: This class is not intended to be subclassed.
- *
- *
- * @see Sample code and further information
- * @noextend This class is not intended to be subclassed by clients.
- */
-
-public class ViewForm extends Composite {
-
- /**
- * marginWidth specifies the number of pixels of horizontal margin
- * that will be placed along the left and right edges of the form.
- *
- * The default value is 0.
- */
- public int marginWidth = 0;
- /**
- * marginHeight specifies the number of pixels of vertical margin
- * that will be placed along the top and bottom edges of the form.
- *
- * The default value is 0.
- */
- public int marginHeight = 0;
- /**
- * horizontalSpacing specifies the number of pixels between the right
- * edge of one cell and the left edge of its neighbouring cell to
- * the right.
- *
- * The default value is 1.
- */
- public int horizontalSpacing = 1;
- /**
- * verticalSpacing specifies the number of pixels between the bottom
- * edge of one cell and the top edge of its neighbouring cell underneath.
- *
- * The default value is 1.
- */
- public int verticalSpacing = 1;
-
- /**
- * Color of innermost line of drop shadow border.
- *
- * NOTE This field is badly named and can not be fixed for backwards compatibility.
- * It should be capitalized.
- *
- * @deprecated
- */
- public static RGB borderInsideRGB = new RGB (132, 130, 132);
- /**
- * Color of middle line of drop shadow border.
- *
- * NOTE This field is badly named and can not be fixed for backwards compatibility.
- * It should be capitalized.
- *
- * @deprecated
- */
- public static RGB borderMiddleRGB = new RGB (143, 141, 138);
- /**
- * Color of outermost line of drop shadow border.
- *
- * NOTE This field is badly named and can not be fixed for backwards compatibility.
- * It should be capitalized.
- *
- * @deprecated
- */
- public static RGB borderOutsideRGB = new RGB (171, 168, 165);
-
- // SWT widgets
- Control topLeft;
- Control topCenter;
- Control topRight;
- Control content;
-
- // Configuration and state info
- boolean separateTopCenter = false;
- boolean showBorder = false;
-
- int separator = -1;
- int borderTop = 0;
- int borderBottom = 0;
- int borderLeft = 0;
- int borderRight = 0;
- int highlight = 0;
- Point oldSize;
-
- Color selectionBackground;
- Listener listener;
-
- static final int OFFSCREEN = -200;
- static final int BORDER1_COLOR = SWT.COLOR_WIDGET_NORMAL_SHADOW;
- static final int SELECTION_BACKGROUND = SWT.COLOR_LIST_BACKGROUND;
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- *
- * The style value is either one of the style constants defined in
- * class SWT
which is applicable to instances of this
- * class, or must be built by bitwise OR'ing together
- * (that is, using the int
"|" operator) two or more
- * of those SWT
style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- *
- *
- * @param parent a widget which will be the parent of the new instance (cannot be null)
- * @param style the style of widget to construct
- *
- * @exception IllegalArgumentException
- * - ERROR_NULL_ARGUMENT - if the parent is null
- *
- * @exception SWTException
- * - ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent
- *
- *
- * @see SWT#BORDER
- * @see SWT#FLAT
- * @see #getStyle()
- */
-public ViewForm(Composite parent, int style) {
- super(parent, checkStyle(style));
- super.setLayout(new ViewFormLayout());
-
- setBorderVisible((style & SWT.BORDER) != 0);
-
- listener = new Listener() {
- public void handleEvent(Event e) {
- switch (e.type) {
- case SWT.Dispose: onDispose(e); break;
- case SWT.Paint: onPaint(e.gc); break;
- case SWT.Resize: onResize(); break;
- }
- }
- };
-
- int[] events = new int[] {SWT.Dispose, SWT.Paint, SWT.Resize};
-
- for (int i = 0; i < events.length; i++) {
- addListener(events[i], listener);
- }
-}
-
-static int checkStyle (int style) {
- int mask = SWT.FLAT | SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT;
- return style & mask | SWT.NO_REDRAW_RESIZE;
-}
-
-//protected void checkSubclass () {
-// String name = getClass().getName ();
-// String validName = ViewForm.class.getName();
-// if (!validName.equals(name)) {
-// SWT.error (SWT.ERROR_INVALID_SUBCLASS);
-// }
-//}
-
-public Rectangle computeTrim (int x, int y, int width, int height) {
- checkWidget ();
- int trimX = x - borderLeft - highlight;
- int trimY = y - borderTop - highlight;
- int trimWidth = width + borderLeft + borderRight + 2*highlight;
- int trimHeight = height + borderTop + borderBottom + 2*highlight;
- return new Rectangle(trimX, trimY, trimWidth, trimHeight);
-}
-public Rectangle getClientArea() {
- checkWidget();
- Rectangle clientArea = super.getClientArea();
- clientArea.x += borderLeft;
- clientArea.y += borderTop;
- clientArea.width -= borderLeft + borderRight;
- clientArea.height -= borderTop + borderBottom;
- return clientArea;
-}
-/**
-* Returns the content area.
-*
-* @return the control in the content area of the pane or null
-*/
-public Control getContent() {
- //checkWidget();
- return content;
-}
-/**
-* Returns Control that appears in the top center of the pane.
-* Typically this is a toolbar.
-*
-* @return the control in the top center of the pane or null
-*/
-public Control getTopCenter() {
- //checkWidget();
- return topCenter;
-}
-/**
-* Returns the Control that appears in the top left corner of the pane.
-* Typically this is a label such as CLabel.
-*
-* @return the control in the top left corner of the pane or null
-*/
-public Control getTopLeft() {
- //checkWidget();
- return topLeft;
-}
-/**
-* Returns the control in the top right corner of the pane.
-* Typically this is a Close button or a composite with a Menu and Close button.
-*
-* @return the control in the top right corner of the pane or null
-*/
-public Control getTopRight() {
- //checkWidget();
- return topRight;
-}
-void onDispose(Event event) {
- removeListener(SWT.Dispose, listener);
- notifyListeners(SWT.Dispose, event);
- event.type = SWT.None;
-
- topLeft = null;
- topCenter = null;
- topRight = null;
- content = null;
- oldSize = null;
- selectionBackground = null;
-}
-void onPaint(GC gc) {
- Color gcForeground = gc.getForeground();
- Point size = getSize();
- Color border = getDisplay().getSystemColor(BORDER1_COLOR);
- if (showBorder) {
- gc.setForeground(border);
- gc.drawRectangle(0, 0, size.x - 1, size.y - 1);
- if (highlight > 0) {
- int x1 = 1;
- int y1 = 1;
- int x2 = size.x - 1;
- int y2 = size.y - 1;
- int[] shape = new int[] {x1,y1, x2,y1, x2,y2, x1,y2, x1,y1+highlight,
- x1+highlight,y1+highlight, x1+highlight,y2-highlight,
- x2-highlight,y2-highlight, x2-highlight,y1+highlight, x1,y1+highlight};
- Color highlightColor = getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION);
- gc.setBackground(highlightColor);
- gc.fillPolygon(shape);
- }
- }
- if (separator > -1) {
- gc.setForeground(border);
- gc.drawLine(borderLeft + highlight, separator, size.x - borderLeft - borderRight - highlight, separator);
- }
- gc.setForeground(gcForeground);
-}
-void onResize() {
- Point size = getSize();
- if (oldSize == null || oldSize.x == 0 || oldSize.y == 0) {
- redraw();
- } else {
- int width = 0;
- if (oldSize.x < size.x) {
- width = size.x - oldSize.x + borderRight + highlight;
- } else if (oldSize.x > size.x) {
- width = borderRight + highlight;
- }
- redraw(size.x - width, 0, width, size.y, false);
-
- int height = 0;
- if (oldSize.y < size.y) {
- height = size.y - oldSize.y + borderBottom + highlight;
- }
- if (oldSize.y > size.y) {
- height = borderBottom + highlight;
- }
- redraw(0, size.y - height, size.x, height, false);
- }
- oldSize = size;
-}
-/**
-* Sets the content.
-* Setting the content to null will remove it from
-* the pane - however, the creator of the content must dispose of the content.
-*
-* @param content the control to be displayed in the content area or null
-*
-* @exception SWTException
-* - ERROR_WIDGET_DISPOSED - if the receiver has been disposed
-* - ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-* - ERROR_INVALID_ARGUMENT - if the control is not a child of this ViewForm
-*
-*/
-public void setContent(Control content) {
- checkWidget();
- if (content != null && content.getParent() != this) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- if (this.content != null && !this.content.isDisposed()) {
- this.content.setBounds(OFFSCREEN, OFFSCREEN, 0, 0);
- }
- this.content = content;
- layout(false);
-}
-/**
- * Sets the layout which is associated with the receiver to be
- * the argument which may be null.
- *
- * Note: No Layout can be set on this Control because it already
- * manages the size and position of its children.
- *
- *
- * @param layout the receiver's new layout or null
- *
- * @exception SWTException
- * - ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- * - ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- *
- */
-public void setLayout (Layout layout) {
- checkWidget();
- return;
-}
-void setSelectionBackground (Color color) {
- checkWidget();
- if (selectionBackground == color) return;
- if (color == null) color = getDisplay().getSystemColor(SELECTION_BACKGROUND);
- selectionBackground = color;
- redraw();
-}
-/**
-* Set the control that appears in the top center of the pane.
-* Typically this is a toolbar.
-* The topCenter is optional. Setting the topCenter to null will remove it from
-* the pane - however, the creator of the topCenter must dispose of the topCenter.
-*
-* @param topCenter the control to be displayed in the top center or null
-*
-* @exception SWTException
-* - ERROR_WIDGET_DISPOSED - if the receiver has been disposed
-* - ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-* - ERROR_INVALID_ARGUMENT - if the control is not a child of this ViewForm
-*
-*/
-public void setTopCenter(Control topCenter) {
- checkWidget();
- if (topCenter != null && topCenter.getParent() != this) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- if (this.topCenter != null && !this.topCenter.isDisposed()) {
- Point size = this.topCenter.getSize();
- this.topCenter.setLocation(OFFSCREEN - size.x, OFFSCREEN - size.y);
- }
- this.topCenter = topCenter;
- layout(false);
-}
-/**
-* Set the control that appears in the top left corner of the pane.
-* Typically this is a label such as CLabel.
-* The topLeft is optional. Setting the top left control to null will remove it from
-* the pane - however, the creator of the control must dispose of the control.
-*
-* @param c the control to be displayed in the top left corner or null
-*
-* @exception SWTException
-* - ERROR_WIDGET_DISPOSED - if the receiver has been disposed
-* - ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-* - ERROR_INVALID_ARGUMENT - if the control is not a child of this ViewForm
-*
-*/
-public void setTopLeft(Control c) {
- checkWidget();
- if (c != null && c.getParent() != this) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- if (this.topLeft != null && !this.topLeft.isDisposed()) {
- Point size = this.topLeft.getSize();
- this.topLeft.setLocation(OFFSCREEN - size.x, OFFSCREEN - size.y);
- }
- this.topLeft = c;
- layout(false);
-}
-/**
-* Set the control that appears in the top right corner of the pane.
-* Typically this is a Close button or a composite with a Menu and Close button.
-* The topRight is optional. Setting the top right control to null will remove it from
-* the pane - however, the creator of the control must dispose of the control.
-*
-* @param c the control to be displayed in the top right corner or null
-*
-* @exception SWTException
-* - ERROR_WIDGET_DISPOSED - if the receiver has been disposed
-* - ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-* - ERROR_INVALID_ARGUMENT - if the control is not a child of this ViewForm
-*
-*/
-public void setTopRight(Control c) {
- checkWidget();
- if (c != null && c.getParent() != this) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- if (this.topRight != null && !this.topRight.isDisposed()) {
- Point size = this.topRight.getSize();
- this.topRight.setLocation(OFFSCREEN - size.x, OFFSCREEN - size.y);
- }
- this.topRight = c;
- layout(false);
-}
-/**
-* Specify whether the border should be displayed or not.
-*
-* @param show true if the border should be displayed
-*
-* @exception SWTException
-* - ERROR_WIDGET_DISPOSED - if the receiver has been disposed
-* - ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-*
-*/
-public void setBorderVisible(boolean show) {
- checkWidget();
- if (showBorder == show) return;
-
- showBorder = show;
- if (showBorder) {
- borderLeft = borderTop = borderRight = borderBottom = 1;
- if ((getStyle() & SWT.FLAT)== 0) highlight = 2;
- } else {
- borderBottom = borderTop = borderLeft = borderRight = 0;
- highlight = 0;
- }
- layout(false);
- redraw();
-}
-/**
-* If true, the topCenter will always appear on a separate line by itself, otherwise the
-* topCenter will appear in the top row if there is room and will be moved to the second row if
-* required.
-*
-* @param show true if the topCenter will always appear on a separate line by itself
-*
-* @exception SWTException
-* - ERROR_WIDGET_DISPOSED - if the receiver has been disposed
-* - ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-*
-*/
-public void setTopCenterSeparate(boolean show) {
- checkWidget();
- separateTopCenter = show;
- layout(false);
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/ViewFormLayout.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/ViewFormLayout.java
deleted file mode 100644
index 18d4b6d421..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/ViewFormLayout.java
+++ /dev/null
@@ -1,211 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.custom;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.widgets.*;
-
-/**
- * This class provides the layout for ViewForm
- *
- * @see ViewForm
- */
-class ViewFormLayout extends Layout {
-
-protected Point computeSize(Composite composite, int wHint, int hHint, boolean flushCache) {
- ViewForm form = (ViewForm)composite;
- Control left = form.topLeft;
- Control center = form.topCenter;
- Control right = form.topRight;
- Control content = form.content;
-
- Point leftSize = new Point(0, 0);
- if (left != null) {
- leftSize = computeChildSize(left, SWT.DEFAULT, SWT.DEFAULT, flushCache);
- }
- Point centerSize = new Point(0, 0);
- if (center != null) {
- centerSize = computeChildSize(center, SWT.DEFAULT, SWT.DEFAULT, flushCache);
- }
- Point rightSize = new Point(0, 0);
- if (right != null) {
- rightSize = computeChildSize(right, SWT.DEFAULT, SWT.DEFAULT, flushCache);
- }
- Point size = new Point(0, 0);
- // calculate width of title bar
- if (form.separateTopCenter ||
- (wHint != SWT.DEFAULT && leftSize.x + centerSize.x + rightSize.x > wHint)) {
- size.x = leftSize.x + rightSize.x;
- if (leftSize.x > 0 && rightSize.x > 0) size.x += form.horizontalSpacing;
- size.x = Math.max(centerSize.x, size.x);
- size.y = Math.max(leftSize.y, rightSize.y);
- if (center != null){
- size.y += centerSize.y;
- if (left != null ||right != null)size.y += form.verticalSpacing;
- }
- } else {
- size.x = leftSize.x + centerSize.x + rightSize.x;
- int count = -1;
- if (leftSize.x > 0) count++;
- if (centerSize.x > 0) count++;
- if (rightSize.x > 0) count++;
- if (count > 0) size.x += count * form.horizontalSpacing;
- size.y = Math.max(leftSize.y, Math.max(centerSize.y, rightSize.y));
- }
-
- if (content != null) {
- if (left != null || right != null || center != null) size.y += 1; // allow space for a vertical separator
- Point contentSize = new Point(0, 0);
- contentSize = computeChildSize(content, SWT.DEFAULT, SWT.DEFAULT, flushCache);
- size.x = Math.max (size.x, contentSize.x);
- size.y += contentSize.y;
- if (size.y > contentSize.y) size.y += form.verticalSpacing;
- }
-
- size.x += 2*form.marginWidth;
- size.y += 2*form.marginHeight;
-
- if (wHint != SWT.DEFAULT) size.x = wHint;
- if (hHint != SWT.DEFAULT) size.y = hHint;
-
- return size;
-}
-
-Point computeChildSize(Control control, int wHint, int hHint, boolean flushCache) {
- Object data = control.getLayoutData();
- if (data == null || !(data instanceof CLayoutData)) {
- data = new CLayoutData();
- control.setLayoutData(data);
- }
- return ((CLayoutData)data).computeSize(control, wHint, hHint, flushCache);
-}
-
-int computeTrim(Control c) {
- if (c instanceof Scrollable) {
- Rectangle rect = ((Scrollable) c).computeTrim (0, 0, 0, 0);
- return rect.width;
- }
- return c.getBorderWidth () * 2;
-}
-
-protected boolean flushCache(Control control) {
- Object data = control.getLayoutData();
- if (data != null && data instanceof CLayoutData) ((CLayoutData)data).flushCache();
- return true;
-}
-
-protected void layout(Composite composite, boolean flushCache) {
- ViewForm form = (ViewForm)composite;
- Control left = form.topLeft;
- Control center = form.topCenter;
- Control right = form.topRight;
- Control content = form.content;
-
- Rectangle rect = composite.getClientArea();
-
- Point leftSize = new Point(0, 0);
- if (left != null && !left.isDisposed()) {
- leftSize = computeChildSize(left, SWT.DEFAULT, SWT.DEFAULT, flushCache);
- }
- Point centerSize = new Point(0, 0);
- if (center != null && !center.isDisposed()) {
- centerSize = computeChildSize(center, SWT.DEFAULT, SWT.DEFAULT, flushCache);
- }
- Point rightSize = new Point(0, 0);
- if (right != null && !right.isDisposed()) {
- rightSize = computeChildSize(right, SWT.DEFAULT, SWT.DEFAULT, flushCache);
- }
-
- int minTopWidth = leftSize.x + centerSize.x + rightSize.x + 2*form.marginWidth + 2*form.highlight;
- int count = -1;
- if (leftSize.x > 0) count++;
- if (centerSize.x > 0) count++;
- if (rightSize.x > 0) count++;
- if (count > 0) minTopWidth += count * form.horizontalSpacing;
-
- int x = rect.x + rect.width - form.marginWidth - form.highlight;
- int y = rect.y + form.marginHeight + form.highlight;
-
- boolean top = false;
- if (form.separateTopCenter || minTopWidth > rect.width) {
- int topHeight = Math.max(rightSize.y, leftSize.y);
- if (right != null && !right.isDisposed()) {
- top = true;
- x -= rightSize.x;
- right.setBounds(x, y, rightSize.x, topHeight);
- x -= form.horizontalSpacing;
- }
- if (left != null && !left.isDisposed()) {
- top = true;
- int trim = computeTrim(left);
- int leftW = x - rect.x - form.marginWidth - form.highlight - trim;
- leftSize = computeChildSize(left, leftW, SWT.DEFAULT, false);
- left.setBounds(rect.x + form.marginWidth + form.highlight, y, leftSize.x, topHeight);
- }
- if (top) y += topHeight + form.verticalSpacing;
- if (center != null && !center.isDisposed()) {
- top = true;
- int trim = computeTrim(center);
- int w = rect.width - 2*form.marginWidth - 2*form.highlight - trim;
- centerSize = computeChildSize(center, w, SWT.DEFAULT, false);
- center.setBounds(rect.x + rect.width - form.marginWidth - form.highlight - centerSize.x, y, centerSize.x, centerSize.y);
- y += centerSize.y + form.verticalSpacing;
- }
- } else {
- int topHeight = Math.max(rightSize.y, Math.max(centerSize.y, leftSize.y));
- if (right != null && !right.isDisposed()) {
- top = true;
- x -= rightSize.x;
- right.setBounds(x, y, rightSize.x, topHeight);
- x -= form.horizontalSpacing;
- }
- if (center != null && !center.isDisposed()) {
- top = true;
- x -= centerSize.x;
- center.setBounds(x, y, centerSize.x, topHeight);
- x -= form.horizontalSpacing;
- }
- if (left != null && !left.isDisposed()) {
- top = true;
- Rectangle trim = left instanceof Composite ? ((Composite)left).computeTrim(0, 0, 0, 0) : new Rectangle(0, 0, 0, 0);
- int w = x - rect.x - form.marginWidth - form.highlight - trim.width;
- int h = topHeight - trim.height;
- leftSize = computeChildSize(left, w, h, false);
- left.setBounds(rect.x + form.marginWidth + form.highlight, y, leftSize.x, topHeight);
- }
- if (top)y += topHeight + form.verticalSpacing;
- }
- int oldSeperator = form.separator;
- form.separator = -1;
- if (content != null && !content.isDisposed()) {
- if (left != null || right!= null || center != null){
- form.separator = y;
- y++;
- }
- content.setBounds(rect.x + form.marginWidth + form.highlight, y, rect.width - 2 * form.marginWidth - 2*form.highlight, rect.y + rect.height - y - form.marginHeight - form.highlight);
- }
- if (oldSeperator != form.separator) {
- int t, b;
- if (oldSeperator == -1) {
- t = form.separator;
- b = form.separator + 1;
- } else if (form.separator == -1) {
- t = oldSeperator;
- b = oldSeperator + 1;
- } else {
- t = Math.min(form.separator, oldSeperator);
- b = Math.max(form.separator, oldSeperator);
- }
- form.redraw(form.borderLeft, t, form.getSize().x - form.borderLeft - form.borderRight, b - t, false);
- }
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/package.html b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/package.html
deleted file mode 100755
index 3011a3feef..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/package.html
+++ /dev/null
@@ -1,15 +0,0 @@
-
-
-
-
-
- Package-level Javadoc
-
-
-SWT Custom widgets.
-
-Package Specification
-This package contains the custom widgets which were written to provide the
-standard look and feel of the Eclipse platform.
-
-
--
cgit