# HG changeset patch
# User Frank Benoit
- * The style value is either one of the style constants defined in
- * class
+ * The style value is either one of the style constants defined in
+ * class
- * The elements in the segments field specify the start offset of
+ * 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 : Canvas
-{
+public class AnimatedProgress : Canvas {
+
+ alias Canvas.computeSize computeSize;
static const int SLEEP = 70;
static const int DEFAULT_WIDTH = 160;
@@ -47,236 +54,192 @@
int orientation = DWT.HORIZONTAL;
bool showBorder = false;
- /**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * DWT
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 DWT
style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- *
- *
- * @exception DWTException
- *
- *
- * @see DWT#VERTICAL
- * @see DWT#HORIZONTAL
- * @see DWT#BORDER
- * @see #getStyle()
- */
- public this (Composite parent, int style)
- {
- super(parent, checkStyle(style));
+/**
+ * Constructs a new instance of this class given its parent
+ * and a style value describing its behavior and appearance.
+ * DWT
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 DWT
style constants. The class description
+ * lists the style constants that are applicable to the class.
+ * Style bits are also inherited from superclasses.
+ *
+ *
+ * @exception DWTException
+ *
+ *
+ * @see DWT#VERTICAL
+ * @see DWT#HORIZONTAL
+ * @see DWT#BORDER
+ * @see #getStyle()
+ */
+public this(Composite parent, int style) {
+ super(parent, checkStyle(style));
- if ((style & DWT.VERTICAL) !is 0)
- {
- orientation = DWT.VERTICAL;
- }
- showBorder = (style & DWT.BORDER) !is 0;
+ if ((style & DWT.VERTICAL) !is 0) {
+ orientation = DWT.VERTICAL;
+ }
+ showBorder = (style & DWT.BORDER) !is 0;
- addControlListener(new class ControlAdapter
- {
- public void controlResized (ControlEvent e)
- {
- redraw();
- }
- });
- addPaintListener(new class PaintListener
- {
- public void paintControl (PaintEvent e)
- {
- paint(e);
- }
- });
- addDisposeListener(new class DisposeListener
- {
- public void widgetDisposed (DisposeEvent e)
- {
- stop();
- }
- });
+ addControlListener(new class() ControlAdapter {
+ public void controlResized(ControlEvent e) {
+ redraw();
+ }
+ });
+ addPaintListener(new class() PaintListener {
+ public void paintControl(PaintEvent e) {
+ paint(e);
+ }
+ });
+ addDisposeListener(new class() DisposeListener {
+ public void widgetDisposed(DisposeEvent e){
+ stop();
+ }
+ });
+}
+private static int checkStyle (int style) {
+ int mask = DWT.NONE;
+ return style & mask;
+}
+/**
+ * Stop the animation if it is not already stopped and
+ * reset the presentation to a blank appearance.
+ *
+ * @exception DWTException
+ *
+ */
+public synchronized void clear(){
+ checkWidget();
+ if (active) stop();
+ showStripes = false;
+ redraw();
+}
+public override Point computeSize(int wHint, int hHint, bool changed) {
+ checkWidget();
+ Point size = null;
+ if (orientation is DWT.HORIZONTAL) {
+ size = new Point(DEFAULT_WIDTH, DEFAULT_HEIGHT);
+ } else {
+ size = new Point(DEFAULT_HEIGHT, DEFAULT_WIDTH);
}
+ if (wHint !is DWT.DEFAULT) size.x = wHint;
+ if (hHint !is DWT.DEFAULT) size.y = hHint;
- private static int checkStyle (int style)
- {
- int mask = DWT.NONE;
- return style & mask;
- }
+ 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);
- /**
- * Stop the animation if it is not already stopped and
- * reset the presentation to a blank appearance.
- *
- * @exception DWTException
- *
- */
- public synchronized void clear ()
- {
- checkWidget();
- if (active)
- stop();
- showStripes = false;
- redraw();
+ 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(DWT.COLOR_WIDGET_NORMAL_SHADOW),
+ disp.getSystemColor(DWT.COLOR_WIDGET_HIGHLIGHT_SHADOW));
}
- public Point computeSize (int wHint, int hHint, bool changed)
- {
- checkWidget();
- Point size = null;
- if (orientation is DWT.HORIZONTAL)
- {
- size = new Point(DEFAULT_WIDTH, DEFAULT_HEIGHT);
- }
- else
- {
- size = new Point(DEFAULT_HEIGHT, DEFAULT_WIDTH);
- }
- if (wHint !is DWT.DEFAULT)
- size.x = wHint;
- if (hHint !is DWT.DEFAULT)
- size.y = hHint;
-
- return size;
- }
+ paintStripes(gc);
+}
+void paintStripes(GC gc) {
- 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);
- }
+ if (!showStripes) return;
- 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(DWT.COLOR_WIDGET_NORMAL_SHADOW),
- disp.getSystemColor(DWT.COLOR_WIDGET_HIGHLIGHT_SHADOW));
- }
+ Rectangle rect= getClientArea();
+ // Subtracted border painted by paint.
+ rect = new Rectangle(rect.x+2, rect.y+2, rect.width-4, rect.height-4);
- 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(DWT.COLOR_LIST_SELECTION);
+ gc.setBackground(color);
+ gc.fillRectangle(rect);
+ gc.setForeground(this.getBackground());
+ int step = 12;
+ int foregroundValue = value is 0 ? step - 2 : value - 2;
+ if (orientation is DWT.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;
- gc.setLineWidth(2);
- gc.setClipping(rect);
- Color color = getDisplay().getSystemColor(DWT.COLOR_LIST_SELECTION);
- gc.setBackground(color);
- gc.fillRectangle(rect);
- gc.setForeground(this.getBackground());
- int step = 12;
- int foregroundValue = value is 0 ? step - 2 : value - 2;
- if (orientation is DWT.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;
+ for (int i= 0; i < h; i+= step) {
+ int y = i + foregroundValue;
+ gc.drawLine(x, y, w, y);
}
}
- /**
- * Start the animation.
- *
- * @exception DWTException
- *
- */
- public synchronized void start ()
- {
- checkWidget();
- if (active)
- return;
-
- active = true;
- showStripes = true;
-
- const Display display = getDisplay();
- const Runnable[] timer = new Runnable[1];
- timer[0] = new class (display) Runnable
- {
- Display display;
-
- this (Display display)
- {
- this.display = display;
- }
-
- public void run ()
- {
- if (!active)
- return;
- GC gc = new GC(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;
+ if (active) {
+ value = (value + 2) % step;
}
}
+/**
+* Start the animation.
+*
+* @exception DWTException
+*
+*/
+public synchronized void start() {
+ checkWidget();
+ if (active) return;
+
+ active = true;
+ showStripes = true;
+
+ Display display = getDisplay();
+ Runnable [] timer = new Runnable [1];
+
+ timer [0] = new class( display, timer ) Runnable {
+ Display disp;
+ Runnable [] runs;
+ this( Display disp, Runnable[] runs ){
+ this.disp = disp;
+ this.runs = runs;
+ }
+ public void run () {
+ if (!active) return;
+ GC gc = new GC(this.outer);
+ paintStripes(gc);
+ gc.dispose();
+ disp.timerExec (SLEEP, runs [0]);
+ }
+ };
+ display.timerExec (SLEEP, timer [0]);
+}
+/**
+* Stop the animation. Freeze the presentation at its current appearance.
+*/
+public synchronized void stop() {
+ //checkWidget();
+ active = false;
+}
+}
diff -r fbe68c33eeee -r 6337764516f1 dwt/custom/BidiSegmentEvent.d
--- a/dwt/custom/BidiSegmentEvent.d Tue Oct 07 14:41:31 2008 +0200
+++ b/dwt/custom/BidiSegmentEvent.d Tue Oct 07 16:29:55 2008 +0200
@@ -1,5 +1,5 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 IBM Corporation and others.
+/*******************************************************************************
+ * 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
@@ -7,25 +7,25 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
- *
* Port to the D programming language:
- * Jacob Carlborg
@@ -33,57 +33,57 @@
*
- * In addition, the last element may be set to the end of the line
+ * 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
+ * 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). + * + * 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". + * + * 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 : TypedEvent { - /** - * line start offset + /** + * line start offset */ public int lineOffset; - /** - * line text + /** + * line text */ public String lineText; - /** - * bidi segments, see above + /** + * bidi segments, see above */ public int[] segments; - static final long serialVersionUID = 3257846571587547957L; - - this (StyledTextEvent e) { - super(e); - lineOffset = e.detail; - lineText = e.text; - } +this(StyledTextEvent e) { + super(cast(Object)e); + lineOffset = e.detail; + lineText = e.text; } +} diff -r fbe68c33eeee -r 6337764516f1 dwt/custom/BidiSegmentListener.d --- a/dwt/custom/BidiSegmentListener.d Tue Oct 07 14:41:31 2008 +0200 +++ b/dwt/custom/BidiSegmentListener.d Tue Oct 07 16:29:55 2008 +0200 @@ -1,4 +1,4 @@ -/******************************************************************************* +/******************************************************************************* * 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 @@ -7,14 +7,13 @@ * * Contributors: * IBM Corporation - initial API and implementation - * * Port to the D programming language: - * Jacob Carlborg
- * The following event fields are used:
+ * The following event fields are used:
StyledText
.
* - * The toHash() method in this class uses the values of the public + * 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. + * 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 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 * IMPORTANT: This class is not intended to be subclassed. *
- * + * + * @see Sample code and further information + * * @since 3.0 */ @@ -59,9 +66,9 @@ bool simple = true; - int[] curve = new int[0]; + int[] curve; int curveStart = 0; - Rectangle curveRect = new Rectangle(0, 0, 0, 0); + Rectangle curveRect; int curve_width = 5; int curve_indent = -2; @@ -82,506 +89,472 @@ static const int MIN_LEFT = 10; static int BORDER1 = DWT.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 DWT
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 DWT
style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- *
+ * The style value is either one of the style constants defined in
+ * class DWT
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 DWT
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 bool getSimple() {
+ checkWidget();
+ return simple;
+}
+void onDispose() {
+ if (resizeCursor !is 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;
}
-
- /**
- * Returns the minimum size of the control that appears on the right of the banner.
- *
- * @return the minimum size of the control that appears on the right of the banner
- *
- * @since 3.1
- */
- public Point getRightMinimumSize () {
- checkWidget();
- return new Point(rightMinWidth, rightMinHeight);
- }
-
- /**
- * Returns the width of the control that appears on the right of the banner.
- *
- * @return the width of the control that appears on the right of the banner
- *
- * @since 3.0
- */
- public int getRightWidth () {
- checkWidget();
- if (right is null)
- return 0;
- if (rightWidth is DWT.DEFAULT) {
- Point size = right.computeSize(DWT.DEFAULT, DWT.DEFAULT, false);
- return size.x;
+}
+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 is DWT.DEFAULT) {
+ Point minSize = right.computeSize(rightMinWidth, rightMinHeight);
+ rightWidth = Math.max(minSize.x, rightWidth);
+ } else {
+ rightWidth = Math.max(rightMinWidth, rightWidth);
}
- return rightWidth;
+ layout(false);
+ return;
}
-
- /**
- * Returns 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 bool getSimple () {
- checkWidget();
- return simple;
+ if (curveRect.contains(x, y)) {
+ setCursor(resizeCursor);
+ } else {
+ setCursor(null);
}
-
- void onDispose () {
- if (resizeCursor !is null)
- resizeCursor.dispose();
- resizeCursor = null;
- left = null;
- right = null;
- bottom = null;
+}
+void onMouseUp () {
+ dragging = false;
+}
+void onPaint(GC gc) {
+// Useful for debugging paint problems
+// {
+// Point size = getSize();
+// gc.setBackground(getDisplay().getSystemColor(DWT.COLOR_GREEN));
+// gc.fillRectangle(-10, -10, size.x+20, size.y+20);
+// }
+ if (left is null && right is null) return;
+ Point size = getSize();
+ Color border1 = getDisplay().getSystemColor(BORDER1);
+ if (bottom !is null) {
+ int y = bottom.getBounds().y - BORDER_STRIPE - 1;
+ gc.setForeground(border1);
+ gc.drawLine(0, y, size.x, y);
}
-
- void onMouseDown (int x, int y) {
- if (curveRect.contains(x, y)) {
- dragging = true;
- rightDragDisplacement = curveStart - x + curve_width - curve_indent;
- }
+ if (left is null || right is 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;
- void onMouseExit () {
- if (!dragging)
- setCursor(null);
- }
+ Color background = getBackground();
- 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 is DWT.DEFAULT) {
- Point minSize = right.computeSize(rightMinWidth, rightMinHeight);
- rightWidth = Math.max(minSize.x, rightWidth);
- }
- else {
- rightWidth = Math.max(rightMinWidth, rightWidth);
- }
- layout(false);
- return;
+ 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++];
}
- if (curveRect.contains(x, y)) {
- setCursor(resizeCursor);
- }
- else {
- setCursor(null);
- }
- }
+ 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();
- void onMouseUp () {
- dragging = false;
+ // 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);
}
- void onPaint (GC gc) {
- // Useful for debugging paint problems
- // {
- // Point size = getSize();
- // gc.setBackground(getDisplay().getSystemColor(DWT.COLOR_GREEN));
- // gc.fillRectangle(-10, -10, size.x+20, size.y+20);
- // }
- if (left is null && right is null)
- return;
- Point size = getSize();
- Color border1 = getDisplay().getSystemColor(BORDER1);
- if (bottom !is null) {
- int y = bottom.getBounds().y - BORDER_STRIPE - 1;
- gc.setForeground(border1);
- gc.drawLine(0, y, size.x, y);
- }
- if (left is null || right is 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 border
+ gc.setForeground(border1);
+ gc.drawPolyline(line1);
+}
- // 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);
+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 DWTException - * 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 DWTException+ * 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 DWTExceptiontrue
if the CBanner should render itself in a simple, traditional style
+ *
+ * @exception DWTException true
if the CBanner should render itself in a simple, traditional style
- *
- * @exception DWTException
- * The style value is either one of the style constants defined in
- * class DWT
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 DWT
style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- *
+ * The style value is either one of the style constants defined in
+ * class DWT
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 DWT
style constants. The class description
+ * lists the style constants that are applicable to the class.
+ * Style bits are also inherited from superclasses.
+ *
getItemCount()
as the
- * index or use add(String)
.
- *
- *
- * @param String the new item
- * @param index the index for the item
- *
- * @exception IllegalArgumentException 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 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()
.
- *
+ * Note: To clear the selected items in the receiver's list,
+ * use deselectAll()
.
+ *
- * The current selection is copied to the clipboard. - *
- * - * @exception DWTException+ * The current selection is copied to the clipboard. + *
+ * + * @exception DWTException- * The current selection is first copied to the - * clipboard and then deleted from the widget. - *
- * - * @exception DWTException
+ * Note: To clear the selection in the receiver's text field,
+ * use clearSelection()
.
+ *
- * 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 DWTExceptiontrue
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 DWTExceptionPoint
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 DWTException setTextLimit()
, it will be the constant
- * Combo.LIMIT
.
- *
- * @return the text limit
- *
- * @exception DWTException 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 DWTExceptiontrue
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 DWTExceptionPoint
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 DWTException setTextLimit()
, it will be the constant
+ * Combo.LIMIT
.
+ *
+ * @return the text limit
+ *
+ * @exception DWTException + * The selected text is deleted from the widget + * and new text inserted from the clipboard. + *
+ * + * @exception DWTException+ * @exception DWTException
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 DWTExceptiontrue
,
+ * 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 DWTException
+ * 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.
+ *
- * The selected text is deleted from the widget - * and new text inserted from the clipboard. - *
- * - * @exception DWTException- * @exception DWTException
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 DWTExceptiontrue
,
- * 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 DWTException
- * 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 + * 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 @@ -59,22 +61,26 @@ *
* IMPORTANT: This class is not intended to be subclassed. *
+ * + * @see DWT Example: CustomControlExample + * @see Sample code and further information */ -public class CLabel : Canvas -{ +public class CLabel : Canvas { + + alias Canvas.computeSize computeSize; /** Gap between icon and text */ private static const int GAP = 5; /** Left and right margins */ private static const int INDENT = 3; - /** a String inserted in the middle of text that has been shortened */ + /** a string inserted in the middle of text that has been shortened */ private static const String ELLIPSIS = "..."; //$NON-NLS-1$ // could use the ellipsis glyph on some platforms "\u2026" - /** the alignnment. Either CENTER, RIGHT, LEFT. Default is LEFT*/ - private int alignn = DWT.LEFT; + /** the alignment. Either CENTER, RIGHT, LEFT. Default is LEFT*/ + private int align_ = DWT.LEFT; private int hIndent = INDENT; private int vIndent = INDENT; /** the current text */ @@ -84,7 +90,7 @@ // 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 + // The appToolTip stores the tooltip set by the application. Control.tooltiptext // contains whatever tooltip is currently being displayed. private String appToolTipText; @@ -94,947 +100,750 @@ private bool gradientVertical; private Color background; - private static int - DRAW_FLAGS = DWT.DRAW_MNEMONIC | DWT.DRAW_TAB | DWT.DRAW_TRANSPARENT | DWT.DRAW_DELIMITER; + private static int DRAW_FLAGS = DWT.DRAW_MNEMONIC | DWT.DRAW_TAB | DWT.DRAW_TRANSPARENT | DWT.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 DWT
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 DWT
style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- *
+ * The style value is either one of the style constants defined in
+ * class DWT
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 DWT
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);
- /*
- * Return the lowercase of the first non-'&' character following
- * an '&' character in the given String. If there are no '&'
- * characters in the given String, return '\0'.
- */
- char _findMnemonic (String str)
- {
- if (str is null)
- return '\0';
- int index = 0;
- int length = str.length();
- do
- {
- while (index < length && str.charAt(index) !is '&')
- index++;
- if (++index >= length)
- return '\0';
- if (str.charAt(index) !is '&')
- return CharacterToLower(str.charAt(index));
- index++;
- } while (index < length);
- return '\0';
- }
-
- /**
- * Returns the alignnment.
- * The alignnment style (LEFT, CENTER or RIGHT) is returned.
- *
- * @return DWT.LEFT, DWT.RIGHT or DWT.CENTER
- */
- public int getAlignment ()
- {
- //checkWidget();
- return alignn;
+ if (image !is null) {
+ Rectangle r = image.getBounds();
+ size.x += r.width;
+ size.y += r.height;
}
- /**
- * Return the CLabel's image or null
.
- *
- * @return the image of the label or null
- */
- public Image getImage ()
- {
- //checkWidget();
- return image;
+ GC gc = new GC(this);
+ if (text !is 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 !is null) size.x += GAP;
+ } else {
+ size.y = Math.max(size.y, gc.getFontMetrics().getHeight());
}
+ gc.dispose();
+
+ return size;
+}
+public override int getStyle () {
+ int style = super.getStyle();
+ switch (align_) {
+ case DWT.RIGHT: style |= DWT.RIGHT; break;
+ case DWT.CENTER: style |= DWT.CENTER; break;
+ case DWT.LEFT: style |= DWT.LEFT; break;
+ default:
+ }
+ return style;
+}
- /**
- * Compute the minimum size.
- */
- private Point getTotalSize (Image image, String text)
- {
- Point size = new Point(0, 0);
+/**
+ * Return the Label's text.
+ *
+ * @return the text of the label or null
+ */
+public String getText() {
+ //checkWidget();
+ return text;
+}
+public override String getToolTipText () {
+ checkWidget();
+ return appToolTipText;
+}
+private void initAccessible() {
+ Accessible accessible = getAccessible();
+ accessible.addAccessibleListener(new class() AccessibleAdapter {
+ public void getName(AccessibleEvent e) {
+ e.result = getText();
+ }
- if (image !is null)
- {
- Rectangle r = image.getBounds();
- size.x += r.width;
- size.y += r.height;
+ public void getHelp(AccessibleEvent e) {
+ e.result = getToolTipText();
+ }
+
+ public void getKeyboardShortcut(AccessibleEvent e) {
+ dchar mnemonic = _findMnemonic(this.outer.text);
+ if (mnemonic !is '\0') {
+ dchar[1] d;
+ d[0] = mnemonic;
+ e.result = "Alt+" ~ tango.text.convert.Utf.toString(d); //$NON-NLS-1$
+ }
+ }
+ });
+
+ accessible.addAccessibleControlListener(new class() AccessibleControlAdapter {
+ public void getChildAtPoint(AccessibleControlEvent e) {
+ e.childID = ACC.CHILDID_SELF;
}
- GC gc = new GC(this);
- if (text !is 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 !is null)
- size.x += GAP;
+ 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;
}
- else
- {
- size.y = Math.max(size.y, gc.getFontMetrics().getHeight());
- }
- gc.dispose();
-
- return size;
- }
- public int getStyle ()
- {
- int style = super.getStyle();
- switch (alignn)
- {
- case DWT.RIGHT:
- style |= DWT.RIGHT;
- break;
- case DWT.CENTER:
- style |= DWT.CENTER;
- break;
- case DWT.LEFT:
- style |= DWT.LEFT;
- break;
+ public void getChildCount(AccessibleControlEvent e) {
+ e.detail = 0;
}
- return style;
- }
+
+ public void getRole(AccessibleControlEvent e) {
+ e.detail = ACC.ROLE_LABEL;
+ }
- /**
- * 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 class 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(this.text);
- if (mnemonic !is '\0')
- {
- e.result = "Alt+" + mnemonic; //$NON-NLS-1$
+ public void getState(AccessibleControlEvent e) {
+ e.detail = ACC.STATE_READONLY;
+ }
+ });
+}
+void onDispose(DisposeEvent event) {
+ gradientColors = null;
+ gradientPercents = null;
+ backgroundImage = null;
+ text = null;
+ image = null;
+ appToolTipText = null;
+}
+void onMnemonic(TraverseEvent event) {
+ dchar mnemonic = _findMnemonic(text);
+ if (mnemonic is '\0') return;
+ dchar[1] d; uint ate;
+ auto r = tango.text.convert.Utf.toString32( [event.character][], d, &ate );
+ if (tango.text.Unicode.toLower(r)[0] !is mnemonic) return;
+ Composite control = this.getParent();
+ while (control !is null) {
+ Control [] children = control.getChildren();
+ int index = 0;
+ while (index < children.length) {
+ if (children [index] is this) break;
+ index++;
+ }
+ index++;
+ if (index < children.length) {
+ if (children [index].setFocus ()) {
+ event.doit = true;
+ event.detail = DWT.TRAVERSE_NONE;
}
}
- } );
-
- accessible.addAccessibleControlListener(new class
- AccessibleControlAdapter
- {
- public void getChildAtPoint (AccessibleControlEvent e)
- {
- e.childID = ACC.CHILDID_SELF;
- }
+ control = control.getParent();
+ }
+}
- 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 onPaint(PaintEvent event) {
+ Rectangle rect = getClientArea();
+ if (rect.width is 0 || rect.height is 0) return;
- void onDispose (DisposeEvent event)
- {
- gradientColors = null;
- gradientPercents = null;
- backgroundImage = null;
- text = null;
- image = null;
- appToolTipText = null;
- }
-
- void onMnemonic (TraverseEvent event)
- {
- char mnemonic = _findMnemonic(text);
- if (mnemonic is '\0')
- return;
- if (CharacterToLower(event.character) !is mnemonic)
- return;
- Composite control = this.getParent();
- while (control !is null)
- {
- Control[] children = control.getChildren();
- int index = 0;
- while (index < children.length)
- {
- if (children[index] is this)
- break;
- index++;
- }
- index++;
- if (index < children.length)
- {
- if (children[index].setFocus())
- {
- event.doit = true;
- event.detail = DWT.TRAVERSE_NONE;
- }
- }
- control = control.getParent();
+ bool 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;
}
}
- void onPaint (PaintEvent event)
- {
- Rectangle rect = getClientArea();
- if (rect.width is 0 || rect.height is 0)
- return;
-
- bool 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 is null ? null : splitString(text);
- GC gc = event.gc;
- String[] lines = text is 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 is null)
- {
- super.setToolTipText(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);
}
}
- else
- {
- super.setToolTipText(appToolTipText);
+ if (appToolTipText is null) {
+ super.setToolTipText(text);
}
-
- // determine horizontal position
- int x = rect.x + hIndent;
- if (alignn is DWT.CENTER)
- {
- x = (rect.width - extent.x) / 2;
- }
- if (alignn is DWT.RIGHT)
- {
- x = rect.width - hIndent - extent.x;
- }
+ } else {
+ super.setToolTipText(appToolTipText);
+ }
- // draw a background image behind the text
- try
- {
- if (backgroundImage !is 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 !is null)
- {
- // draw a gradient behind the text
- const Color oldBackground = gc.getBackground();
- if (gradientColors.length is 1)
- {
- if (gradientColors[0] !is null)
- gc.setBackground(gradientColors[0]);
- gc.fillRectangle(0, 0, rect.width, rect.height);
+ // determine horizontal position
+ int x = rect.x + hIndent;
+ if (align_ is DWT.CENTER) {
+ x = (rect.width - extent.x)/2;
+ }
+ if (align_ is DWT.RIGHT) {
+ x = rect.width - hIndent - extent.x;
+ }
+
+ // draw a background image behind the text
+ try {
+ if (backgroundImage !is 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;
}
- else
- {
- const Color oldForeground = gc.getForeground();
- Color lastColor = gradientColors[0];
- if (lastColor is null)
- lastColor = oldBackground;
- int pos = 0;
- for (int i = 0; i < gradientPercents.length; ++i)
- {
- gc.setForeground(lastColor);
- lastColor = gradientColors[i + 1];
- if (lastColor is null)
- lastColor = oldBackground;
- gc.setBackground(lastColor);
- if (gradientVertical)
- {
- const int
- gradientHeight = (gradientPercents[i] * rect.height / 100) - pos;
- gc.fillGradientRectangle(0, pos, rect.width,
- gradientHeight, true);
- pos += gradientHeight;
- }
- else
- {
- const int
- gradientWidth = (gradientPercents[i] * rect.width / 100) - pos;
- gc.fillGradientRectangle(pos, 0, gradientWidth,
- rect.height, false);
- pos += gradientWidth;
- }
+ xPos += imageRect.width;
+ }
+ } else if (gradientColors !is null) {
+ // draw a gradient behind the text
+ final Color oldBackground = gc.getBackground();
+ if (gradientColors.length is 1) {
+ if (gradientColors[0] !is 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 is null) lastColor = oldBackground;
+ int pos = 0;
+ for (int i = 0; i < gradientPercents.length; ++i) {
+ gc.setForeground(lastColor);
+ lastColor = gradientColors[i + 1];
+ if (lastColor is 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);
+ }
+ if (gradientVertical && pos < rect.height) {
+ gc.setBackground(getBackground());
+ gc.fillRectangle(0, pos, rect.width, rect.height - pos);
}
- gc.setBackground(oldBackground);
+ if (!gradientVertical && pos < rect.width) {
+ gc.setBackground(getBackground());
+ gc.fillRectangle(pos, 0, rect.width - pos, rect.height);
+ }
+ gc.setForeground(oldForeground);
}
- else
- {
- if (background !is null || (getStyle() & DWT.DOUBLE_BUFFERED) is 0)
- {
- gc.setBackground(getBackground());
- gc.fillRectangle(rect);
- }
- }
- }
- catch (DWTException e)
- {
- if ((getStyle() & DWT.DOUBLE_BUFFERED) is 0)
- {
+ gc.setBackground(oldBackground);
+ } else {
+ if (background !is null || (getStyle() & DWT.DOUBLE_BUFFERED) is 0) {
gc.setBackground(getBackground());
gc.fillRectangle(rect);
}
}
+ } catch (DWTException e) {
+ if ((getStyle() & DWT.DOUBLE_BUFFERED) is 0) {
+ gc.setBackground(getBackground());
+ gc.fillRectangle(rect);
+ }
+ }
- // draw border
- int style = getStyle();
- if ((style & DWT.SHADOW_IN) !is 0 || (style & DWT.SHADOW_OUT) !is 0)
- {
- paintBorder(gc, rect);
- }
+ // draw border
+ int style = getStyle();
+ if ((style & DWT.SHADOW_IN) !is 0 || (style & DWT.SHADOW_OUT) !is 0) {
+ paintBorder(gc, rect);
+ }
- // draw the image
- if (img !is 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 image
+ if (img !is 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 !is 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_ is DWT.CENTER) {
+ int lineWidth = gc.textExtent(lines[i], DRAW_FLAGS).x;
+ lineX = x + Math.max(0, (extent.x - lineWidth) / 2);
+ }
+ if (align_ is DWT.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;
}
- // draw the text
- if (lines !is 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 (alignn is DWT.CENTER)
- {
- int lineWidth = gc.textExtent(lines[i], DRAW_FLAGS).x;
- lineX = x + Math.max(0, (extent.x - lineWidth) / 2);
- }
- if (alignn is DWT.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 & DWT.SHADOW_IN) !is 0) {
+ c1 = disp.getSystemColor(DWT.COLOR_WIDGET_NORMAL_SHADOW);
+ c2 = disp.getSystemColor(DWT.COLOR_WIDGET_HIGHLIGHT_SHADOW);
+ }
+ if ((style & DWT.SHADOW_OUT) !is 0) {
+ c1 = disp.getSystemColor(DWT.COLOR_WIDGET_LIGHT_SHADOW);
+ c2 = disp.getSystemColor(DWT.COLOR_WIDGET_NORMAL_SHADOW);
+ }
+
+ if (c1 !is null && c2 !is 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 DWTException 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(DWT.COLOR_DARK_BLUE), + * display.getSystemColor(DWT.COLOR_BLUE), + * display.getSystemColor(DWT.COLOR_WHITE), + * display.getSystemColor(DWT.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 DWTException 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(DWT.COLOR_DARK_BLUE), + * display.getSystemColor(DWT.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 DWTException 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(DWT.COLOR_DARK_BLUE), - * display.getSystemColor(DWT.COLOR_BLUE), - * display.getSystemColor(DWT.COLOR_WHITE), - * display.getSystemColor(DWT.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 DWTException 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(DWT.COLOR_DARK_BLUE), - * display.getSystemColor(DWT.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 DWTException null
clears it.
+ *
+ * @param image the image to be displayed in the label or null
+ *
+ * @exception DWTException null
clears it.
+ *
+ * @param text the text to be displayed in the label or null
+ *
+ * @exception DWTException null
clears it.
- *
- * @param image the image to be displayed in the label or null
- *
- * @exception DWTException t
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 is 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[0 .. mid].dup;
+ 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;
}
}
-
- /**
- * Set the label's text.
- * The value null
clears it.
- *
- * @param text the text to be displayed in the label or null
- *
- * @exception DWTException t
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 is 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 is 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, DWT.MOVEMENT_CLUSTER);
- if (nextOffset !is offset)
- return layout.getPreviousOffset(nextOffset, DWT.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 is -1)
- {
- lines[lines.length - 1] = text.substring(start);
- }
- else
- {
- bool crlf = (pos > 0) && (text.charAt(pos - 1) is '\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 !is -1);
- return lines;
- }
+ } while (pos !is text.length);
+ return lines;
}
+}
diff -r fbe68c33eeee -r 6337764516f1 dwt/custom/CLayoutData.d
--- a/dwt/custom/CLayoutData.d Tue Oct 07 14:41:31 2008 +0200
+++ b/dwt/custom/CLayoutData.d Tue Oct 07 16:29:55 2008 +0200
@@ -1,4 +1,4 @@
-/*******************************************************************************
+/*******************************************************************************
* 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
@@ -7,12 +7,12 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
- *
* Port to the D programming language:
- * Jacob Carlborg - * Note: Only one of the styles TOP and BOTTOM + * 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 DWT Example: CustomControlExample + * @see Sample code and further information */ -public class CTabFolder : Composite -{ +public class CTabFolder : Composite { /** * marginWidth specifies the number of pixels of horizontal margin @@ -94,43 +102,43 @@ public int marginHeight = 0; /** - * A multiple of the tab height that specifies the minimum width to which a tab + * 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); + public static RGB borderInsideRGB; /** * 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); + public static RGB borderMiddleRGB; /** * 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); + public static RGB borderOutsideRGB; /* sizing, positioning */ int xClient, yClient; @@ -142,17 +150,17 @@ int minChars = 20; /* item management */ - CTabItem items[] = new CTabItem[0]; + CTabItem items[]; int firstIndex = -1; // index of the left most visible tab. int selectedIndex = -1; - int[] priority = new int[0]; + int[] priority; bool mru = false; Listener listener; /* External Listener management */ - CTabFolder2Listener[] folderListeners = new CTabFolder2Listener[0]; + CTabFolder2Listener[] folderListeners; // support for deprecated listener mechanism - CTabFolderListener[] tabListeners = new CTabFolderListener[0]; + CTabFolderListener[] tabListeners; /* Selected item appearance */ Image selectionBgImage; @@ -160,17 +168,17 @@ int[] selectionGradientPercents; bool selectionGradientVertical; Color selectionForeground; - Color selectionBackground; //selection fade end + Color selectionBackground; //selection fade end Color selectionFadeStart; - Color selectionHighlightGradientBegin = null; //null is no highlight + Color selectionHighlightGradientBegin = null; //null is 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 + Color[] selectionHighlightGradientColorsCache = null; //null is a legal value, check on access /* Unselected item appearance */ Image bgImage; @@ -185,23 +193,23 @@ bool showClose = false; bool showUnselectedClose = true; - Rectangle chevronRect = new Rectangle(0, 0, 0, 0); + Rectangle chevronRect; int chevronImageState = NORMAL; bool showChevron = false; Menu showMenu; bool showMin = false; - Rectangle minRect = new Rectangle(0, 0, 0, 0); + Rectangle minRect; bool minimized = false; int minImageState = NORMAL; bool showMax = false; - Rectangle maxRect = new Rectangle(0, 0, 0, 0); + Rectangle maxRect; bool maximized = false; int maxImageState = NORMAL; Control topRight; - Rectangle topRightRect = new Rectangle(0, 0, 0, 0); + Rectangle topRightRect; int topRightAlignment = DWT.RIGHT; // borders and shapes @@ -219,7 +227,7 @@ int curveWidth = 0; int curveIndent = 0; - // when disposing CTabFolder, don't try to layout the items or + // when disposing CTabFolder, don't try to layout the items or // change the selection as each child is destroyed. bool inDispose = false; @@ -228,53 +236,36 @@ Point oldSize; Font oldFont; - // internal constants + // internal constants static const int DEFAULT_WIDTH = 64; static const int DEFAULT_HEIGHT = 64; static const int BUTTON_SIZE = 18; - static const int[] - TOP_LEFT_CORNER = new int[][0 , 6 , 1 , 5 , 1 , 4 , 4 , 1 , 5 , 1 , 6 , 0]; + static const int[] TOP_LEFT_CORNER = [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 const int[] - TOP_LEFT_CORNER_HILITE = new int[][5 , 2 , 4 , 2 , 3 , 3 , 2 , 4 , 2 , 5 , 1 , 6]; + //TOP_LEFT_CORNER_HILITE is laid out in reverse (ie. top to bottom) + //so can fade in same direction as right swoop curve + static const int[] TOP_LEFT_CORNER_HILITE = [5,2, 4,2, 3,3, 2,4, 2,5, 1,6]; - static const int[] - TOP_RIGHT_CORNER = new int[][-6 , 0 , -5 , 1 , -4 , 1 , -1 , 4 , -1 , 5 , 0 , 6]; - static const int[] - BOTTOM_LEFT_CORNER = new int[][0 , -6 , 1 , -5 , 1 , -4 , 4 , -1 , 5 , -1 , 6 , 0]; - static const int[] - BOTTOM_RIGHT_CORNER = new int[][-6 , 0 , -5 , -1 , -4 , -1 , -1 , -4 , -1 , -5 , 0 , -6]; + static const int[] TOP_RIGHT_CORNER = [-6,0, -5,1, -4,1, -1,4, -1,5, 0,6]; + static const int[] BOTTOM_LEFT_CORNER = [0,-6, 1,-5, 1,-4, 4,-1, 5,-1, 6,0]; + static const int[] BOTTOM_RIGHT_CORNER = [-6,0, -5,-1, -4,-1, -1,-4, -1,-5, 0,-6]; - static const int[] - SIMPLE_TOP_LEFT_CORNER = new int[][0 , 2 , 1 , 1 , 2 , 0]; - static const int[] - SIMPLE_TOP_RIGHT_CORNER = new int[][-2 , 0 , -1 , 1 , 0 , 2]; - static const int[] - SIMPLE_BOTTOM_LEFT_CORNER = new int[][0 , -2 , 1 , -1 , 2 , 0]; - static const int[] - SIMPLE_BOTTOM_RIGHT_CORNER = new int[][-2 , 0 , -1 , -1 , 0 , -2]; - static const int[] SIMPLE_UNSELECTED_INNER_CORNER = new int[][0 , 0]; + static const int[] SIMPLE_TOP_LEFT_CORNER = [0,2, 1,1, 2,0]; + static const int[] SIMPLE_TOP_RIGHT_CORNER = [-2,0, -1,1, 0,2]; + static const int[] SIMPLE_BOTTOM_LEFT_CORNER = [0,-2, 1,-1, 2,0]; + static const int[] SIMPLE_BOTTOM_RIGHT_CORNER = [-2,0, -1,-1, 0,-2]; + static const int[] SIMPLE_UNSELECTED_INNER_CORNER = [0,0]; - static const int[] - TOP_LEFT_CORNER_BORDERLESS = new int[][0 , 6 , 1 , 5 , 1 , 4 , 4 , 1 , 5 , 1 , 6 , 0]; - static const int[] - TOP_RIGHT_CORNER_BORDERLESS = new int[][-7 , 0 , -6 , 1 , -5 , 1 , -2 , 4 , -2 , 5 , -1 , 6]; - static const int[] - BOTTOM_LEFT_CORNER_BORDERLESS = new int[][0 , -6 , 1 , -6 , 1 , -5 , 2 , -4 , 4 , -2 , 5 , -1 , 6 , -1 , 6 , 0]; - static const int[] - BOTTOM_RIGHT_CORNER_BORDERLESS = new int[][-7 , 0 , -7 , -1 , -6 , -1 , -5 , -2 , -3 , -4 , -2 , -5 , -2 , -6 , -1 , -6]; + static const int[] TOP_LEFT_CORNER_BORDERLESS = [0,6, 1,5, 1,4, 4,1, 5,1, 6,0]; + static const int[] TOP_RIGHT_CORNER_BORDERLESS = [-7,0, -6,1, -5,1, -2,4, -2,5, -1,6]; + static const int[] BOTTOM_LEFT_CORNER_BORDERLESS = [0,-6, 1,-6, 1,-5, 2,-4, 4,-2, 5,-1, 6,-1, 6,0]; + static const int[] BOTTOM_RIGHT_CORNER_BORDERLESS = [-7,0, -7,-1, -6,-1, -5,-2, -3,-4, -2,-5, -2,-6, -1,-6]; - static const int[] - SIMPLE_TOP_LEFT_CORNER_BORDERLESS = new int[][0 , 2 , 1 , 1 , 2 , 0]; - static const int[] - SIMPLE_TOP_RIGHT_CORNER_BORDERLESS = new int[][-3 , 0 , -2 , 1 , -1 , 2]; - static const int[] - SIMPLE_BOTTOM_LEFT_CORNER_BORDERLESS = new int[][0 , -3 , 1 , -2 , 2 , -1 , 3 , 0]; - static const int[] - SIMPLE_BOTTOM_RIGHT_CORNER_BORDERLESS = new int[][-4 , 0 , -3 , -1 , -2 , -2 , -1 , -3]; + static const int[] SIMPLE_TOP_LEFT_CORNER_BORDERLESS = [0,2, 1,1, 2,0]; + static const int[] SIMPLE_TOP_RIGHT_CORNER_BORDERLESS= [-3,0, -2,1, -1,2]; + static const int[] SIMPLE_BOTTOM_LEFT_CORNER_BORDERLESS = [0,-3, 1,-2, 2,-1, 3,0]; + static const int[] SIMPLE_BOTTOM_RIGHT_CORNER_BORDERLESS = [-4,0, -3,-1, -2,-2, -1,-3]; static const int SELECTION_FOREGROUND = DWT.COLOR_LIST_FOREGROUND; static const int SELECTION_BACKGROUND = DWT.COLOR_LIST_BACKGROUND; @@ -288,2414 +279,2013 @@ static const int NORMAL = 1; static const int HOT = 2; static const int SELECTED = 3; - static const RGB CLOSE_FILL = new RGB(252, 160, 160); + static const RGB CLOSE_FILL; static const int CHEVRON_CHILD_ID = 0; static const int MINIMIZE_CHILD_ID = 1; static const int MAXIMIZE_CHILD_ID = 2; static const 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 DWT
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 DWT
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.
- *
+ * The style value is either one of the style constants defined in
+ * class DWT
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 DWT
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 DWTException true
if the receiver is minimized.
- *
- * @return the receiver's minimized state
- *
- * @exception DWTException true
if the minimize button
- * is visible.
- *
- * @return the visibility of the minimized button
- *
- * @exception DWTException true
if the receiver is maximized.
- * - * - * @return the receiver's maximized state - * - * @exception DWTException
true
if the maximize button
- * is visible.
- *
- * @return the visibility of the maximized button
- *
- * @exception DWTException 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 DWTExceptiontrue
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 bool 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 bool getSingle ()
- {
- checkWidget();
- return single;
+}
+/**
+ * Returns true
if the receiver's border is visible.
+ *
+ * @return the receiver's border visibility state
+ *
+ * @exception DWTException true
if the receiver is minimized.
+ *
+ * @return the receiver's minimized state
+ *
+ * @exception DWTException true
if the minimize button
+ * is visible.
+ *
+ * @return the visibility of the minimized button
+ *
+ * @exception DWTException true
if the receiver is maximized.
+ * + * + * @return the receiver's maximized state + * + * @exception DWTException
true
if the maximize button
+ * is visible.
+ *
+ * @return the visibility of the maximized button
+ *
+ * @exception DWTException 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 DWTExceptiontrue
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 bool 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 bool getSingle() {
+ checkWidget();
+ return single;
+}
- /**
- * Returns the control in the top right corner of the tab folder.
- * 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 tab folder or null
- *
- * @exception DWTException 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 bool 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 bool getUnselectedImageVisible ()
- {
- checkWidget();
- return showUnselectedImage;
+public override int getStyle() {
+ int style = super.getStyle();
+ style &= ~(DWT.TOP | DWT.BOTTOM);
+ style |= onBottom ? DWT.BOTTOM : DWT.TOP;
+ style &= ~(DWT.SINGLE | DWT.MULTI);
+ style |= single ? DWT.SINGLE : DWT.MULTI;
+ if (borderLeft !is 0) style |= DWT.BORDER;
+ style &= ~DWT.CLOSE;
+ if (showClose) style |= DWT.CLOSE;
+ return style;
+}
+/**
+ * Returns the height of the tab
+ *
+ * @return the height of the tab
+ *
+ * @exception DWTException 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 bool 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 bool 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(DWT.COLOR_DARK_BLUE), + * display.getSystemColor(DWT.COLOR_BLUE), + * display.getSystemColor(DWT.COLOR_WHITE), + * display.getSystemColor(DWT.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 DWTException + * cfolder.setBackground(new Color[]{display.getSystemColor(DWT.COLOR_DARK_BLUE), + * display.getSystemColor(DWT.COLOR_BLUE), + * display.getSystemColor(DWT.COLOR_WHITE), + * display.getSystemColor(DWT.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 DWTException - * cfolder.setBackground(new Color[]{display.getSystemColor(DWT.COLOR_DARK_BLUE), - * display.getSystemColor(DWT.COLOR_BLUE), - * display.getSystemColor(DWT.COLOR_WHITE), - * display.getSystemColor(DWT.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 DWTException - * cfolder.setBackground(new Color[]{display.getSystemColor(DWT.COLOR_DARK_BLUE), - * display.getSystemColor(DWT.COLOR_BLUE), - * display.getSystemColor(DWT.COLOR_WHITE), - * display.getSystemColor(DWT.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 DWTException true
,
- * and marks it invisible otherwise.
- *
- * @param visible the new visibility state
- *
- * @exception DWTException true
,
+ * and marks it invisible otherwise.
+ *
+ * @param visible the new visibility state
+ *
+ * @exception DWTException + * 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 DWTExceptiontrue
,
+ * and marks it invisible otherwise.
+ *
+ * @param visible the new visibility state
+ *
+ * @exception DWTException - * 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 DWTException+ * 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 DWTExceptiontrue
,
- * and marks it invisible otherwise.
- *
- * @param visible the new visibility state
- *
- * @exception DWTException + * cfolder.setBackground(new Color[]{display.getSystemColor(DWT.COLOR_DARK_BLUE), + * display.getSystemColor(DWT.COLOR_BLUE), + * display.getSystemColor(DWT.COLOR_WHITE), + * display.getSystemColor(DWT.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 DWTException + * cfolder.setBackground(new Color[]{display.getSystemColor(DWT.COLOR_DARK_BLUE), + * display.getSystemColor(DWT.COLOR_BLUE), + * display.getSystemColor(DWT.COLOR_WHITE), + * display.getSystemColor(DWT.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 DWTException - * 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 DWTExceptiontrue
if the CTabFolder should render itself in a simple, traditional style
+ *
+ * @exception DWTException true
if only the selected tab should be displayed otherwise, multiple tabs will be shown.
+ *
+ * @exception DWTException DWT.TOP
for tabs along the top or DWT.BOTTOM
for tabs along the bottom
+ *
+ * @exception DWTException
+ * The alignment parameter sets the layout of the control in the tab area.
+ * DWT.RIGHT
will cause the control to be positioned on the far
+ * right of the folder and it will have its default size. DWT.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.
+ *
DWT.RIGHT
or DWT.FILL
+ *
+ * @exception DWTException true
makes the close button appear
+ *
+ * @exception DWTException true
makes the image appear
+ *
+ * @exception DWTException - * cfolder.setBackground(new Color[]{display.getSystemColor(DWT.COLOR_DARK_BLUE), - * display.getSystemColor(DWT.COLOR_BLUE), - * display.getSystemColor(DWT.COLOR_WHITE), - * display.getSystemColor(DWT.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 DWTException - * cfolder.setBackground(new Color[]{display.getSystemColor(DWT.COLOR_DARK_BLUE), - * display.getSystemColor(DWT.COLOR_BLUE), - * display.getSystemColor(DWT.COLOR_WHITE), - * display.getSystemColor(DWT.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 DWTException true
if the CTabFolder should render itself in a simple, traditional style
- *
- * @exception DWTException true
if only the selected tab should be displayed otherwise, multiple tabs will be shown.
- *
- * @exception DWTException DWT.TOP
for tabs along the top or DWT.BOTTOM
for tabs along the bottom
- *
- * @exception DWTException
- * The alignment parameter sets the layout of the control in the tab area.
- * DWT.RIGHT
will cause the control to be positioned on the far
- * right of the folder and it will have its default size. DWT.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.
- *
DWT.RIGHT
or DWT.FILL
- *
- * @exception DWTException true
makes the close button appear
- *
- * @exception DWTException true
makes the image appear
- *
- * @exception DWTException CTabFolder2Listener
interface.
*
- * Classes that wish to dealF with CTabFolderEvent
s can
+ * 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 close button of an item in the CTabFolder. The item being closed is specified + * in the event.item field. Setting the event.doit field to false will stop the CTabItem from closing. + * When the CTabItem is closed, it is disposed. The contents of the CTabItem (see CTabItem#setControl) will be + * made not visible when the CTabItem is closed. + *+ * 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 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 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 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) { - } +/** + * 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 -r fbe68c33eeee -r 6337764516f1 dwt/custom/CTabFolder2Listener.d --- a/dwt/custom/CTabFolder2Listener.d Tue Oct 07 14:41:31 2008 +0200 +++ b/dwt/custom/CTabFolder2Listener.d Tue Oct 07 16:29:55 2008 +0200 @@ -1,4 +1,4 @@ -/******************************************************************************* +/******************************************************************************* * Copyright (c) 2000, 2004 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -7,18 +7,20 @@ * * Contributors: * IBM Corporation - initial API and implementation - * * Port to the D programming language: - * Jacob Carlborg
* After creating an instance of a class that :
@@ -31,86 +33,163 @@
*
* @see CTabFolder2Adapter
* @see CTabFolderEvent
- *
+ *
* @since 3.0
*/
public interface CTabFolder2Listener : DWTEventListener {
+ public enum {
+ MINIMIZE,
+ MAXIMIZE,
+ SHOWLIST,
+ RESTORE,
+ CLOSE
+ }
- /**
- * Sent when the user clicks on the close button of an item in the CTabFolder.
- * The item being closed is specified in the event.item field.
- * Setting the event.doit field to false will stop the CTabItem from closing.
- * When the CTabItem is closed, it is disposed. The contents of the
- * CTabItem (see CTabItem.setControl) will be made not visible when
- * the CTabItem is closed.
- *
- * @param event an event indicating the item being closed
- */
- public void close (CTabFolderEvent event);
+/**
+ * Sent when the user clicks on the close button of an item in the CTabFolder.
+ * The item being closed is specified in the event.item field.
+ * Setting the event.doit field to false will stop the CTabItem from closing.
+ * When the CTabItem is closed, it is disposed. The contents of the
+ * CTabItem (see CTabItem.setControl) will be made not visible when
+ * the CTabItem is closed.
+ *
+ * @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 state of the CTabFolder does not change automatically - it
+ * is up to the application to change the state of the CTabFolder
+ * in response to this event using CTabFolder.setMinimized(true).
+ *
+ * @param event an event containing information about the minimize
+ *
+ * @see CTabFolder#getMinimized()
+ * @see CTabFolder#setMinimized(bool)
+ * @see CTabFolder#setMinimizeVisible(bool)
+ */
+public void minimize(CTabFolderEvent event);
- /**
- * Sent when the user clicks on the minimize button of a CTabFolder.
- * The state of the CTabFolder does not change automatically - it
- * is up to the application to change the state of the CTabFolder
- * in response to this event using CTabFolder.setMinimized(true).
- *
- * @param event an event containing information about the minimize
- *
- * @see CTabFolder#getMinimized()
- * @see CTabFolder#setMinimized(bool)
- * @see CTabFolder#setMinimizeVisible(bool)
- */
- public void minimize (CTabFolderEvent event);
+/**
+ * Sent when the user clicks on the maximize button of a CTabFolder.
+ * The state of the CTabFolder does not change automatically - it
+ * is up to the application to change the state of the CTabFolder
+ * in response to this event using CTabFolder.setMaximized(true).
+ *
+ * @param event an event containing information about the maximize
+ *
+ * @see CTabFolder#getMaximized()
+ * @see CTabFolder#setMaximized(bool)
+ * @see CTabFolder#setMaximizeVisible(bool)
+ */
+public void maximize(CTabFolderEvent event);
+
+/**
+ * Sent when the user clicks on the restore button of a CTabFolder.
+ * This event is sent either to restore the CTabFolder from the
+ * minimized state or from the maximized state. To determine
+ * which restore is requested, use CTabFolder.getMinimized() or
+ * CTabFolder.getMaximized() to determine the current state.
+ * The state of the CTabFolder does not change automatically - it
+ * is up to the application to change the state of the CTabFolder
+ * in response to this event using CTabFolder.setMaximized(false)
+ * or CTabFolder.setMinimized(false).
+ *
+ * @param event an event containing information about the restore
+ *
+ * @see CTabFolder#getMinimized()
+ * @see CTabFolder#getMaximized()
+ * @see CTabFolder#setMinimized(bool)
+ * @see CTabFolder#setMinimizeVisible(bool)
+ * @see CTabFolder#setMaximized(bool)
+ * @see CTabFolder#setMaximizeVisible(bool)
+ */
+public void restore(CTabFolderEvent event);
- /**
- * Sent when the user clicks on the maximize button of a CTabFolder.
- * The state of the CTabFolder does not change automatically - it
- * is up to the application to change the state of the CTabFolder
- * in response to this event using CTabFolder.setMaximized(true).
- *
- * @param event an event containing information about the maximize
- *
- * @see CTabFolder#getMaximized()
- * @see CTabFolder#setMaximized(bool)
- * @see CTabFolder#setMaximizeVisible(bool)
- */
- public void maximize (CTabFolderEvent event);
+/**
+ * Sent when the user clicks on the chevron button of the CTabFolder.
+ * A chevron appears in the CTabFolder when there are more tabs
+ * than can be displayed at the current widget size. To select a
+ * tab that is not currently visible, the user clicks on the
+ * chevron and selects a tab item from a list. By default, the
+ * CTabFolder provides a list of all the items that are not currently
+ * visible, however, the application can provide its own list by setting
+ * the event.doit field to
* IMPORTANT: This class is not intended to be subclassed.
*
- * The style value is either one of the style constants defined in
- * class
+ * The style value is either one of the style constants defined in
+ * class
+ * The style value is either one of the style constants defined in
+ * class
- * The style value is either one of the style constants defined in
- * class Here is an example of using a ControlEditor:
- *
- * Here is an example of using a ControlEditor:
+*
+* Note: The Control provided as the editor must be created with its parent
- * being the Composite specified in the ControlEditor constructor.
- *
- * @param editor the Control that is displayed above the composite being edited
- */
- public void setEditor (Control editor) {
-
- if (editor is null) {
- // this is the case where the caller is setting the editor to be blank
- // set all the values accordingly
- this.editor = null;
- return;
- }
-
- this.editor = editor;
- layout();
- if (this.editor is null || this.editor.isDisposed())
- return;
- editor.setVisible(true);
- }
+ this.editor = editor;
+ layout();
+ if (this.editor is null || this.editor.isDisposed()) return;
+ editor.setVisible(true);
}
+}
diff -r fbe68c33eeee -r 6337764516f1 dwt/custom/DefaultContent.d
--- a/dwt/custom/DefaultContent.d Tue Oct 07 14:41:31 2008 +0200
+++ b/dwt/custom/DefaultContent.d Tue Oct 07 16:29:55 2008 +0200
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2007 IBM Corporation and others.
+ * 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
@@ -7,39 +7,52 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ * Frank Benoit
@@ -49,19 +62,19 @@
*/
void addLineIndex(int start, int length) {
int size = lines.length;
- if (lineCount is size) {
+ if (lineCount_ is size) {
// expand the lines by powers of 2
- int[][] newLines = new int[size+Compatibility.pow2(expandExp)][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++;
+ int[] range = [start, length];
+ lines[lineCount_] = range;
+ lineCount_++;
}
-/**
- * Adds a line index to the end of
*
@@ -75,19 +88,19 @@
int size = linesArray.length;
int[][] newLines = linesArray;
if (count is size) {
- newLines = new int[size+Compatibility.pow2(replaceExpandExp)][2];
+ newLines = new int[][]( size+Compatibility.pow2(replaceExpandExp), 2 );
replaceExpandExp++;
System.arraycopy(linesArray, 0, newLines, 0, size);
}
- int[] range = new int[] {start, length};
+ int[] range = [start, length];
newLines[count] = range;
return newLines;
}
/**
- * Adds a
*
@@ -99,8 +112,8 @@
public void addTextChangeListener(TextChangeListener listener) {
if (listener is null) error(DWT.ERROR_NULL_ARGUMENT);
StyledTextListener typedListener = new StyledTextListener(listener);
- textListeners.addElement(typedListener);
-}
+ textListeners ~= typedListener;
+}
/**
* Adjusts the gap to accommodate a text change that is occurring.
*
@@ -124,16 +137,16 @@
moveAndResizeGap(position, sizeHint, line);
}
/**
- * Calculates the indexes of each line in the text store. Assumes no gap exists.
+ * 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;
+ lineCount_ = 0;
int textLength = textStore.length;
int i;
for (i = start; i < textLength; i++) {
- char ch = textStore[i];
+ char ch = textStore[i];
if (ch is DWT.CR) {
// see if the next character is a LF
if (i + 1 < textLength) {
@@ -151,8 +164,8 @@
}
addLineIndex(start, i - start);
}
-/**
- * Returns whether or not the given character is a line delimiter. Both CR and LF
+/**
+ * Returns whether or not the given character is a line delimiter. Both CR and LF
* are valid line delimiters.
*
*
@@ -163,7 +176,7 @@
if (ch is DWT.CR) return true;
if (ch is DWT.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.
@@ -179,30 +192,30 @@
// inserting text, see if the \r\n line delimiter is being split
if (start is 0) return true;
if (start is getCharCount()) return true;
- char before = getTextRange(start - 1, 1).charAt(0);
+ char before = getTextRange(start - 1, 1)[0];
if (before is '\r') {
- char after = getTextRange(start, 1).charAt(0);
+ char after = getTextRange(start, 1)[0];
if (after is '\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);
+ char startChar = getTextRange(start, 1)[0];
if (startChar is '\n') {
// see if char before delete position is \r
if (start !is 0) {
- char before = getTextRange(start - 1, 1).charAt(0);
+ char before = getTextRange(start - 1, 1)[0];
if (before is '\r') return false;
}
}
- char endChar = getTextRange(start + replaceLength - 1, 1).charAt(0);
+ char endChar = getTextRange(start + replaceLength - 1, 1)[0];
if (endChar is '\r') {
// see if char after delete position is \n
if (start + replaceLength !is getCharCount()) {
- char after = getTextRange(start + replaceLength, 1).charAt(0);
+ char after = getTextRange(start + replaceLength, 1)[0];
if (after is '\n') return false;
}
}
- }
+ }
return true;
}
/**
@@ -213,44 +226,44 @@
* @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
+ * @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[][] indexedLines = new int[][]( numLines, 2 );
int start = 0;
- int lineCount = 0;
+ int lineCount_ = 0;
int i;
replaceExpandExp = 1;
for (i = start; i < length; i++) {
- int location = i + offset;
+ int location = i + offset;
if ((location >= gapStart) && (location < gapEnd)) {
// ignore the gap
} else {
- char ch = textStore[location];
+ char ch = textStore[location];
if (ch is DWT.CR) {
// see if the next character is a LF
if (location+1 < textStore.length) {
ch = textStore[location+1];
if (ch is DWT.LF) {
i++;
- }
+ }
}
- indexedLines = addLineIndex(start, i - start + 1, indexedLines, lineCount);
- lineCount++;
+ indexedLines = addLineIndex(start, i - start + 1, indexedLines, lineCount_);
+ lineCount_++;
start = i + 1;
} else if (ch is DWT.LF) {
- indexedLines = addLineIndex(start, i - start + 1, indexedLines, lineCount);
- lineCount++;
+ 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;
+ int[][] newLines = new int[][]( lineCount_+1, 2 );
+ System.arraycopy(indexedLines, 0, newLines, 0, lineCount_);
+ int[] range = [start, i - start];
+ newLines[lineCount_] = range;
+ return newLines;
}
/**
* Inserts text.
@@ -259,30 +272,30 @@
* @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() is 0) return;
-
+void insert(int position, String text) {
+ if (text.length is 0) return;
+
int startLine = getLineAtOffset(position);
- int change = text.length();
+ int change = text.length;
bool endInsert = position is 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
+ // 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();
-
+ int startLineLength = getPhysicalLine(startLine).length;
+
if (change > 0) {
- // shrink gap
+ // shrink gap
gapStart += (change);
- for (int i = 0; i < text.length(); i++) {
- textStore[position + i]= text.charAt(i);
+ for (int i = 0; i < text.length; i++) {
+ textStore[position + i]= text[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
@@ -292,17 +305,17 @@
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
+ // 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--) {
+ for (int i = lineCount_ - 1; i > startLine; i--) {
lines[i + numNewLines]=lines[i];
}
// insert the new lines
@@ -315,13 +328,13 @@
newLines[numNewLines][0] += startLineOffset;
lines[startLine + numNewLines] = newLines[numNewLines];
}
-
- lineCount += 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
+ * 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.
*
*
@@ -343,11 +356,11 @@
// 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++) {
+ for (int i = gapLine + 1; i < lineCount_; i++) {
lines[i][0] = lines[i][0] - oldSize;
}
}
-
+
if (newSize < 0) {
if (oldSize > 0) {
// removing the gap
@@ -364,7 +377,7 @@
int newGapEnd = newGapStart + newSize;
if (oldSize is 0) {
System.arraycopy(textStore, 0, content, 0, newGapStart);
- System.arraycopy(textStore, newGapStart, content, newGapEnd, content.length - newGapEnd);
+ System.arraycopy(textStore, newGapStart, content, newGapEnd, content.length - newGapEnd);
} else if (newGapStart < gapStart) {
int delta = gapStart - newGapStart;
System.arraycopy(textStore, 0, content, 0, newGapStart);
@@ -379,7 +392,7 @@
textStore = content;
gapStart = newGapStart;
gapEnd = newGapEnd;
-
+
// add the new gap to the lines information
if (gapExists()) {
gapLine = newGapLine;
@@ -387,12 +400,12 @@
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++) {
+ 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.
*
*
@@ -404,7 +417,7 @@
if (length is 0) {
return 0;
}
- int lineCount = 0;
+ int lineCount_ = 0;
int count = 0;
int i = startOffset;
if (i >= gapStart) {
@@ -414,7 +427,7 @@
if ((i >= gapStart) && (i < gapEnd)) {
// ignore the gap
} else {
- char ch = textStore[i];
+ char ch = textStore[i];
if (ch is DWT.CR) {
// see if the next character is a LF
if (i + 1 < textStore.length) {
@@ -422,19 +435,19 @@
if (ch is DWT.LF) {
i++;
count++;
- }
- }
- lineCount++;
+ }
+ }
+ lineCount_++;
} else if (ch is DWT.LF) {
- lineCount++;
+ lineCount_++;
}
count++;
}
i++;
}
- return lineCount;
+ return lineCount_;
}
-/**
+/**
* Returns the number of lines that are in the specified text.
*
*
@@ -442,20 +455,20 @@
* @return number of lines in the text
*/
int lineCount(String text){
- int lineCount = 0;
- int length = text.length();
+ int lineCount_ = 0;
+ int length = text.length;
for (int i = 0; i < length; i++) {
- char ch = text.charAt(i);
+ char ch = text[i];
if (ch is DWT.CR) {
- if (i + 1 < length && text.charAt(i + 1) is DWT.LF) {
+ if (i + 1 < length && text[i + 1] is DWT.LF) {
i++;
}
- lineCount++;
+ lineCount_++;
} else if (ch is DWT.LF) {
- lineCount++;
+ lineCount_++;
}
}
- return lineCount;
+ return lineCount_;
}
/**
* @return the logical length of the text store
@@ -475,31 +488,31 @@
*
*/
public String getLine(int index) {
- if ((index >= lineCount) || (index < 0)) error(DWT.ERROR_INVALID_ARGUMENT);
+ if ((index >= lineCount_) || (index < 0)) error(DWT.ERROR_INVALID_ARGUMENT);
int start = lines[index][0];
- int length = lines[index][1];
- int end = start + length - 1;
+ 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--;
+ while ((length_ - 1 >= 0) && isDelimiter(textStore[start+length_-1])) {
+ length_--;
}
- return new String(textStore, start, length);
+ return textStore[ start .. start + length_].dup;
} 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--;
+ buf.append(textStore[ start .. gapStart ] );
+ buf.append(textStore[ gapEnd .. gapEnd + length_ - gapLength - (gapStart - start) ]);
+ length_ = buf.length;
+ while ((length_ - 1 >=0) && isDelimiter(buf.slice[length_ - 1])) {
+ length_--;
}
- return buf.toString().substring(0, length);
+ return buf.toString()[ 0 .. length_ ].dup;
}
}
/**
- * Returns the line delimiter that should be used by the StyledText
+ * 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
@@ -518,18 +531,18 @@
*/
String getFullLine(int index) {
int start = lines[index][0];
- int length = lines[index][1];
- int end = start + length - 1;
+ 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);
+ return textStore[ start .. start + length_ ].dup;
} 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();
+ buffer.append(textStore[ start .. gapStart ]);
+ buffer.append(textStore[ gapEnd .. gapEnd + length_ - gapLength - (gapStart - start) ]);
+ return buffer.toString().dup;
}
}
/**
@@ -537,18 +550,18 @@
*
*
* @param index the line index
- * @return the physical line
+ * @return the physical line
*/
String getPhysicalLine(int index) {
int start = lines[index][0];
- int length = lines[index][1];
- return getPhysicalText(start, length);
+ int length_ = lines[index][1];
+ return getPhysicalText(start, length_);
}
/**
* @return the number of lines in the text store
*/
public int getLineCount(){
- return lineCount;
+ return lineCount_;
}
/**
* Returns the line at the given offset.
@@ -571,18 +584,18 @@
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
+ // 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 is lines[lastLine][0] + lines[lastLine][1])
+ if (lineCount_ > 0) {
+ int lastLine = lineCount_ - 1;
+ if (position is lines[lastLine][0] + lines[lastLine][1])
return lastLine;
}
- int high = lineCount;
+ int high = lineCount_;
int low = -1;
- int index = lineCount;
+ int index = lineCount_;
while (high - low > 1) {
index = (high + low) / 2;
int lineStart = lines[index][0];
@@ -606,9 +619,9 @@
* @return the line index
*/
int getLineAtPhysicalOffset(int position){
- int high = lineCount;
+ int high = lineCount_;
int low = -1;
- int index = lineCount;
+ int index = lineCount_;
while (high - low > 1) {
index = (high + low) / 2;
int lineStart = lines[index][0];
@@ -628,7 +641,7 @@
* Returns the logical offset of the given line.
*
*
- * @param lineIndex index of 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
@@ -653,14 +666,14 @@
*/
void expandLinesBy(int numLines) {
int size = lines.length;
- if (size - lineCount >= numLines) {
+ if (size - lineCount_ >= numLines) {
return;
}
- int[][] newLines = new int[size+Math.max(10, numLines)][2];
+ int[][] newLines = new int[][]( size+Math.max(10, numLines), 2 );
System.arraycopy(lines, 0, newLines, 0, size);
lines = newLines;
}
-/**
+/**
* Reports an DWT error.
*
*
@@ -669,7 +682,7 @@
void error (int code) {
DWT.error(code);
}
-/**
+/**
* Returns whether or not a gap exists in the text store.
*
*
@@ -679,7 +692,7 @@
return gapStart !is gapEnd;
}
/**
- * Returns a String representing the continuous content of
+ * Returns a string representing the continuous content of
* the text store.
*
*
@@ -687,11 +700,11 @@
* @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);
+String getPhysicalText(int start, int length_) {
+ return textStore[ start .. start + length_ ].dup;
}
/**
- * Returns a String representing the logical content of
+ * Returns a string representing the logical content of
* the text store (i.e., gap stripped out).
*
*
@@ -699,72 +712,73 @@
* @param length the logical length of the text to return
* @return the text
*/
-public String getTextRange(int start, int length) {
+public String getTextRange(int start, int length_) {
if (textStore is null)
return "";
- if (length is 0)
+ if (length_ is 0)
return "";
- int end= start + length;
+ int end= start + length_;
if (!gapExists() || (end < gapStart))
- return new String(textStore, start, length);
+ return textStore[ start .. start + length_].dup;
if (gapStart < start) {
int gapLength= gapEnd - gapStart;
- return new String(textStore, start + gapLength , length);
+ return textStore[ start + gapLength .. start + gapLength + length_ ].dup;
}
StringBuffer buf = new StringBuffer();
- buf.append(textStore, start, gapStart - start);
- buf.append(textStore, gapEnd, end - gapStart);
- return buf.toString();
+ buf.append(textStore[ start .. start + gapStart - start ] );
+ buf.append(textStore[ gapEnd .. gapEnd + end - gapStart ] );
+ return buf.toString().dup;
}
/**
* Removes the specified
*
- * @param listener the listener
+ * @param listener the listener which should no longer be notified
+ *
* @exception IllegalArgumentException
*
- * When sending the TextChangingEvent,
*
* @param text the text
*/
public void setText (String text){
- textStore = text.toCharArray();
+ textStore = text.dup;
gapStart = -1;
gapEnd = -1;
expandExp = 1;
@@ -819,32 +833,32 @@
* @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 is 0) return;
-
+void delete_(int position, int length_, int numLines) {
+ if (length_ is 0) return;
+
int startLine = getLineAtOffset(position);
int startLineOffset = getOffsetAtLine(startLine);
- int endLine = getLineAtOffset(position + length);
+ int endLine = getLineAtOffset(position + length_);
String endText = "";
bool splittingDelimiter = false;
- if (position + length < getCharCount()) {
- endText = getTextRange(position + length - 1, 2);
- if ((endText.charAt(0) is DWT.CR) && (endText.charAt(1) is DWT.LF)) {
+ if (position + length_ < getCharCount()) {
+ endText = getTextRange(position + length_ - 1, 2);
+ if ((endText[0] is DWT.CR) && (endText[1] is DWT.LF)) {
splittingDelimiter = true;
}
}
- adjustGap(position + length, -length, startLine);
- int [][] oldLines = indexLines(position, length + (gapEnd - gapStart), numLines);
-
+ 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 is gapStart) {
- gapStart -= length;
+ if (position + length_ is gapStart) {
+ gapStart -= length_;
} else {
- gapEnd += length;
- }
+ gapEnd += length_;
+ }
// figure out the length of the new concatenated line, do so by
// finding the first line delimiter after position
@@ -860,7 +874,7 @@
}
}
eol = true;
- }
+ }
}
j++;
}
@@ -871,10 +885,39 @@
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++) {
+ for (int i = endLine + 1; i < lineCount_; i++) {
lines[i - numOldLines] = lines[i];
}
- lineCount -= numOldLines;
- gapLine = getLineAtPhysicalOffset(gapStart);
+ lineCount_ -= numOldLines;
+ gapLine = getLineAtPhysicalOffset(gapStart);
}
+
+/++
+ + DWT extension
+ +/
+int utf8AdjustOffset( int offset ){
+ if (textStore is null)
+ return offset;
+ if (offset is 0)
+ return offset;
+ if( offset >= textStore.length ){
+ return offset;
+ }
+ if (!gapExists() || (offset < gapStart)){
+ while( textStore[offset] & 0xC0 is 0x80 ){
+ offset--;
+ }
+ return offset;
+ }
+ int gapLength= gapEnd - gapStart;
+ if( offset+gapLength >= textStore.length ){
+ return offset;
+ }
+ while( textStore[offset+gapLength] & 0xC0 is 0x80 ){
+ offset--;
+ }
+ return offset;
}
+
+
+}
diff -r fbe68c33eeee -r 6337764516f1 dwt/custom/ExtendedModifyEvent.d
--- a/dwt/custom/ExtendedModifyEvent.d Tue Oct 07 14:41:31 2008 +0200
+++ b/dwt/custom/ExtendedModifyEvent.d Tue Oct 07 16:29:55 2008 +0200
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * 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
@@ -7,26 +7,39 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ * Frank Benoit
diff -r fbe68c33eeee -r 6337764516f1 dwt/custom/LineBackgroundEvent.d
--- a/dwt/custom/LineBackgroundEvent.d Tue Oct 07 14:41:31 2008 +0200
+++ b/dwt/custom/LineBackgroundEvent.d Tue Oct 07 16:29:55 2008 +0200
@@ -1,5 +1,5 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 IBM Corporation and others.
+/*******************************************************************************
+ * 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
@@ -7,36 +7,50 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ * Frank Benoit
* The following event fields are used:
* The following event fields are used:
* The following event fields are used:
-* 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.
+* 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
+* @param string the text of the item
*
* @exception DWTException 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);
+}
+
+
+
+/// Helper class for the dgListener template function
+private class _DgCTabFolder2ListenerT(Dg,T...) : CTabFolder2Listener {
+
+ alias ParameterTupleOf!(Dg) DgArgs;
+ static assert( is(DgArgs == Tuple!(CTabFolderEvent,T)),
+ "Delegate args not correct: "~DgArgs.stringof~" vs. (Event,"~T.stringof~")" );
+
+ Dg dg;
+ T t;
+ int type;
+
+ private this( int type, Dg dg, T t ){
+ this.type = type;
+ this.dg = dg;
+ static if( T.length > 0 ){
+ this.t = t;
+ }
+ }
- /**
- * Sent when the user clicks on the restore button of a CTabFolder.
- * This event is sent either to restore the CTabFolder from the
- * minimized state or from the maximized state. To determine
- * which restore is requested, use CTabFolder.getMinimized() or
- * CTabFolder.getMaximized() to determine the current state.
- * The state of the CTabFolder does not change automatically - it
- * is up to the application to change the state of the CTabFolder
- * in response to this event using CTabFolder.setMaximized(false)
- * or CTabFolder.setMinimized(false).
- *
- * @param event an event containing information about the restore
- *
- * @see CTabFolder#getMinimized()
- * @see CTabFolder#getMaximized()
- * @see CTabFolder#setMinimized(bool)
- * @see CTabFolder#setMinimizeVisible(bool)
- * @see CTabFolder#setMaximized(bool)
- * @see CTabFolder#setMaximizeVisible(bool)
- */
- public void restore (CTabFolderEvent event);
+ void itemClosed( CTabFolderEvent e ){
+ dg(e,t);
+ }
+ public void close(CTabFolderEvent e){
+ if( type is CTabFolder2Listener.CLOSE ){
+ dg(e,t);
+ }
+ }
+ public void minimize(CTabFolderEvent e){
+ if( type is CTabFolder2Listener.MINIMIZE ){
+ dg(e,t);
+ }
+ }
+ public void maximize(CTabFolderEvent e){
+ if( type is CTabFolder2Listener.MAXIMIZE ){
+ dg(e,t);
+ }
+ }
+ public void restore(CTabFolderEvent e){
+ if( type is CTabFolder2Listener.RESTORE ){
+ dg(e,t);
+ }
+ }
+ public void showList(CTabFolderEvent e){
+ if( type is CTabFolder2Listener.SHOWLIST ){
+ dg(e,t);
+ }
+ }
+}
- /**
- * Sent when the user clicks on the chevron button of the CTabFolder.
- * A chevron appears in the CTabFolder when there are more tabs
- * than can be displayed at the current widget size. To select a
- * tab that is not currently visible, the user clicks on the
- * chevron and selects a tab item from a list. By default, the
- * CTabFolder provides a list of all the items that are not currently
- * visible, however, the application can provide its own list by setting
- * the event.doit field to 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);
+/++
+ + dgListener creates a class implementing the Listener interface and delegating the call to
+ + handleEvent to the users delegate. This template function will store also additional parameters.
+ +
+ + Examle of usage:
+ + ---
+ + void handleTextEvent ( Event e, int inset ) {
+ + // ...
+ + }
+ + text.addListener (DWT.FocusOut, dgListener( &handleTextEvent, inset ));
+ + ---
+ +/
+CTabFolder2Listener dgCTabFolder2Listener( Dg, T... )( int type, Dg dg, T args ){
+ return new _DgCTabFolder2ListenerT!( Dg, T )( type, dg, args );
}
+
+
+
diff -r fbe68c33eeee -r 6337764516f1 dwt/custom/CTabFolderAdapter.d
--- a/dwt/custom/CTabFolderAdapter.d Tue Oct 07 14:41:31 2008 +0200
+++ b/dwt/custom/CTabFolderAdapter.d Tue Oct 07 16:29:55 2008 +0200
@@ -1,5 +1,5 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
+/*******************************************************************************
+ * 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
@@ -7,16 +7,22 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
- *
* Port to the D programming language:
- * Jacob Carlborg CTabFolderListener
interface.
+ *
+ * @see CTabFolderListener
+ * @see CTabFolderEvent
+ * @see Sample code and further information
+ */
public class CTabFolderAdapter : CTabFolderListener {
- public void itemClosed (CTabFolderEvent event) {
- }
+ public void itemClosed(CTabFolderEvent event){}
}
diff -r fbe68c33eeee -r 6337764516f1 dwt/custom/CTabFolderEvent.d
--- a/dwt/custom/CTabFolderEvent.d Tue Oct 07 14:41:31 2008 +0200
+++ b/dwt/custom/CTabFolderEvent.d Tue Oct 07 16:29:55 2008 +0200
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * 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
@@ -7,19 +7,24 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
- *
* Port to the D programming language:
- * Jacob Carlborg
*
* CTabFolder
) and a style value
- * describing its behavior and appearance. The item is added
- * to the end of the items maintained by its parent.
- * DWT
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 DWT
style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- *
- *
- * @exception DWTException
- *
- *
- * @see DWT
- * @see Widget#getStyle()
- */
- public this (CTabFolder parent, int style) {
- this(parent, style, parent.getItemCount());
- }
+/**
+ * Constructs a new instance of this class given its parent
+ * (which must be a CTabFolder
) and a style value
+ * describing its behavior and appearance. The item is added
+ * to the end of the items maintained by its parent.
+ * DWT
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 DWT
style constants. The class description
+ * lists the style constants that are applicable to the class.
+ * Style bits are also inherited from superclasses.
+ *
+ *
+ * @exception DWTException
+ *
+ *
+ * @see DWT
+ * @see Widget#getStyle()
+ */
+public this (CTabFolder parent, int style) {
+ this(parent, style, parent.getItemCount());
+}
+/**
+ * Constructs a new instance of this class given its parent
+ * (which must be a CTabFolder
), a style value
+ * describing its behavior and appearance, and the index
+ * at which to place it in the items maintained by its parent.
+ * DWT
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 DWT
style constants. The class description
+ * lists the style constants that are applicable to the class.
+ * Style bits are also inherited from superclasses.
+ *
+ *
+ * @exception DWTException
+ *
+ *
+ * @see DWT
+ * @see Widget#getStyle()
+ */
+public this (CTabFolder parent, int style, int index) {
+ closeRect = new Rectangle(0, 0, 0, 0);
+ super (parent, style);
+ showClose = (style & DWT.CLOSE) !is 0;
+ parent.createItem (this, index);
+}
+
+/*
+ * Return whether to use ellipses or just truncate labels
+ */
+bool useEllipses() {
+ return parent.simple;
+}
+
+String shortenText(GC gc, String text, int width) {
+ return useEllipses()
+ ? shortenText(gc, text, width, ELLIPSIS)
+ : shortenText(gc, text, width, ""); //$NON-NLS-1$
+}
- /**
- * Constructs a new instance of this class given its parent
- * (which must be a CTabFolder
), a style value
- * describing its behavior and appearance, and the index
- * at which to place it in the items maintained by its parent.
- * DWT
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 DWT
style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- *
- *
- * @exception DWTException
- *
- *
- * @see DWT
- * @see Widget#getStyle()
- */
- public this (CTabFolder parent, int style, int index) {
- super(parent, style);
- showClose = (style & DWT.CLOSE) !is 0;
- parent.createItem(this, index);
+String shortenText(GC gc, String text, int width, String ellipses) {
+ if (gc.textExtent(text, FLAGS).x <= width) return text;
+ int ellipseWidth = gc.textExtent(ellipses, FLAGS).x;
+ int length = text.length;
+ TextLayout layout = new TextLayout(getDisplay());
+ layout.setText(text);
+ int end = layout.getPreviousOffset(length, DWT.MOVEMENT_CLUSTER);
+ while (end > 0) {
+ text = text[ 0 .. end ];
+ int l = gc.textExtent(text, FLAGS).x;
+ if (l + ellipseWidth <= width) {
+ break;
+ }
+ end = layout.getPreviousOffset(end, DWT.MOVEMENT_CLUSTER);
}
+ layout.dispose();
+ return end is 0 ? text.substring(0, 1) : text ~ ellipses;
+}
- /*
- * Return whether to use ellipses or just truncate labels
- */
- bool useEllipses () {
- return parent.simple;
+public override void dispose() {
+ if (isDisposed ()) return;
+ //if (!isValidThread ()) error (DWT.ERROR_THREAD_INVALID_ACCESS);
+ parent.destroyItem(this);
+ super.dispose();
+ parent = null;
+ control = null;
+ toolTipText = null;
+ shortenedText = null;
+ font = null;
+}
+void drawClose(GC gc) {
+ if (closeRect.width is 0 || closeRect.height is 0) return;
+ Display display = getDisplay();
+
+ // draw X 9x9
+ int indent = Math.max(1, (CTabFolder.BUTTON_SIZE-9)/2);
+ int x = closeRect.x + indent;
+ int y = closeRect.y + indent;
+ y += parent.onBottom ? -1 : 1;
+
+ Color closeBorder = display.getSystemColor(CTabFolder.BUTTON_BORDER);
+ switch (closeImageState) {
+ case CTabFolder.NORMAL: {
+ int[] shape = [x,y, x+2,y, x+4,y+2, x+5,y+2, x+7,y, x+9,y,
+ x+9,y+2, x+7,y+4, x+7,y+5, x+9,y+7, x+9,y+9,
+ x+7,y+9, x+5,y+7, x+4,y+7, x+2,y+9, x,y+9,
+ x,y+7, x+2,y+5, x+2,y+4, x,y+2];
+ gc.setBackground(display.getSystemColor(CTabFolder.BUTTON_FILL));
+ gc.fillPolygon(shape);
+ gc.setForeground(closeBorder);
+ gc.drawPolygon(shape);
+ break;
+ }
+ case CTabFolder.HOT: {
+ int[] shape = [x,y, x+2,y, x+4,y+2, x+5,y+2, x+7,y, x+9,y,
+ x+9,y+2, x+7,y+4, x+7,y+5, x+9,y+7, x+9,y+9,
+ x+7,y+9, x+5,y+7, x+4,y+7, x+2,y+9, x,y+9,
+ x,y+7, x+2,y+5, x+2,y+4, x,y+2];
+ Color fill = new Color(display, CTabFolder.CLOSE_FILL);
+ gc.setBackground(fill);
+ gc.fillPolygon(shape);
+ fill.dispose();
+ gc.setForeground(closeBorder);
+ gc.drawPolygon(shape);
+ break;
+ }
+ case CTabFolder.SELECTED: {
+ int[] shape = [x+1,y+1, x+3,y+1, x+5,y+3, x+6,y+3, x+8,y+1, x+10,y+1,
+ x+10,y+3, x+8,y+5, x+8,y+6, x+10,y+8, x+10,y+10,
+ x+8,y+10, x+6,y+8, x+5,y+8, x+3,y+10, x+1,y+10,
+ x+1,y+8, x+3,y+6, x+3,y+5, x+1,y+3];
+ Color fill = new Color(display, CTabFolder.CLOSE_FILL);
+ gc.setBackground(fill);
+ gc.fillPolygon(shape);
+ fill.dispose();
+ gc.setForeground(closeBorder);
+ gc.drawPolygon(shape);
+ break;
+ }
+ case CTabFolder.NONE: {
+ int[] shape = [x,y, x+10,y, x+10,y+10, x,y+10];
+ if (parent.gradientColors !is null && !parent.gradientVertical) {
+ parent.drawBackground(gc, shape, false);
+ } else {
+ Color defaultBackground = parent.getBackground();
+ Image image = parent.bgImage;
+ Color[] colors = parent.gradientColors;
+ int[] percents = parent.gradientPercents;
+ bool vertical = parent.gradientVertical;
+ parent.drawBackground(gc, shape, x, y, 10, 10, defaultBackground, image, colors, percents, vertical);
+ }
+ break;
+ }
+ default:
}
+}
+void drawSelected(GC gc ) {
+ Point size = parent.getSize();
+ int rightEdge = Math.min (x + width, parent.getRightItemEdge());
- String shortenText (GC gc, String text, int width) {
- return useEllipses() ? shortenText(gc, text, width, ELLIPSIS) : shortenText(gc, text, width, ""); //$NON-NLS-1$
+ // Draw selection border across all tabs
+ int xx = parent.borderLeft;
+ int yy = parent.onBottom ? size.y - parent.borderBottom - parent.tabHeight - parent.highlight_header : parent.borderTop + parent.tabHeight + 1;
+ int ww = size.x - parent.borderLeft - parent.borderRight;
+ int hh = parent.highlight_header - 1;
+ int[] shape = [xx,yy, xx+ww,yy, xx+ww,yy+hh, xx,yy+hh];
+ if (parent.selectionGradientColors !is null && !parent.selectionGradientVertical) {
+ parent.drawBackground(gc, shape, true);
+ } else {
+ gc.setBackground(parent.selectionBackground);
+ gc.fillRectangle(xx, yy, ww, hh);
}
- String shortenText (GC gc, String text, int width, String ellipses) {
- if (gc.textExtent(text, FLAGS).x <= width)
- return text;
- int ellipseWidth = gc.textExtent(ellipses, FLAGS).x;
- int length = text.length;
- TextLayout layout = new TextLayout(getDisplay());
- layout.setText(text);
- int end = layout.getPreviousOffset(length, DWT.MOVEMENT_CLUSTER);
- while (end > 0) {
- text = text.substring(0, end);
- int l = gc.textExtent(text, FLAGS).x;
- if (l + ellipseWidth <= width) {
- break;
- }
- end = layout.getPreviousOffset(end, DWT.MOVEMENT_CLUSTER);
+ if (parent.single) {
+ if (!showing) return;
+ } else {
+ // if selected tab scrolled out of view or partially out of view
+ // just draw bottom line
+ if (!showing){
+ int x1 = Math.max(0, parent.borderLeft - 1);
+ int y1 = (parent.onBottom) ? y - 1 : y + height;
+ int x2 = size.x - parent.borderRight;
+ gc.setForeground(CTabFolder.borderColor);
+ gc.drawLine(x1, y1, x2, y1);
+ return;
}
- layout.dispose();
- return end is 0 ? text.substring(0, 1) : text + ellipses;
- }
+
+ // draw selected tab background and outline
+ shape = null;
+ if (this.parent.onBottom) {
+ int[] left = parent.simple ? CTabFolder.SIMPLE_BOTTOM_LEFT_CORNER : CTabFolder.BOTTOM_LEFT_CORNER;
+ int[] right = parent.simple ? CTabFolder.SIMPLE_BOTTOM_RIGHT_CORNER : parent.curve;
+ if (parent.borderLeft is 0 && parent.indexOf(this) is parent.firstIndex) {
+ left = [x, y+height];
+ }
+ shape = new int[left.length+right.length+8];
+ int index = 0;
+ shape[index++] = x; // first point repeated here because below we reuse shape to draw outline
+ shape[index++] = y - 1;
+ shape[index++] = x;
+ shape[index++] = y - 1;
+ for (int i = 0; i < left.length/2; i++) {
+ shape[index++] = x + left[2*i];
+ shape[index++] = y + height + left[2*i+1] - 1;
+ }
+ for (int i = 0; i < right.length/2; i++) {
+ shape[index++] = parent.simple ? rightEdge - 1 + right[2*i] : rightEdge - parent.curveIndent + right[2*i];
+ shape[index++] = parent.simple ? y + height + right[2*i+1] - 1 : y + right[2*i+1] - 2;
+ }
+ shape[index++] = parent.simple ? rightEdge - 1 : rightEdge + parent.curveWidth - parent.curveIndent;
+ shape[index++] = y - 1;
+ shape[index++] = parent.simple ? rightEdge - 1 : rightEdge + parent.curveWidth - parent.curveIndent;
+ shape[index++] = y - 1;
+ } else {
+ int[] left = parent.simple ? CTabFolder.SIMPLE_TOP_LEFT_CORNER : CTabFolder.TOP_LEFT_CORNER;
+ int[] right = parent.simple ? CTabFolder.SIMPLE_TOP_RIGHT_CORNER : parent.curve;
+ if (parent.borderLeft is 0 && parent.indexOf(this) is parent.firstIndex) {
+ left = [x, y];
+ }
+ shape = new int[left.length+right.length+8];
+ int index = 0;
+ shape[index++] = x; // first point repeated here because below we reuse shape to draw outline
+ shape[index++] = y + height + 1;
+ shape[index++] = x;
+ shape[index++] = y + height + 1;
+ for (int i = 0; i < left.length/2; i++) {
+ shape[index++] = x + left[2*i];
+ shape[index++] = y + left[2*i+1];
+ }
+ for (int i = 0; i < right.length/2; i++) {
+ shape[index++] = parent.simple ? rightEdge - 1 + right[2*i] : rightEdge - parent.curveIndent + right[2*i];
+ shape[index++] = y + right[2*i+1];
+ }
+ shape[index++] = parent.simple ? rightEdge - 1 : rightEdge + parent.curveWidth - parent.curveIndent;
+ shape[index++] = y + height + 1;
+ shape[index++] = parent.simple ? rightEdge - 1 : rightEdge + parent.curveWidth - parent.curveIndent;
+ shape[index++] = y + height + 1;
+ }
- public void dispose () {
- if (isDisposed())
- return;
- //if (!isValidThread ()) error (DWT.ERROR_THREAD_INVALID_ACCESS);
- parent.destroyItem(this);
- super.dispose();
- parent = null;
- control = null;
- toolTipText = null;
- shortenedText = null;
- font = null;
+ Rectangle clipping = gc.getClipping();
+ Rectangle bounds = getBounds();
+ bounds.height += 1;
+ if (parent.onBottom) bounds.y -= 1;
+ bool tabInPaint = clipping.intersects(bounds);
+
+ if (tabInPaint) {
+ // fill in tab background
+ if (parent.selectionGradientColors !is null && !parent.selectionGradientVertical) {
+ parent.drawBackground(gc, shape, true);
+ } else {
+ Color defaultBackground = parent.selectionBackground;
+ Image image = parent.selectionBgImage;
+ Color[] colors = parent.selectionGradientColors;
+ int[] percents = parent.selectionGradientPercents;
+ bool vertical = parent.selectionGradientVertical;
+ xx = x;
+ yy = parent.onBottom ? y -1 : y + 1;
+ ww = width;
+ hh = height;
+ if (!parent.single && !parent.simple) ww += parent.curveWidth - parent.curveIndent;
+ parent.drawBackground(gc, shape, xx, yy, ww, hh, defaultBackground, image, colors, percents, vertical);
+ }
+ }
+
+ //Highlight MUST be drawn before the outline so that outline can cover it in the right spots (start of swoop)
+ //otherwise the curve looks jagged
+ drawHighlight(gc, rightEdge);
+
+ // draw outline
+ shape[0] = Math.max(0, parent.borderLeft - 1);
+ if (parent.borderLeft is 0 && parent.indexOf(this) is parent.firstIndex) {
+ shape[1] = parent.onBottom ? y + height - 1 : y;
+ shape[5] = shape[3] = shape[1];
+ }
+ shape[shape.length - 2] = size.x - parent.borderRight + 1;
+ for (int i = 0; i < shape.length/2; i++) {
+ if (shape[2*i + 1] is y + height + 1) shape[2*i + 1] -= 1;
+ }
+ RGB inside = parent.selectionBackground.getRGB();
+ if (parent.selectionBgImage !is null ||
+ (parent.selectionGradientColors !is null && parent.selectionGradientColors.length > 1)) {
+ inside = null;
+ }
+ RGB outside = parent.getBackground().getRGB();
+ if (parent.bgImage !is null ||
+ (parent.gradientColors !is null && parent.gradientColors.length > 1)) {
+ outside = null;
+ }
+ parent.antialias(shape, CTabFolder.borderColor.getRGB(), inside, outside, gc);
+ gc.setForeground(CTabFolder.borderColor);
+ gc.drawPolyline(shape);
+
+ if (!tabInPaint) return;
}
- void drawClose (GC gc) {
- if (closeRect.width is 0 || closeRect.height is 0)
- return;
- Display display = getDisplay();
-
- // draw X 9x9
- int indent = Math.max(1, (CTabFolder.BUTTON_SIZE - 9) / 2);
- int x = closeRect.x + indent;
- int y = closeRect.y + indent;
- y += parent.onBottom ? -1 : 1;
-
- Color closeBorder = display.getSystemColor(CTabFolder.BUTTON_BORDER);
- switch (closeImageState) {
- case CTabFolder.NORMAL: {
- int[] shape = new int[]
- {
- x , y , x + 2 , y , x + 4 , y + 2 , x + 5 , y + 2 , x + 7 , y , x + 9 , y , x + 9 , y + 2 , x + 7 , y + 4 , x + 7 , y + 5 , x + 9 , y + 7 , x + 9 , y + 9 , x + 7 , y + 9 , x + 5 , y + 7 , x + 4 , y + 7 , x + 2 , y + 9 , x , y + 9 , x , y + 7 , x + 2 , y + 5 , x + 2 , y + 4 , x , y + 2
- };
- gc.setBackground(display.getSystemColor(CTabFolder.BUTTON_FILL));
- gc.fillPolygon(shape);
- gc.setForeground(closeBorder);
- gc.drawPolygon(shape);
- break;
- }
- case CTabFolder.HOT: {
- int[] shape = new int[]
- {
- x , y , x + 2 , y , x + 4 , y + 2 , x + 5 , y + 2 , x + 7 , y , x + 9 , y , x + 9 , y + 2 , x + 7 , y + 4 , x + 7 , y + 5 , x + 9 , y + 7 , x + 9 , y + 9 , x + 7 , y + 9 , x + 5 , y + 7 , x + 4 , y + 7 , x + 2 , y + 9 , x , y + 9 , x , y + 7 , x + 2 , y + 5 , x + 2 , y + 4 , x , y + 2
- };
- Color fill = new Color(display, CTabFolder.CLOSE_FILL);
- gc.setBackground(fill);
- gc.fillPolygon(shape);
- fill.dispose();
- gc.setForeground(closeBorder);
- gc.drawPolygon(shape);
- break;
- }
- case CTabFolder.SELECTED: {
- int[] shape = new int[]
- {
- x + 1 , y + 1 , x + 3 , y + 1 , x + 5 , y + 3 , x + 6 , y + 3 , x + 8 , y + 1 , x + 10 , y + 1 , x + 10 , y + 3 , x + 8 , y + 5 , x + 8 , y + 6 , x + 10 , y + 8 , x + 10 , y + 10 , x + 8 , y + 10 , x + 6 , y + 8 , x + 5 , y + 8 , x + 3 , y + 10 , x + 1 , y + 10 , x + 1 , y + 8 , x + 3 , y + 6 , x + 3 , y + 5 , x + 1 , y + 3
- };
- Color fill = new Color(display, CTabFolder.CLOSE_FILL);
- gc.setBackground(fill);
- gc.fillPolygon(shape);
- fill.dispose();
- gc.setForeground(closeBorder);
- gc.drawPolygon(shape);
- break;
- }
- case CTabFolder.NONE: {
- int[] shape = new int[]
- {
- x , y , x + 10 , y , x + 10 , y + 10 , x , y + 10
- };
- if (parent.gradientColors !is null && !parent.gradientVertical) {
- parent.drawBackground(gc, shape, false);
- }
- else {
- Color defaultBackground = parent.getBackground();
- Image image = parent.bgImage;
- Color[] colors = parent.gradientColors;
- int[] percents = parent.gradientPercents;
- bool vertical = parent.gradientVertical;
- parent.drawBackground(gc, shape, x, y, 10, 10, defaultBackground, image, colors, percents, vertical);
- }
- break;
- }
+ // draw Image
+ int xDraw = x + LEFT_MARGIN;
+ if (parent.single && (parent.showClose || showClose)) xDraw += CTabFolder.BUTTON_SIZE;
+ Image image = getImage();
+ if (image !is null) {
+ Rectangle imageBounds = image.getBounds();
+ // only draw image if it won't overlap with close button
+ int maxImageWidth = rightEdge - xDraw - RIGHT_MARGIN;
+ if (!parent.single && closeRect.width > 0) maxImageWidth -= closeRect.width + INTERNAL_SPACING;
+ if (imageBounds.width < maxImageWidth) {
+ int imageX = xDraw;
+ int imageY = y + (height - imageBounds.height) / 2;
+ imageY += parent.onBottom ? -1 : 1;
+ gc.drawImage(image, imageX, imageY);
+ xDraw += imageBounds.width + INTERNAL_SPACING;
}
}
- void drawSelected (GC gc) {
- Point size = parent.getSize();
- int rightEdge = Math.min(x + width, parent.getRightItemEdge());
+ // draw Text
+ int textWidth = rightEdge - xDraw - RIGHT_MARGIN;
+ if (!parent.single && closeRect.width > 0) textWidth -= closeRect.width + INTERNAL_SPACING;
+ if (textWidth > 0) {
+ Font gcFont = gc.getFont();
+ gc.setFont(font is null ? parent.getFont() : font);
- // Draw selection border across all tabs
- int xx = parent.borderLeft;
- int
- yy = parent.onBottom ? size.y - parent.borderBottom - parent.tabHeight - parent.highlight_header : parent.borderTop + parent.tabHeight + 1;
- int ww = size.x - parent.borderLeft - parent.borderRight;
- int hh = parent.highlight_header - 1;
- int[] shape = new int[]
- {
- xx , yy , xx + ww , yy , xx + ww , yy + hh , xx , yy + hh
- };
- if (parent.selectionGradientColors !is null && !parent.selectionGradientVertical) {
- parent.drawBackground(gc, shape, true);
- }
- else {
- gc.setBackground(parent.selectionBackground);
- gc.fillRectangle(xx, yy, ww, hh);
- }
-
- if (parent.single) {
- if (!showing)
- return;
+ if (shortenedText is null || shortenedTextWidth !is textWidth) {
+ shortenedText = shortenText(gc, getText(), textWidth);
+ shortenedTextWidth = textWidth;
}
- else {
- // if selected tab scrolled out of view or partially out of view
- // just draw bottom line
- if (!showing) {
- int x1 = Math.max(0, parent.borderLeft - 1);
- int y1 = (parent.onBottom) ? y - 1 : y + height;
- int x2 = size.x - parent.borderRight;
- gc.setForeground(CTabFolder.borderColor);
- gc.drawLine(x1, y1, x2, y1);
- return;
- }
+ Point extent = gc.textExtent(shortenedText, FLAGS);
+ int textY = y + (height - extent.y) / 2;
+ textY += parent.onBottom ? -1 : 1;
+
+ gc.setForeground(parent.selectionForeground);
+ gc.drawText(shortenedText, xDraw, textY, FLAGS);
+ gc.setFont(gcFont);
- // draw selected tab background and outline
- shape = null;
- if (this.parent.onBottom) {
- int[] left = parent.simple ? CTabFolder.SIMPLE_BOTTOM_LEFT_CORNER : CTabFolder.BOTTOM_LEFT_CORNER;
- int[] right = parent.simple ? CTabFolder.SIMPLE_BOTTOM_RIGHT_CORNER : parent.curve;
- if (parent.borderLeft is 0 && parent.indexOf(this) is parent.firstIndex) {
- left = new int[]
- {
- x , y + height
- };
- }
- shape = new int[left.length + right.length + 8];
- int index = 0;
- shape[index++] = x; // first point repeated here because below we reuse shape to draw outline
- shape[index++] = y - 1;
- shape[index++] = x;
- shape[index++] = y - 1;
- for (int i = 0; i < left.length / 2; i++) {
- shape[index++] = x + left[2 * i];
- shape[index++] = y + height + left[2 * i + 1] - 1;
- }
- for (int i = 0; i < right.length / 2; i++) {
- shape[index++] = parent.simple ? rightEdge - 1 + right[2 * i] : rightEdge - parent.curveIndent + right[2 * i];
- shape[index++] = parent.simple ? y + height + right[2 * i + 1] - 1 : y + right[2 * i + 1] - 2;
- }
- shape[index++] = parent.simple ? rightEdge - 1 : rightEdge + parent.curveWidth - parent.curveIndent;
- shape[index++] = y - 1;
- shape[index++] = parent.simple ? rightEdge - 1 : rightEdge + parent.curveWidth - parent.curveIndent;
- shape[index++] = y - 1;
+ // draw a Focus rectangle
+ if (parent.isFocusControl()) {
+ Display display = getDisplay();
+ if (parent.simple || parent.single) {
+ gc.setBackground(display.getSystemColor(DWT.COLOR_BLACK));
+ gc.setForeground(display.getSystemColor(DWT.COLOR_WHITE));
+ gc.drawFocus(xDraw-1, textY-1, extent.x+2, extent.y+2);
+ } else {
+ gc.setForeground(display.getSystemColor(CTabFolder.BUTTON_BORDER));
+ gc.drawLine(xDraw, textY+extent.y+1, xDraw+extent.x+1, textY+extent.y+1);
}
- else {
- int[] left = parent.simple ? CTabFolder.SIMPLE_TOP_LEFT_CORNER : CTabFolder.TOP_LEFT_CORNER;
- int[] right = parent.simple ? CTabFolder.SIMPLE_TOP_RIGHT_CORNER : parent.curve;
- if (parent.borderLeft is 0 && parent.indexOf(this) is parent.firstIndex) {
- left = new int[]
- {
- x , y
- };
- }
- shape = new int[left.length + right.length + 8];
- int index = 0;
- shape[index++] = x; // first point repeated here because below we reuse shape to draw outline
- shape[index++] = y + height + 1;
- shape[index++] = x;
- shape[index++] = y + height + 1;
- for (int i = 0; i < left.length / 2; i++) {
- shape[index++] = x + left[2 * i];
- shape[index++] = y + left[2 * i + 1];
- }
- for (int i = 0; i < right.length / 2; i++) {
- shape[index++] = parent.simple ? rightEdge - 1 + right[2 * i] : rightEdge - parent.curveIndent + right[2 * i];
- shape[index++] = y + right[2 * i + 1];
- }
- shape[index++] = parent.simple ? rightEdge - 1 : rightEdge + parent.curveWidth - parent.curveIndent;
- shape[index++] = y + height + 1;
- shape[index++] = parent.simple ? rightEdge - 1 : rightEdge + parent.curveWidth - parent.curveIndent;
- shape[index++] = y + height + 1;
- }
+ }
+ }
+ if (parent.showClose || showClose) drawClose(gc);
+}
+
+/*
+ * Draw a highlight effect along the left, top, and right edges of the tab.
+ * Only for curved tabs, on top.
+ * Do not draw if insufficient colors.
+ */
+void drawHighlight(GC gc, int rightEdge) {
+ //only draw for curvy tabs and only draw for top tabs
+ if(parent.simple || this.parent.onBottom)
+ return;
+
+ if(parent.selectionHighlightGradientBegin is null)
+ return;
+
+ Color[] gradients = parent.selectionHighlightGradientColorsCache;
+ if(gradients is null)
+ return;
+ int gradientsSize = gradients.length;
+ if(gradientsSize is 0)
+ return; //shouldn't happen but just to be tidy
+
+ gc.setForeground(gradients[0]);
- Rectangle clipping = gc.getClipping();
- Rectangle bounds = getBounds();
- bounds.height += 1;
- if (parent.onBottom)
- bounds.y -= 1;
- bool tabInPaint = clipping.intersects(bounds);
+ //draw top horizontal line
+ gc.drawLine(
+ CTabFolder.TOP_LEFT_CORNER_HILITE[0] + x + 1, //rely on fact that first pair is top/right of curve
+ 1 + y,
+ rightEdge - parent.curveIndent,
+ 1 + y);
+
+ int[] leftHighlightCurve = CTabFolder.TOP_LEFT_CORNER_HILITE;
+
+ int d = parent.tabHeight - parent.topCurveHighlightEnd.length /2;
+
+ int lastX = 0;
+ int lastY = 0;
+ int lastColorIndex = 0;
+
+ //draw upper left curve highlight
+ for (int i = 0; i < leftHighlightCurve.length /2; i++) {
+ int rawX = leftHighlightCurve[i * 2];
+ int rawY = leftHighlightCurve[i * 2 + 1];
+ lastX = rawX + x;
+ lastY = rawY + y;
+ lastColorIndex = rawY - 1;
+ gc.setForeground(gradients[lastColorIndex]);
+ gc.drawPoint(lastX, lastY);
+ }
+ //draw left vertical line highlight
+ for(int i = lastColorIndex; i < gradientsSize; i++) {
+ gc.setForeground(gradients[i]);
+ gc.drawPoint(lastX, 1 + lastY++);
+ }
+
+ int rightEdgeOffset = rightEdge - parent.curveIndent;
- if (tabInPaint) {
- // fill in tab background
- if (parent.selectionGradientColors !is null && !parent.selectionGradientVertical) {
- parent.drawBackground(gc, shape, true);
- }
- else {
- Color defaultBackground = parent.selectionBackground;
- Image image = parent.selectionBgImage;
- Color[] colors = parent.selectionGradientColors;
- int[] percents = parent.selectionGradientPercents;
- bool vertical = parent.selectionGradientVertical;
- xx = x;
- yy = parent.onBottom ? y - 1 : y + 1;
- ww = width;
- hh = height;
- if (!parent.single && !parent.simple)
- ww += parent.curveWidth - parent.curveIndent;
- parent.drawBackground(gc, shape, xx, yy, ww, hh, defaultBackground, image, colors, percents, vertical);
- }
- }
+ //draw right swoop highlight up to diagonal portion
+ for (int i = 0; i < parent.topCurveHighlightStart.length /2; i++) {
+ int rawX = parent.topCurveHighlightStart[i * 2];
+ int rawY = parent.topCurveHighlightStart[i * 2 + 1];
+ lastX = rawX + rightEdgeOffset;
+ lastY = rawY + y;
+ lastColorIndex = rawY - 1;
+ if(lastColorIndex >= gradientsSize)
+ break; //can happen if tabs are unusually short and cut off the curve
+ gc.setForeground(gradients[lastColorIndex]);
+ gc.drawPoint(lastX, lastY);
+ }
+ //draw right diagonal line highlight
+ for(int i = lastColorIndex; i < lastColorIndex + d; i++) {
+ if(i >= gradientsSize)
+ break; //can happen if tabs are unusually short and cut off the curve
+ gc.setForeground(gradients[i]);
+ gc.drawPoint(1 + lastX++, 1 + lastY++);
+ }
- //Highlight MUST be drawn before the outline so that outline can cover it in the right spots (start of swoop)
- //otherwise the curve looks jagged
- drawHighlight(gc, rightEdge);
+ //draw right swoop highlight from diagonal portion to end
+ for (int i = 0; i < parent.topCurveHighlightEnd.length /2; i++) {
+ int rawX = parent.topCurveHighlightEnd[i * 2]; //d is already encoded in this value
+ int rawY = parent.topCurveHighlightEnd[i * 2 + 1]; //d already encoded
+ lastX = rawX + rightEdgeOffset;
+ lastY = rawY + y;
+ lastColorIndex = rawY - 1;
+ if(lastColorIndex >= gradientsSize)
+ break; //can happen if tabs are unusually short and cut off the curve
+ gc.setForeground(gradients[lastColorIndex]);
+ gc.drawPoint(lastX, lastY);
+ }
+}
- // draw outline
- shape[0] = Math.max(0, parent.borderLeft - 1);
- if (parent.borderLeft is 0 && parent.indexOf(this) is parent.firstIndex) {
- shape[1] = parent.onBottom ? y + height - 1 : y;
- shape[5] = shape[3] = shape[1];
- }
- shape[shape.length - 2] = size.x - parent.borderRight + 1;
- for (int i = 0; i < shape.length / 2; i++) {
- if (shape[2 * i + 1] is y + height + 1)
- shape[2 * i + 1] -= 1;
- }
- RGB inside = parent.selectionBackground.getRGB();
- if (parent.selectionBgImage !is null || (parent.selectionGradientColors !is null && parent.selectionGradientColors.length > 1)) {
- inside = null;
- }
- RGB outside = parent.getBackground().getRGB();
- if (parent.bgImage !is null || (parent.gradientColors !is null && parent.gradientColors.length > 1)) {
- outside = null;
- }
- parent.antialias(shape, CTabFolder.borderColor.getRGB(), inside, outside, gc);
- gc.setForeground(CTabFolder.borderColor);
- gc.drawPolyline(shape);
+/*
+ * Draw the unselected border for the receiver on the right.
+ *
+ * @param gc
+ */
+void drawRightUnselectedBorder(GC gc) {
+
+ int[] shape = null;
+ int startX = x + width - 1;
+
+ if (this.parent.onBottom) {
+ int[] right = parent.simple
+ ? CTabFolder.SIMPLE_UNSELECTED_INNER_CORNER
+ : CTabFolder.BOTTOM_RIGHT_CORNER;
+
+ shape = new int[right.length + 2];
+ int index = 0;
- if (!tabInPaint)
- return;
+ for (int i = 0; i < right.length / 2; i++) {
+ shape[index++] = startX + right[2 * i];
+ shape[index++] = y + height + right[2 * i + 1] - 1;
+ }
+ shape[index++] = startX;
+ shape[index++] = y - 1;
+ } else {
+ int[] right = parent.simple
+ ? CTabFolder.SIMPLE_UNSELECTED_INNER_CORNER
+ : CTabFolder.TOP_RIGHT_CORNER;
+
+ shape = new int[right.length + 2];
+ int index = 0;
+
+ for (int i = 0; i < right.length / 2; i++) {
+ shape[index++] = startX + right[2 * i];
+ shape[index++] = y + right[2 * i + 1];
}
- // draw Image
- int xDraw = x + LEFT_MARGIN;
- if (parent.single && (parent.showClose || showClose))
- xDraw += CTabFolder.BUTTON_SIZE;
- Image image = getImage();
- if (image !is null) {
- Rectangle imageBounds = image.getBounds();
- // only draw image if it won't overlap with close button
- int maxImageWidth = rightEdge - xDraw - RIGHT_MARGIN;
- if (!parent.single && closeRect.width > 0)
- maxImageWidth -= closeRect.width + INTERNAL_SPACING;
- if (imageBounds.width < maxImageWidth) {
- int imageX = xDraw;
- int imageY = y + (height - imageBounds.height) / 2;
- imageY += parent.onBottom ? -1 : 1;
- gc.drawImage(image, imageX, imageY);
- xDraw += imageBounds.width + INTERNAL_SPACING;
- }
- }
-
- // draw Text
- int textWidth = rightEdge - xDraw - RIGHT_MARGIN;
- if (!parent.single && closeRect.width > 0)
- textWidth -= closeRect.width + INTERNAL_SPACING;
- if (textWidth > 0) {
- Font gcFont = gc.getFont();
- gc.setFont(font is null ? parent.getFont() : font);
-
- if (shortenedText is null || shortenedTextWidth !is textWidth) {
- shortenedText = shortenText(gc, getText(), textWidth);
- shortenedTextWidth = textWidth;
- }
- Point extent = gc.textExtent(shortenedText, FLAGS);
- int textY = y + (height - extent.y) / 2;
- textY += parent.onBottom ? -1 : 1;
-
- gc.setForeground(parent.selectionForeground);
- gc.drawText(shortenedText, xDraw, textY, FLAGS);
- gc.setFont(gcFont);
-
- // draw a Focus rectangle
- if (parent.isFocusControl()) {
- Display display = getDisplay();
- if (parent.simple || parent.single) {
- gc.setBackground(display.getSystemColor(DWT.COLOR_BLACK));
- gc.setForeground(display.getSystemColor(DWT.COLOR_WHITE));
- gc.drawFocus(xDraw - 1, textY - 1, extent.x + 2, extent.y + 2);
- }
- else {
- gc.setForeground(display.getSystemColor(CTabFolder.BUTTON_BORDER));
- gc.drawLine(xDraw, textY + extent.y + 1, xDraw + extent.x + 1, textY + extent.y + 1);
- }
- }
- }
- if (parent.showClose || showClose)
- drawClose(gc);
- }
-
- /*
- * Draw a highlight effect along the left, top, and right edges of the tab.
- * Only for curved tabs, on top.
- * Do not draw if insufficient colors.
- */
- void drawHighlight (GC gc, int rightEdge) {
- //only draw for curvy tabs and only draw for top tabs
- if (parent.simple || this.parent.onBottom)
- return;
-
- if (parent.selectionHighlightGradientBegin is null)
- return;
-
- Color[] gradients = parent.selectionHighlightGradientColorsCache;
- if (gradients is null)
- return;
- int gradientsSize = gradients.length;
- if (gradientsSize is 0)
- return; //shouldn't happen but just to be tidy
-
- gc.setForeground(gradients[0]);
-
- //draw top horizontal line
- gc.drawLine(CTabFolder.TOP_LEFT_CORNER_HILITE[0] + x + 1, //rely on fact that first pair is top/right of curve
- 1 + y, rightEdge - parent.curveIndent, 1 + y);
-
- int[] leftHighlightCurve = CTabFolder.TOP_LEFT_CORNER_HILITE;
-
- int d = parent.tabHeight - parent.topCurveHighlightEnd.length / 2;
-
- int lastX = 0;
- int lastY = 0;
- int lastColorIndex = 0;
-
- //draw upper left curve highlight
- for (int i = 0; i < leftHighlightCurve.length / 2; i++) {
- int rawX = leftHighlightCurve[i * 2];
- int rawY = leftHighlightCurve[i * 2 + 1];
- lastX = rawX + x;
- lastY = rawY + y;
- lastColorIndex = rawY - 1;
- gc.setForeground(gradients[lastColorIndex]);
- gc.drawPoint(lastX, lastY);
- }
- //draw left vertical line highlight
- for (int i = lastColorIndex; i < gradientsSize; i++) {
- gc.setForeground(gradients[i]);
- gc.drawPoint(lastX, 1 + lastY++);
- }
-
- int rightEdgeOffset = rightEdge - parent.curveIndent;
-
- //draw right swoop highlight up to diagonal portion
- for (int i = 0; i < parent.topCurveHighlightStart.length / 2; i++) {
- int rawX = parent.topCurveHighlightStart[i * 2];
- int rawY = parent.topCurveHighlightStart[i * 2 + 1];
- lastX = rawX + rightEdgeOffset;
- lastY = rawY + y;
- lastColorIndex = rawY - 1;
- if (lastColorIndex >= gradientsSize)
- break; //can happen if tabs are unusually short and cut off the curve
- gc.setForeground(gradients[lastColorIndex]);
- gc.drawPoint(lastX, lastY);
- }
- //draw right diagonal line highlight
- for (int i = lastColorIndex; i < lastColorIndex + d; i++) {
- if (i >= gradientsSize)
- break; //can happen if tabs are unusually short and cut off the curve
- gc.setForeground(gradients[i]);
- gc.drawPoint(1 + lastX++, 1 + lastY++);
- }
-
- //draw right swoop highlight from diagonal portion to end
- for (int i = 0; i < parent.topCurveHighlightEnd.length / 2; i++) {
- int rawX = parent.topCurveHighlightEnd[i * 2]; //d is already encoded in this value
- int rawY = parent.topCurveHighlightEnd[i * 2 + 1]; //d already encoded
- lastX = rawX + rightEdgeOffset;
- lastY = rawY + y;
- lastColorIndex = rawY - 1;
- if (lastColorIndex >= gradientsSize)
- break; //can happen if tabs are unusually short and cut off the curve
- gc.setForeground(gradients[lastColorIndex]);
- gc.drawPoint(lastX, lastY);
- }
- }
-
- /*
- * Draw the unselected border for the receiver on the right.
- *
- * @param gc
- */
- void drawRightUnselectedBorder (GC gc) {
-
- int[] shape = null;
- int startX = x + width - 1;
-
- if (this.parent.onBottom) {
- int[] right = parent.simple ? CTabFolder.SIMPLE_UNSELECTED_INNER_CORNER : CTabFolder.BOTTOM_RIGHT_CORNER;
-
- shape = new int[right.length + 2];
- int index = 0;
-
- for (int i = 0; i < right.length / 2; i++) {
- shape[index++] = startX + right[2 * i];
- shape[index++] = y + height + right[2 * i + 1] - 1;
- }
- shape[index++] = startX;
- shape[index++] = y - 1;
- }
- else {
- int[] right = parent.simple ? CTabFolder.SIMPLE_UNSELECTED_INNER_CORNER : CTabFolder.TOP_RIGHT_CORNER;
-
- shape = new int[right.length + 2];
- int index = 0;
-
- for (int i = 0; i < right.length / 2; i++) {
- shape[index++] = startX + right[2 * i];
- shape[index++] = y + right[2 * i + 1];
- }
-
- shape[index++] = startX;
- shape[index++] = y + height;
-
- }
-
- drawBorder(gc, shape);
+ shape[index++] = startX;
+ shape[index++] = y + height;
}
- /*
- * Draw the border of the tab
- *
- * @param gc
- * @param shape
- */
- void drawBorder (GC gc, int[] shape) {
+ drawBorder(gc, shape);
+
+}
- gc.setForeground(CTabFolder.borderColor);
- gc.drawPolyline(shape);
- }
+/*
+ * Draw the border of the tab
+ *
+ * @param gc
+ * @param shape
+ */
+void drawBorder(GC gc, int[] shape) {
- /*
- * Draw the unselected border for the receiver on the left.
- *
- * @param gc
- */
- void drawLeftUnselectedBorder (GC gc) {
+ gc.setForeground(CTabFolder.borderColor);
+ gc.drawPolyline(shape);
+}
+
+/*
+ * Draw the unselected border for the receiver on the left.
+ *
+ * @param gc
+ */
+void drawLeftUnselectedBorder(GC gc) {
- int[] shape = null;
- if (this.parent.onBottom) {
- int[] left = parent.simple ? CTabFolder.SIMPLE_UNSELECTED_INNER_CORNER : CTabFolder.BOTTOM_LEFT_CORNER;
+ int[] shape = null;
+ if (this.parent.onBottom) {
+ int[] left = parent.simple
+ ? CTabFolder.SIMPLE_UNSELECTED_INNER_CORNER
+ : CTabFolder.BOTTOM_LEFT_CORNER;
- shape = new int[left.length + 2];
- int index = 0;
- shape[index++] = x;
- shape[index++] = y - 1;
- for (int i = 0; i < left.length / 2; i++) {
- shape[index++] = x + left[2 * i];
- shape[index++] = y + height + left[2 * i + 1] - 1;
- }
+ shape = new int[left.length + 2];
+ int index = 0;
+ shape[index++] = x;
+ shape[index++] = y - 1;
+ for (int i = 0; i < left.length / 2; i++) {
+ shape[index++] = x + left[2 * i];
+ shape[index++] = y + height + left[2 * i + 1] - 1;
}
- else {
- int[] left = parent.simple ? CTabFolder.SIMPLE_UNSELECTED_INNER_CORNER : CTabFolder.TOP_LEFT_CORNER;
+ } else {
+ int[] left = parent.simple
+ ? CTabFolder.SIMPLE_UNSELECTED_INNER_CORNER
+ : CTabFolder.TOP_LEFT_CORNER;
- shape = new int[left.length + 2];
- int index = 0;
- shape[index++] = x;
- shape[index++] = y + height;
- for (int i = 0; i < left.length / 2; i++) {
- shape[index++] = x + left[2 * i];
- shape[index++] = y + left[2 * i + 1];
- }
-
+ shape = new int[left.length + 2];
+ int index = 0;
+ shape[index++] = x;
+ shape[index++] = y + height;
+ for (int i = 0; i < left.length / 2; i++) {
+ shape[index++] = x + left[2 * i];
+ shape[index++] = y + left[2 * i + 1];
}
- drawBorder(gc, shape);
- }
-
- void drawUnselected (GC gc) {
- // Do not draw partial items
- if (!showing)
- return;
-
- Rectangle clipping = gc.getClipping();
- Rectangle bounds = getBounds();
- if (!clipping.intersects(bounds))
- return;
-
- // draw border
- int index = parent.indexOf(this);
-
- if (index > 0 && index < parent.selectedIndex)
- drawLeftUnselectedBorder(gc);
- // If it is the last one then draw a line
- if (index > parent.selectedIndex)
- drawRightUnselectedBorder(gc);
-
- // draw Image
- int xDraw = x + LEFT_MARGIN;
- Image image = getImage();
- if (image !is null && parent.showUnselectedImage) {
- Rectangle imageBounds = image.getBounds();
- // only draw image if it won't overlap with close button
- int maxImageWidth = x + width - xDraw - RIGHT_MARGIN;
- if (parent.showUnselectedClose && (parent.showClose || showClose)) {
- maxImageWidth -= closeRect.width + INTERNAL_SPACING;
- }
- if (imageBounds.width < maxImageWidth) {
- int imageX = xDraw;
- int imageHeight = imageBounds.height;
- int imageY = y + (height - imageHeight) / 2;
- imageY += parent.onBottom ? -1 : 1;
- int imageWidth = imageBounds.width * imageHeight / imageBounds.height;
- gc.drawImage(image, imageBounds.x, imageBounds.y, imageBounds.width, imageBounds.height, imageX, imageY, imageWidth, imageHeight);
- xDraw += imageWidth + INTERNAL_SPACING;
- }
- }
- // draw Text
- int textWidth = x + width - xDraw - RIGHT_MARGIN;
- if (parent.showUnselectedClose && (parent.showClose || showClose)) {
- textWidth -= closeRect.width + INTERNAL_SPACING;
- }
- if (textWidth > 0) {
- Font gcFont = gc.getFont();
- gc.setFont(font is null ? parent.getFont() : font);
- if (shortenedText is null || shortenedTextWidth !is textWidth) {
- shortenedText = shortenText(gc, getText(), textWidth);
- shortenedTextWidth = textWidth;
- }
- Point extent = gc.textExtent(shortenedText, FLAGS);
- int textY = y + (height - extent.y) / 2;
- textY += parent.onBottom ? -1 : 1;
- gc.setForeground(parent.getForeground());
- gc.drawText(shortenedText, xDraw, textY, FLAGS);
- gc.setFont(gcFont);
- }
- // draw close
- if (parent.showUnselectedClose && (parent.showClose || showClose))
- drawClose(gc);
- }
-
- /**
- * Returns a rectangle describing the receiver's size and location
- * relative to its parent.
- *
- * @return the receiver's bounding column rectangle
- *
- * @exception DWTException
- *
- */
- public Rectangle getBounds () {
- //checkWidget();
- int w = width;
- if (!parent.simple && !parent.single && parent.indexOf(this) is parent.selectedIndex)
- w += parent.curveWidth - parent.curveIndent;
- return new Rectangle(x, y, w, height);
- }
-
- /**
- * Gets the control that is displayed in the content area of the tab item.
- *
- * @return the control
- *
- * @exception DWTException
- *
- */
- public Control getControl () {
- checkWidget();
- return control;
- }
-
- /**
- * Get the image displayed in the tab if the tab is disabled.
- *
- * @return the disabled image or null
- *
- * @exception DWTException
- *
- *
- * @deprecated the disabled image is not used
- */
- public Image getDisabledImage () {
- checkWidget();
- return disabledImage;
- }
-
- /**
- * Returns the font that the receiver will use to paint textual information.
- *
- * @return the receiver's font
- *
- * @exception DWTException
- *
- *
- * @since 3.0
- */
- public Font getFont () {
- checkWidget();
- if (font !is null)
- return font;
- return parent.getFont();
- }
-
- /**
- * Returns the receiver's parent, which must be a CTabFolder
.
- *
- * @return the receiver's parent
- *
- * @exception DWTException
- *
- */
- public CTabFolder getParent () {
- //checkWidget();
- return parent;
- }
-
- /**
- * Returns true
to indicate that the receiver's close button should be shown.
- * Otherwise return false
. The initial value is defined by the style (DWT.CLOSE)
- * that was used to create the receiver.
- *
- * @return true
if the close button should be shown
- *
- * @exception DWTException
- *
- *
- * @since 3.4
- */
- public bool getShowClose () {
- checkWidget();
- return showClose;
- }
-
- /**
- * Returns the receiver's tool tip text, or null if it has
- * not been set.
- *
- * @return the receiver's tool tip text
- *
- * @exception DWTException
- *
- */
- public String getToolTipText () {
- checkWidget();
- if (toolTipText is null && shortenedText !is null) {
- String text = getText();
- if (!shortenedText.opEquals(text))
- return text;
- }
- return toolTipText;
}
- /**
- * Returns 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 DWTException
- *
- *
- * @since 3.0
- */
- public bool isShowing () {
- checkWidget();
- return showing;
- }
+ drawBorder(gc, shape);
+}
+
+void drawUnselected(GC gc) {
+ // Do not draw partial items
+ if (!showing) return;
+
+ Rectangle clipping = gc.getClipping();
+ Rectangle bounds = getBounds();
+ if (!clipping.intersects(bounds)) return;
+
+ // draw border
+ int index = parent.indexOf(this);
+
+ if (index > 0 && index < parent.selectedIndex)
+ drawLeftUnselectedBorder(gc);
+ // If it is the last one then draw a line
+ if (index > parent.selectedIndex)
+ drawRightUnselectedBorder(gc);
- void onPaint (GC gc, bool isSelected) {
- if (width is 0 || height is 0)
- return;
- if (isSelected) {
- drawSelected(gc);
+ // draw Image
+ int xDraw = x + LEFT_MARGIN;
+ Image image = getImage();
+ if (image !is null && parent.showUnselectedImage) {
+ Rectangle imageBounds = image.getBounds();
+ // only draw image if it won't overlap with close button
+ int maxImageWidth = x + width - xDraw - RIGHT_MARGIN;
+ if (parent.showUnselectedClose && (parent.showClose || showClose)) {
+ maxImageWidth -= closeRect.width + INTERNAL_SPACING;
}
- else {
- drawUnselected(gc);
+ if (imageBounds.width < maxImageWidth) {
+ int imageX = xDraw;
+ int imageHeight = imageBounds.height;
+ int imageY = y + (height - imageHeight) / 2;
+ imageY += parent.onBottom ? -1 : 1;
+ int imageWidth = imageBounds.width * imageHeight / imageBounds.height;
+ gc.drawImage(image,
+ imageBounds.x, imageBounds.y, imageBounds.width, imageBounds.height,
+ imageX, imageY, imageWidth, imageHeight);
+ xDraw += imageWidth + INTERNAL_SPACING;
}
}
-
- int preferredHeight (GC gc) {
- Image image = getImage();
- int h = (image is null) ? 0 : image.getBounds().height;
+ // draw Text
+ int textWidth = x + width - xDraw - RIGHT_MARGIN;
+ if (parent.showUnselectedClose && (parent.showClose || showClose)) {
+ textWidth -= closeRect.width + INTERNAL_SPACING;
+ }
+ if (textWidth > 0) {
+ Font gcFont = gc.getFont();
+ gc.setFont(font is null ? parent.getFont() : font);
+ if (shortenedText is null || shortenedTextWidth !is textWidth) {
+ shortenedText = shortenText(gc, getText(), textWidth);
+ shortenedTextWidth = textWidth;
+ }
+ Point extent = gc.textExtent(shortenedText, FLAGS);
+ int textY = y + (height - extent.y) / 2;
+ textY += parent.onBottom ? -1 : 1;
+ gc.setForeground(parent.getForeground());
+ gc.drawText(shortenedText, xDraw, textY, FLAGS);
+ gc.setFont(gcFont);
+ }
+ // draw close
+ if (parent.showUnselectedClose && (parent.showClose || showClose)) drawClose(gc);
+}
+/**
+ * Returns a rectangle describing the receiver's size and location
+ * relative to its parent.
+ *
+ * @return the receiver's bounding column rectangle
+ *
+ * @exception DWTException
+ *
+ */
+public Rectangle getBounds () {
+ //checkWidget();
+ int w = width;
+ if (!parent.simple && !parent.single && parent.indexOf(this) is parent.selectedIndex) w += parent.curveWidth - parent.curveIndent;
+ return new Rectangle(x, y, w, height);
+}
+/**
+* Gets the control that is displayed in the content area of the tab item.
+*
+* @return the control
+*
+* @exception DWTException
+*
+*/
+public Control getControl () {
+ checkWidget();
+ return control;
+}
+/**
+ * Get the image displayed in the tab if the tab is disabled.
+ *
+ * @return the disabled image or null
+ *
+ * @exception DWTException
+ *
+ *
+ * @deprecated the disabled image is not used
+ */
+public Image getDisabledImage(){
+ checkWidget();
+ return disabledImage;
+}
+/**
+ * Returns the font that the receiver will use to paint textual information.
+ *
+ * @return the receiver's font
+ *
+ * @exception DWTException
+ *
+ *
+ * @since 3.0
+ */
+public Font getFont() {
+ checkWidget();
+ if (font !is null) return font;
+ return parent.getFont();
+}
+/**
+ * Returns the receiver's parent, which must be a CTabFolder
.
+ *
+ * @return the receiver's parent
+ *
+ * @exception DWTException
+ *
+ */
+public CTabFolder getParent () {
+ //checkWidget();
+ return parent;
+}
+/**
+ * Returns true
to indicate that the receiver's close button should be shown.
+ * Otherwise return false
. The initial value is defined by the style (DWT.CLOSE)
+ * that was used to create the receiver.
+ *
+ * @return true
if the close button should be shown
+ *
+ * @exception DWTException
+ *
+ *
+ * @since 3.4
+ */
+public bool getShowClose() {
+ checkWidget();
+ return showClose;
+}
+/**
+ * Returns the receiver's tool tip text, or null if it has
+ * not been set.
+ *
+ * @return the receiver's tool tip text
+ *
+ * @exception DWTException
+ *
+ */
+public String getToolTipText () {
+ checkWidget();
+ if (toolTipText is null && shortenedText !is null) {
String text = getText();
+ if (shortenedText!=text) return text;
+ }
+ return toolTipText;
+}
+/**
+* Returns 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 DWTException
+ *
+ *
+* @since 3.0
+*/
+public bool isShowing () {
+ checkWidget();
+ return showing;
+}
+void onPaint(GC gc, bool isSelected) {
+ if (width is 0 || height is 0) return;
+ if (isSelected) {
+ drawSelected(gc);
+ } else {
+ drawUnselected(gc);
+ }
+}
+int preferredHeight(GC gc) {
+ Image image = getImage();
+ int h = (image is null) ? 0 : image.getBounds().height;
+ String text = getText();
+ if (font is null) {
+ h = Math.max(h, gc.textExtent(text, FLAGS).y);
+ } else {
+ Font gcFont = gc.getFont();
+ gc.setFont(font);
+ h = Math.max(h, gc.textExtent(text, FLAGS).y);
+ gc.setFont(gcFont);
+ }
+ return h + TOP_MARGIN + BOTTOM_MARGIN;
+}
+int preferredWidth(GC gc, bool isSelected, bool minimum) {
+ // NOTE: preferred width does not include the "dead space" caused
+ // by the curve.
+ if (isDisposed()) return 0;
+ int w = 0;
+ Image image = getImage();
+ if (image !is null && (isSelected || parent.showUnselectedImage)) {
+ w += image.getBounds().width;
+ }
+ String text = null;
+ if (minimum) {
+ int minChars = parent.minChars;
+ text = minChars is 0 ? null : getText();
+ if (text !is null && text.length > minChars) {
+ if (useEllipses()) {
+ int end = minChars < ELLIPSIS.length + 1 ? minChars : minChars - ELLIPSIS.length;
+ text = text[ 0 .. end ];
+ if (minChars > ELLIPSIS.length + 1) text ~= ELLIPSIS;
+ } else {
+ int end = minChars;
+ text = text[ 0 .. end ];
+ }
+ }
+ } else {
+ text = getText();
+ }
+ if (text !is null) {
+ if (w > 0) w += INTERNAL_SPACING;
if (font is null) {
- h = Math.max(h, gc.textExtent(text, FLAGS).y);
- }
- else {
+ w += gc.textExtent(text, FLAGS).x;
+ } else {
Font gcFont = gc.getFont();
gc.setFont(font);
- h = Math.max(h, gc.textExtent(text, FLAGS).y);
+ w += gc.textExtent(text, FLAGS).x;
gc.setFont(gcFont);
}
- return h + TOP_MARGIN + BOTTOM_MARGIN;
}
-
- int preferredWidth (GC gc, bool isSelected, bool minimum) {
- // NOTE: preferred width does not include the "dead space" caused
- // by the curve.
- if (isDisposed())
- return 0;
- int w = 0;
- Image image = getImage();
- if (image !is null && (isSelected || parent.showUnselectedImage)) {
- w += image.getBounds().width;
- }
- String text = null;
- if (minimum) {
- int minChars = parent.minChars;
- text = minChars is 0 ? null : getText();
- if (text !is null && text.length() > minChars) {
- if (useEllipses()) {
- int end = minChars < ELLIPSIS.length() + 1 ? minChars : minChars - ELLIPSIS.length();
- text = text.substring(0, end);
- if (minChars > ELLIPSIS.length() + 1)
- text += ELLIPSIS;
- }
- else {
- int end = minChars;
- text = text.substring(0, end);
- }
- }
- }
- else {
- text = getText();
+ if (parent.showClose || showClose) {
+ if (isSelected || parent.showUnselectedClose) {
+ if (w > 0) w += INTERNAL_SPACING;
+ w += CTabFolder.BUTTON_SIZE;
}
- if (text !is null) {
- if (w > 0)
- w += INTERNAL_SPACING;
- if (font is null) {
- w += gc.textExtent(text, FLAGS).x;
- }
- else {
- Font gcFont = gc.getFont();
- gc.setFont(font);
- w += gc.textExtent(text, FLAGS).x;
- gc.setFont(gcFont);
- }
- }
- if (parent.showClose || showClose) {
- if (isSelected || parent.showUnselectedClose) {
- if (w > 0)
- w += INTERNAL_SPACING;
- w += CTabFolder.BUTTON_SIZE;
- }
- }
- return w + LEFT_MARGIN + RIGHT_MARGIN;
}
-
- /**
- * Sets the control that is used to fill the client area of
- * the tab folder when the user selects the tab item.
- *
- * @param control the new control (or null)
- *
- * @exception IllegalArgumentException
- *
- * @exception DWTException
- *
- */
- public void setControl (Control control) {
- checkWidget();
- if (control !is null) {
- if (control.isDisposed())
- DWT.error(DWT.ERROR_INVALID_ARGUMENT);
- if (control.getParent() !is parent)
- DWT.error(DWT.ERROR_INVALID_PARENT);
- }
- if (this.control !is null && !this.control.isDisposed()) {
+ return w + LEFT_MARGIN + RIGHT_MARGIN;
+}
+/**
+ * Sets the control that is used to fill the client area of
+ * the tab folder when the user selects the tab item.
+ *
+ * @param control the new control (or null)
+ *
+ * @exception IllegalArgumentException
+ *
+ * @exception DWTException
+ *
+ */
+public void setControl (Control control) {
+ checkWidget();
+ if (control !is null) {
+ if (control.isDisposed()) DWT.error (DWT.ERROR_INVALID_ARGUMENT);
+ if (control.getParent() !is parent) DWT.error (DWT.ERROR_INVALID_PARENT);
+ }
+ if (this.control !is null && !this.control.isDisposed()) {
+ this.control.setVisible(false);
+ }
+ this.control = control;
+ if (this.control !is null) {
+ int index = parent.indexOf (this);
+ if (index is parent.getSelectionIndex ()){
+ this.control.setBounds(parent.getClientArea ());
+ this.control.setVisible(true);
+ } else {
this.control.setVisible(false);
}
- this.control = control;
- if (this.control !is null) {
- int index = parent.indexOf(this);
- if (index is parent.getSelectionIndex()) {
- this.control.setBounds(parent.getClientArea());
- this.control.setVisible(true);
- }
- else {
- this.control.setVisible(false);
- }
- }
}
-
- /**
- * Sets the image that is displayed if the tab item is disabled.
- * Null will clear the image.
- *
- * @param image the image to be displayed when the item is disabled or null
- *
- * @exception DWTException
- *
- *
- * @deprecated This image is not used
- */
- public void setDisabledImage (Image image) {
- checkWidget();
- if (image !is null && image.isDisposed()) {
- DWT.error(DWT.ERROR_INVALID_ARGUMENT);
- }
- this.disabledImage = image;
- }
-
- /**
- * 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
- *
- * @exception DWTException
- *
- *
- * @since 3.0
- */
- public void setFont (Font font) {
- checkWidget();
- if (font !is null && font.isDisposed()) {
- DWT.error(DWT.ERROR_INVALID_ARGUMENT);
- }
- if (font is null && this.font is null)
- return;
- if (font !is null && font.opEquals(this.font))
- return;
- this.font = font;
- if (!parent.updateTabHeight(false)) {
- parent.updateItems();
- parent.redrawTabs();
- }
+}
+/**
+ * Sets the image that is displayed if the tab item is disabled.
+ * Null will clear the image.
+ *
+ * @param image the image to be displayed when the item is disabled or null
+ *
+ * @exception DWTException
+ *
+ *
+ * @deprecated This image is not used
+ */
+public void setDisabledImage (Image image) {
+ checkWidget();
+ if (image !is null && image.isDisposed ()) {
+ DWT.error(DWT.ERROR_INVALID_ARGUMENT);
}
-
- public void setImage (Image image) {
- checkWidget();
- if (image !is null && image.isDisposed()) {
- DWT.error(DWT.ERROR_INVALID_ARGUMENT);
- }
- Image oldImage = getImage();
- if (image is null && oldImage is null)
- return;
- if (image !is null && image.opEquals(oldImage))
- return;
- super.setImage(image);
- if (!parent.updateTabHeight(false)) {
- // If image is the same size as before,
- // redraw only the image
- if (oldImage !is null && image !is null) {
- Rectangle oldBounds = oldImage.getBounds();
- Rectangle bounds = image.getBounds();
- if (bounds.width is oldBounds.width && bounds.height is oldBounds.height) {
- if (showing) {
- bool selected = parent.indexOf(this) is parent.selectedIndex;
- if (selected || parent.showUnselectedImage) {
- int imageX = x + LEFT_MARGIN, maxImageWidth;
- if (selected) {
- if (parent.single && (parent.showClose || showClose))
- imageX += CTabFolder.BUTTON_SIZE;
- int rightEdge = Math.min(x + width, parent.getRightItemEdge());
- maxImageWidth = rightEdge - imageX - RIGHT_MARGIN;
- if (!parent.single && closeRect.width > 0)
- maxImageWidth -= closeRect.width + INTERNAL_SPACING;
- }
- else {
- maxImageWidth = x + width - imageX - RIGHT_MARGIN;
- if (parent.showUnselectedClose && (parent.showClose || showClose)) {
- maxImageWidth -= closeRect.width + INTERNAL_SPACING;
- }
- }
- if (bounds.width < maxImageWidth) {
- int imageY = y + (height - bounds.height) / 2 + (parent.onBottom ? -1 : 1);
- parent.redraw(imageX, imageY, bounds.width, bounds.height, false);
- }
- }
- }
- return;
- }
- }
- parent.updateItems();
- parent.redrawTabs();
- }
+ this.disabledImage = image;
+}
+/**
+ * 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
+ *
+ * @exception DWTException
+ *
+ *
+ * @since 3.0
+ */
+public void setFont (Font font){
+ checkWidget();
+ if (font !is null && font.isDisposed ()) {
+ DWT.error(DWT.ERROR_INVALID_ARGUMENT);
}
-
- /**
- * Sets to true
to indicate that the receiver's close button should be shown.
- * If the parent cast(CTabFolder) was created with DWT.CLOSE style, changing this value has
- * no effect.
- *
- * @param close the new state of the close button
- *
- * @exception DWTException
- *
- *
- * @since 3.4
- */
- public void setShowClose (bool close) {
- checkWidget();
- if (showClose is close)
- return;
- showClose = close;
+ if (font is null && this.font is null) return;
+ if (font !is null && font==this.font) return;
+ this.font = font;
+ if (!parent.updateTabHeight(false)) {
parent.updateItems();
parent.redrawTabs();
}
-
- public void setText (String String) {
- checkWidget();
- if (String is null)
- DWT.error(DWT.ERROR_NULL_ARGUMENT);
- if (String.opEquals(getText()))
- return;
- super.setText(String);
- shortenedText = null;
- shortenedTextWidth = 0;
- if (!parent.updateTabHeight(false)) {
- parent.updateItems();
- parent.redrawTabs();
+}
+public override void setImage (Image image) {
+ checkWidget();
+ if (image !is null && image.isDisposed ()) {
+ DWT.error(DWT.ERROR_INVALID_ARGUMENT);
+ }
+ Image oldImage = getImage();
+ if (image is null && oldImage is null) return;
+ if (image !is null && image==oldImage) return;
+ super.setImage(image);
+ if (!parent.updateTabHeight(false)) {
+ // If image is the same size as before,
+ // redraw only the image
+ if (oldImage !is null && image !is null) {
+ Rectangle oldBounds = oldImage.getBounds();
+ Rectangle bounds = image.getBounds();
+ if (bounds.width is oldBounds.width && bounds.height is oldBounds.height) {
+ if (showing) {
+ bool selected = parent.indexOf(this) is parent.selectedIndex;
+ if (selected || parent.showUnselectedImage) {
+ int imageX = x + LEFT_MARGIN, maxImageWidth;
+ if (selected) {
+ if (parent.single && (parent.showClose || showClose)) imageX += CTabFolder.BUTTON_SIZE;
+ int rightEdge = Math.min (x + width, parent.getRightItemEdge());
+ maxImageWidth = rightEdge - imageX - RIGHT_MARGIN;
+ if (!parent.single && closeRect.width > 0) maxImageWidth -= closeRect.width + INTERNAL_SPACING;
+ } else {
+ maxImageWidth = x + width - imageX - RIGHT_MARGIN;
+ if (parent.showUnselectedClose && (parent.showClose || showClose)) {
+ maxImageWidth -= closeRect.width + INTERNAL_SPACING;
+ }
+ }
+ if (bounds.width < maxImageWidth) {
+ int imageY = y + (height - bounds.height) / 2 + (parent.onBottom ? -1 : 1);
+ parent.redraw(imageX, imageY, bounds.width, bounds.height, false);
+ }
+ }
+ }
+ return;
+ }
}
+ parent.updateItems();
+ parent.redrawTabs();
}
-
- /**
- * Sets the receiver's tool tip text to the argument, which
- * may be null indicating that no tool tip text should be shown.
- *
- * @param String the new tool tip text (or null)
- *
- * @exception DWTException
- *
- */
- public void setToolTipText (String String) {
- checkWidget();
- toolTipText = String;
+}
+/**
+ * Sets to true
to indicate that the receiver's close button should be shown.
+ * If the parent (CTabFolder) was created with DWT.CLOSE style, changing this value has
+ * no effect.
+ *
+ * @param close the new state of the close button
+ *
+ * @exception DWTException
+ *
+ *
+ * @since 3.4
+ */
+public void setShowClose(bool close) {
+ checkWidget();
+ if (showClose is close) return;
+ showClose = close;
+ parent.updateItems();
+ parent.redrawTabs();
+}
+public override void setText (String string) {
+ checkWidget();
+ // DWT extension: allow null for zero length string
+ //if (string is null) DWT.error (DWT.ERROR_NULL_ARGUMENT);
+ if (string.equals (getText())) return;
+ super.setText(string);
+ shortenedText = null;
+ shortenedTextWidth = 0;
+ if (!parent.updateTabHeight(false)) {
+ parent.updateItems();
+ parent.redrawTabs();
}
+}
+/**
+ * Sets the receiver's tool tip text to the argument, which
+ * may be null indicating that no tool tip text should be shown.
+ *
+ * @param string the new tool tip text (or null)
+ *
+ * @exception DWTException
+ *
+ */
+public void setToolTipText (String string) {
+ checkWidget();
+ toolTipText = string;
+}
}
diff -r fbe68c33eeee -r 6337764516f1 dwt/custom/ControlEditor.d
--- a/dwt/custom/ControlEditor.d Tue Oct 07 14:41:31 2008 +0200
+++ b/dwt/custom/ControlEditor.d Tue Oct 07 16:29:55 2008 +0200
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2007 IBM Corporation and others.
+ * 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
@@ -7,13 +7,12 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
- *
* Port to the D programming language:
- * Jacob Carlborg
- */
+*
+* A ControlEditor is a manager for a Control that appears above a composite and tracks with the
+* moving and resizing of that composite. It can be used to display one control above
+* another control. This could be used when editing a control that does not have editing
+* capabilities by using a text editor or for launching a dialog by placing a button
+* above a control.
+*
+*
- * Canvas canvas = new Canvas(shell, DWT.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, DWT.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 !is null) {
- * if (color !is null) color.dispose();
- * color = new Color(null, rgb);
- * canvas.setBackground(color);
- * }
- *
- * }
- * });
- *
- * editor.horizontalAlignment = DWT.RIGHT;
- * editor.verticalAlignment = DWT.BOTTOM;
- * editor.grabHorizontal = false;
- * editor.grabVertical = false;
- * Point size = button.computeSize(DWT.DEFAULT, DWT.DEFAULT);
- * editor.minimumWidth = size.x;
- * editor.minimumHeight = size.y;
- * editor.setEditor (button);
- *
+*
+* @see Sample code and further information
+*/
public class ControlEditor {
/**
- * Specifies how the editor should be aligned relative to the control. Allowed values
- * are DWT.LEFT, DWT.RIGHT and DWT.CENTER. The default value is DWT.CENTER.
- */
+ * Specifies how the editor should be aligned relative to the control. Allowed values
+ * are DWT.LEFT, DWT.RIGHT and DWT.CENTER. The default value is DWT.CENTER.
+ */
public int horizontalAlignment = DWT.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.
- */
+ * 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 bool 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.
- */
+ * 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 DWT.TOP, DWT.BOTTOM and DWT.CENTER. The default value is DWT.CENTER.
- */
+ * Specifies how the editor should be aligned relative to the control. Allowed values
+ * are DWT.TOP, DWT.BOTTOM and DWT.CENTER. The default value is DWT.CENTER.
+ */
public int verticalAlignment = DWT.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.
- */
+ * 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 bool 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.
- */
+ * 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;
@@ -116,160 +117,146 @@
private Listener controlListener;
private Listener scrollbarListener;
- private const static int[] EVENTS = [DWT.KeyDown, DWT.KeyUp, DWT.MouseDown, DWT.MouseUp, DWT.Resize];
-
- /**
- * Creates a ControlEditor for the specified Composite.
- *
- * @param parent the Composite above which this editor will be displayed
- *
- */
- public this (Composite parent) {
- this.parent = parent;
+ private final static int [] EVENTS = [DWT.KeyDown, DWT.KeyUp, DWT.MouseDown, DWT.MouseUp, DWT.Resize];
+/**
+* Creates a ControlEditor for the specified Composite.
+*
+* @param parent the Composite above which this editor will be displayed
+*
+*/
+public this (Composite parent) {
+ this.parent = parent;
- controlListener = new class Listener {
- public void handleEvent (Event e) {
- layout();
- }
- };
- for (int i = 0; i < EVENTS.length; i++) {
- parent.addListener(EVENTS[i], controlListener);
+ controlListener = new class() Listener {
+ public void handleEvent(Event e) {
+ layout ();
}
-
- scrollbarListener = new class Listener {
- public void handleEvent (Event e) {
- scroll(e);
- }
- };
- ScrollBar hBar = parent.getHorizontalBar();
- if (hBar !is null)
- hBar.addListener(DWT.Selection, scrollbarListener);
- ScrollBar vBar = parent.getVerticalBar();
- if (vBar !is null)
- vBar.addListener(DWT.Selection, scrollbarListener);
+ };
+ for (int i=0; i
+* Canvas canvas = new Canvas(shell, DWT.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, DWT.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 !is null) {
+* if (color !is null) color.dispose();
+* color = new Color(null, rgb);
+* canvas.setBackground(color);
+* }
+*
+* }
+* });
+*
+* editor.horizontalAlignment = DWT.RIGHT;
+* editor.verticalAlignment = DWT.BOTTOM;
+* editor.grabHorizontal = false;
+* editor.grabVertical = false;
+* Point size = button.computeSize(DWT.DEFAULT, DWT.DEFAULT);
+* editor.minimumWidth = size.x;
+* editor.minimumHeight = size.y;
+* editor.setEditor (button);
+*
StyledTextContent> will always have
* at least one empty line.
*/
this() {
- super();
+ lines = new int[][]( 50, 2 );
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
+/**
+ * Adds a line index to the end of linesArray
. Increases the
* size of the array if necessary and returns a new array.
* TextChangeListener
listening for
- * TextChangingEvent
and TextChangedEvent
. A
+ * Adds a 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
+ * A TextChangedEvent
is sent after changes to the text
* occurred.
* StyledTextContent
interface.
*
@@ -637,14 +650,14 @@
*/
public int getOffsetAtLine(int lineIndex) {
if (lineIndex is 0) return 0;
- if ((lineIndex >= lineCount) || (lineIndex < 0)) error(DWT.ERROR_INVALID_ARGUMENT);
+ if ((lineIndex >= lineCount_) || (lineIndex < 0)) error(DWT.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 is null) error(DWT.ERROR_NULL_ARGUMENT);
- for (int i = 0; i < textListeners.size(); i++) {
- TypedListener typedListener = cast(TypedListener) textListeners.elementAt(i);
+ for (int i = 0; i < textListeners.length; i++) {
+ TypedListener typedListener = cast(TypedListener) textListeners[i];
if (typedListener.getEventListener () is listener) {
- textListeners.removeElementAt(i);
+ textListeners = textListeners[ 0 .. i ] ~ textListeners[ i+1 .. $ ];
break;
}
}
}
/**
- * Replaces the text with newText
starting at position start
+ * 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
+ * When sending the TextChangingEvent, 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:
*
- *
*
*
*/
public void replaceTextRange(int start, int replaceLength, String newText){
// check for invalid replace operations
- if (!isValidReplace(start, replaceLength, newText)) DWT.error(DWT.ERROR_INVALID_ARGUMENT);
+ if (!isValidReplace(start, replaceLength, newText)) DWT.error(DWT.ERROR_INVALID_ARGUMENT);
// inform listeners
StyledTextEvent event = new StyledTextEvent(this);
@@ -774,11 +788,11 @@
event.text = newText;
event.newLineCount = lineCount(newText);
event.replaceCharCount = replaceLength;
- event.newCharCount = newText.length();
+ event.newCharCount = newText.length;
sendTextEvent(event);
// first delete the text to be replaced
- delete(start, replaceLength, event.replaceLineCount + 1);
+ delete_(start, replaceLength, event.replaceLineCount + 1);
// then insert the new text
insert(start, newText);
// inform listeners
@@ -790,19 +804,19 @@
* Sends the text listeners the TextChanged event.
*/
void sendTextEvent(StyledTextEvent event) {
- for (int i = 0; i < textListeners.size(); i++) {
- (cast(StyledTextListener)textListeners.elementAt(i)).handleEvent(event);
+ for (int i = 0; i < textListeners.length; i++) {
+ (cast(StyledTextListener)textListeners[i]).handleEvent(event);
}
-}
+}
/**
- * Sets the content to text and removes the gap since there are no sensible predictions
+ * Sets the content to text and removes the gap since there are no sensible predictions
* about where the next change will occur.
*
*
*
* @param event the event
- *
+ *
* @see MovementEvent
* @see StyledText#addWordMovementListener(MovementListener)
*/
@@ -47,7 +50,7 @@
/**
* This method is called when a new offset is required based on the current
* offset and a movement type.
- *
+ *
*
*
*
* @param event the event
- *
+ *
* @see MovementEvent
* @see StyledText#addWordMovementListener(MovementListener)
*/
diff -r fbe68c33eeee -r 6337764516f1 dwt/custom/PaintObjectEvent.d
--- a/dwt/custom/PaintObjectEvent.d Tue Oct 07 14:41:31 2008 +0200
+++ b/dwt/custom/PaintObjectEvent.d Tue Oct 07 16:29:55 2008 +0200
@@ -1,5 +1,5 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2006 IBM Corporation and others.
+/*******************************************************************************
+ * 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
@@ -7,63 +7,77 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ * Frank Benoit
*
*
* @param event the event
- *
+ *
* @see PaintObjectEvent
* @see StyledText#addPaintObjectListener(PaintObjectListener)
*/
diff -r fbe68c33eeee -r 6337764516f1 dwt/custom/PopupList.d
--- a/dwt/custom/PopupList.d Tue Oct 07 14:41:31 2008 +0200
+++ b/dwt/custom/PopupList.d Tue Oct 07 16:29:55 2008 +0200
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2007 IBM Corporation and others.
+ * 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
@@ -7,72 +7,92 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ * Frank Benoit
*
*/
-public void select(String String) {
+public void select(String string) {
String[] items = list.getItems();
// find the first entry in the list that starts with the
- // specified String
- if (String !is null){
+ // specified string
+ if (string !is null){
for (int i = 0; i < items.length; i++) {
- if (items[i].startsWith(String)){
+ if ( tango.text.Util.locatePattern( items[i], string) is 0 ){
int index = list.indexOf(items[i]);
list.select(index);
break;
@@ -223,7 +243,7 @@
* to the default system font for the widget.
*
* @param font the new font (or null)
-*
+*
* @exception DWTException
*
-*
* @exception DWTException
@@ -254,8 +273,8 @@
*
*/
-public void setItems (String[] Strings) {
- list.setItems(Strings);
+public void setItems (String[] strings) {
+ list.setItems(strings);
}
/**
* Sets the minimum width of the list.
@@ -265,7 +284,7 @@
public void setMinimumWidth (int width) {
if (width < 0)
DWT.error(DWT.ERROR_INVALID_ARGUMENT);
-
+
minimumWidth = width;
}
}
diff -r fbe68c33eeee -r 6337764516f1 dwt/custom/ST.d
--- a/dwt/custom/ST.d Tue Oct 07 14:41:31 2008 +0200
+++ b/dwt/custom/ST.d Tue Oct 07 16:29:55 2008 +0200
@@ -1,5 +1,5 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2006 IBM Corporation and others.
+/*******************************************************************************
+ * 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
@@ -7,123 +7,127 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ * Frank Benoit 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 = DWT.ARROW_UP
- public static final int LINE_DOWN = 16777218; // binding = DWT.ARROW_DOWN
- public static final int LINE_START = 16777223; // binding = DWT.HOME
- public static final int LINE_END = 16777224; // binding = DWT.END
- public static final int COLUMN_PREVIOUS = 16777219; // binding = DWT.ARROW_LEFT
- public static final int COLUMN_NEXT = 16777220; // binding = DWT.ARROW_RIGHT
- public static final int PAGE_UP = 16777221; // binding = DWT.PAGE_UP
- public static final int PAGE_DOWN = 16777222; // binding = DWT.PAGE_DOWN
- public static final int WORD_PREVIOUS = 17039363; // binding = DWT.MOD1 + DWT.ARROW_LEFT
- public static final int WORD_NEXT = 17039364; // binding = DWT.MOD1 + DWT.ARROW_RIGHT
- public static final int TEXT_START = 17039367; // binding = DWT.MOD1 + DWT.HOME
- public static final int TEXT_END = 17039368; // binding = DWT.MOD1 + DWT.END
- public static final int WINDOW_START = 17039365; // binding = DWT.MOD1 + DWT.PAGE_UP
- public static final int WINDOW_END = 17039366; // binding = DWT.MOD1 + DWT.PAGE_DOWN
-
- /*
- * Selection Key Actions
*/
- public static final int SELECT_ALL = 262209; // binding = DWT.MOD1 + 'A'
- public static final int SELECT_LINE_UP = 16908289; // binding = DWT.MOD2 + DWT.ARROW_UP
- public static final int SELECT_LINE_DOWN = 16908290; // binding = DWT.MOD2 + DWT.ARROW_DOWN
- public static final int SELECT_LINE_START = 16908295; // binding = DWT.MOD2 + DWT.HOME
- public static final int SELECT_LINE_END = 16908296; // binding = DWT.MOD2 + DWT.END
- public static final int SELECT_COLUMN_PREVIOUS = 16908291; // binding = DWT.MOD2 + DWT.ARROW_LEFT
- public static final int SELECT_COLUMN_NEXT = 16908292; // binding = DWT.MOD2 + DWT.ARROW_RIGHT
- public static final int SELECT_PAGE_UP = 16908293; // binding = DWT.MOD2 + DWT.PAGE_UP
- public static final int SELECT_PAGE_DOWN = 16908294; // binding = DWT.MOD2 + DWT.PAGE_DOWN
- public static final int SELECT_WORD_PREVIOUS = 17170435; // binding = DWT.MOD1 + DWT.MOD2 + DWT.ARROW_LEFT
- public static final int SELECT_WORD_NEXT = 17170436; // binding = DWT.MOD1 + DWT.MOD2 + DWT.ARROW_RIGHT
- public static final int SELECT_TEXT_START = 17170439; // binding = DWT.MOD1 + DWT.MOD2 + DWT.HOME
- public static final int SELECT_TEXT_END = 17170440; // binding = DWT.MOD1 + DWT.MOD2 + DWT.END
- public static final int SELECT_WINDOW_START = 17170437; // binding = DWT.MOD1 + DWT.MOD2 + DWT.PAGE_UP
- public static final int SELECT_WINDOW_END = 17170438; // binding = DWT.MOD1 + DWT.MOD2 + DWT.PAGE_DOWN
+ public static const int LINE_UP = 16777217; // binding = DWT.ARROW_UP
+ public static const int LINE_DOWN = 16777218; // binding = DWT.ARROW_DOWN
+ public static const int LINE_START = 16777223; // binding = DWT.HOME
+ public static const int LINE_END = 16777224; // binding = DWT.END
+ public static const int COLUMN_PREVIOUS = 16777219; // binding = DWT.ARROW_LEFT
+ public static const int COLUMN_NEXT = 16777220; // binding = DWT.ARROW_RIGHT
+ public static const int PAGE_UP = 16777221; // binding = DWT.PAGE_UP
+ public static const int PAGE_DOWN = 16777222; // binding = DWT.PAGE_DOWN
+ public static const int WORD_PREVIOUS = 17039363; // binding = DWT.MOD1 + DWT.ARROW_LEFT
+ public static const int WORD_NEXT = 17039364; // binding = DWT.MOD1 + DWT.ARROW_RIGHT
+ public static const int TEXT_START = 17039367; // binding = DWT.MOD1 + DWT.HOME
+ public static const int TEXT_END = 17039368; // binding = DWT.MOD1 + DWT.END
+ public static const int WINDOW_START = 17039365; // binding = DWT.MOD1 + DWT.PAGE_UP
+ public static const int WINDOW_END = 17039366; // binding = DWT.MOD1 + DWT.PAGE_DOWN
/*
- * Modification Key Actions
+ * Selection Key Actions
*/
- public static final int CUT = 131199; // binding = DWT.MOD2 + DWT.DEL
- public static final int COPY = 17039369; // binding = DWT.MOD1 + DWT.INSERT;
- public static final int PASTE = 16908297; // binding = DWT.MOD2 + DWT.INSERT ;
- public static final int DELETE_PREVIOUS = '\b'; // binding = DWT.BS;
- public static final int DELETE_NEXT = 0x7F; // binding = DWT.DEL;
- public static final int DELETE_WORD_PREVIOUS = 262152; // binding = DWT.BS | DWT.MOD1;
- public static final int DELETE_WORD_NEXT = 262271; // binding = DWT.DEL | DWT.MOD1;
+ public static const int SELECT_ALL = 262209; // binding = DWT.MOD1 + 'A'
+ public static const int SELECT_LINE_UP = 16908289; // binding = DWT.MOD2 + DWT.ARROW_UP
+ public static const int SELECT_LINE_DOWN = 16908290; // binding = DWT.MOD2 + DWT.ARROW_DOWN
+ public static const int SELECT_LINE_START = 16908295; // binding = DWT.MOD2 + DWT.HOME
+ public static const int SELECT_LINE_END = 16908296; // binding = DWT.MOD2 + DWT.END
+ public static const int SELECT_COLUMN_PREVIOUS = 16908291; // binding = DWT.MOD2 + DWT.ARROW_LEFT
+ public static const int SELECT_COLUMN_NEXT = 16908292; // binding = DWT.MOD2 + DWT.ARROW_RIGHT
+ public static const int SELECT_PAGE_UP = 16908293; // binding = DWT.MOD2 + DWT.PAGE_UP
+ public static const int SELECT_PAGE_DOWN = 16908294; // binding = DWT.MOD2 + DWT.PAGE_DOWN
+ public static const int SELECT_WORD_PREVIOUS = 17170435; // binding = DWT.MOD1 + DWT.MOD2 + DWT.ARROW_LEFT
+ public static const int SELECT_WORD_NEXT = 17170436; // binding = DWT.MOD1 + DWT.MOD2 + DWT.ARROW_RIGHT
+ public static const int SELECT_TEXT_START = 17170439; // binding = DWT.MOD1 + DWT.MOD2 + DWT.HOME
+ public static const int SELECT_TEXT_END = 17170440; // binding = DWT.MOD1 + DWT.MOD2 + DWT.END
+ public static const int SELECT_WINDOW_START = 17170437; // binding = DWT.MOD1 + DWT.MOD2 + DWT.PAGE_UP
+ public static const int SELECT_WINDOW_END = 17170438; // binding = DWT.MOD1 + DWT.MOD2 + DWT.PAGE_DOWN
- /*
- * Miscellaneous Key Actions
+ /*
+ * Modification Key Actions
*/
- public static final int TOGGLE_OVERWRITE = 16777225; // binding = DWT.INSERT;
-
+ public static const int CUT = 131199; // binding = DWT.MOD2 + DWT.DEL
+ public static const int COPY = 17039369; // binding = DWT.MOD1 + DWT.INSERT;
+ public static const int PASTE = 16908297; // binding = DWT.MOD2 + DWT.INSERT ;
+ public static const int DELETE_PREVIOUS = '\b'; // binding = DWT.BS;
+ public static const int DELETE_NEXT = 0x7F; // binding = DWT.DEL;
+ public static const int DELETE_WORD_PREVIOUS = 262152; // binding = DWT.BS | DWT.MOD1;
+ public static const int DELETE_WORD_NEXT = 262271; // binding = DWT.DEL | DWT.MOD1;
+
+ /*
+ * Miscellaneous Key Actions
+ */
+ public static const int TOGGLE_OVERWRITE = 16777225; // binding = DWT.INSERT;
+
/**
* Bullet style dot.
- *
+ *
* @see Bullet
- *
+ *
* @since 3.2
*/
- public static final int BULLET_DOT = 1 << 0;
+ public static const int BULLET_DOT = 1 << 0;
/**
* Bullet style number.
- *
+ *
* @see Bullet
- *
+ *
* @since 3.2
*/
- public static final int BULLET_NUMBER = 1 << 1;
+ public static const int BULLET_NUMBER = 1 << 1;
/**
* Bullet style lower case letter.
- *
+ *
* @see Bullet
- *
+ *
* @since 3.2
*/
- public static final int BULLET_LETTER_LOWER = 1 << 2;
+ public static const 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;
+ public static const int BULLET_LETTER_UPPER = 1 << 3;
/**
* Bullet style text.
- *
+ *
* @see Bullet
- *
+ *
* @since 3.2
*/
- public static final int BULLET_TEXT = 1 << 4;
+ public static const int BULLET_TEXT = 1 << 4;
/**
* Bullet style custom draw.
- *
+ *
* @see StyledText#addPaintObjectListener(PaintObjectListener)
* @see StyledText#removePaintObjectListener(PaintObjectListener)
- * @see Bullet
- *
+ * @see Bullet
+ *
* @since 3.2
*/
- public static final int BULLET_CUSTOM = 1 << 5;
+ public static const int BULLET_CUSTOM = 1 << 5;
}
diff -r fbe68c33eeee -r 6337764516f1 dwt/custom/SashForm.d
--- a/dwt/custom/SashForm.d Tue Oct 07 14:41:31 2008 +0200
+++ b/dwt/custom/SashForm.d Tue Oct 07 16:29:55 2008 +0200
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2007 IBM Corporation and others.
+ * 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
@@ -7,13 +7,26 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ * Frank Benoit
* The style value is either one of the style constants defined in
* class DWT
which is applicable to instances of this
- * class, or must be built by bitwise OR'ing together
+ * class, or must be built by bitwise OR'ing together
* (that is, using the int
"|" operator) two or more
* of those DWT
style constants. The class description
* lists the style constants that are applicable to the class.
@@ -78,7 +98,7 @@
sashStyle = ((style & DWT.VERTICAL) !is 0) ? DWT.HORIZONTAL : DWT.VERTICAL;
if ((style & DWT.BORDER) !is 0) sashStyle |= DWT.BORDER;
if ((style & DWT.SMOOTH) !is 0) sashStyle |= DWT.SMOOTH;
- sashListener = new Listener() {
+ sashListener = new class() Listener {
public void handleEvent(Event e) {
onDragSash(e);
}
@@ -91,7 +111,7 @@
/**
* Returns DWT.HORIZONTAL if the controls in the SashForm are laid out side by side
* or DWT.VERTICAL if the controls in the SashForm are laid out top to bottom.
- *
+ *
* @return DWT.HORIZONTAL or DWT.VERTICAL
*/
public int getOrientation() {
@@ -115,16 +135,16 @@
checkWidget();
return SASH_WIDTH;
}
-public int getStyle() {
+public override int getStyle() {
int style = super.getStyle();
style |= getOrientation() is DWT.VERTICAL ? DWT.VERTICAL : DWT.HORIZONTAL;
if ((sashStyle & DWT.SMOOTH) !is 0) style |= DWT.SMOOTH;
return style;
}
/**
- * Answer the control that currently is maximized in the SashForm.
+ * Answer the control that currently is maximized in the SashForm.
* This value may be null.
- *
+ *
* @return the control that currently is maximized or null
*/
public Control getMaximizedControl(){
@@ -133,13 +153,13 @@
}
/**
* Answer the relative weight of each child in the SashForm. The weight represents the
- * percent of the total width (if SashForm has Horizontal orientation) or
+ * percent of the total width (if SashForm has Horizontal orientation) or
* total height (if SashForm has Vertical orientation) each control occupies.
* The weights are returned in order of the creation of the widgets (weight[0]
* corresponds to the weight of the first child created).
- *
+ *
* @return the relative weight of each child
- *
+ *
* @exception DWTException
There are two ways to use the ScrolledComposite: - * + * *
- * 1) Set the size of the control that is being scrolled and 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
+ * 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().
- *
+ *
*
* The style value is either one of the style constants defined in
* class
* public static void main (String [] args) {
* Display display = new Display ();
@@ -39,7 +55,7 @@
* Color blue = display.getSystemColor(DWT.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, DWT.H_SCROLL | DWT.V_SCROLL | DWT.BORDER);
* final Composite c1 = new Composite(sc1, DWT.NONE);
@@ -51,7 +67,7 @@
* Button b1 = new Button (c1, DWT.PUSH);
* b1.setText("first button");
* c1.setSize(c1.computeSize(DWT.DEFAULT, DWT.DEFAULT));
- *
+ *
* // set the minimum width and height of the scrolled content - method 2
* final ScrolledComposite sc2 = new ScrolledComposite(shell, DWT.H_SCROLL | DWT.V_SCROLL | DWT.BORDER);
* sc2.setExpandHorizontal(true);
@@ -65,7 +81,7 @@
* Button b2 = new Button (c2, DWT.PUSH);
* b2.setText("first button");
* sc2.setMinSize(c2.computeSize(DWT.DEFAULT, DWT.DEFAULT));
- *
+ *
* Button add = new Button (shell, DWT.PUSH);
* add.setText("add children");
* final int[] index = new int[]{0};
@@ -77,7 +93,7 @@
* // reset size of content so children can be seen - method 1
* c1.setSize(c1.computeSize(DWT.DEFAULT, DWT.DEFAULT));
* c1.layout();
- *
+ *
* button = new Button(c2, DWT.PUSH);
* button.setText("button "+index[0]);
* // reset the minimum width and height so children can be seen - method 2
@@ -85,7 +101,7 @@
* c2.layout();
* }
* });
- *
+ *
* shell.open ();
* while (!shell.isDisposed ()) {
* if (!display.readAndDispatch ()) display.sleep ();
@@ -97,13 +113,16 @@
*
*
+ *
+ * @see ScrolledComposite snippets
+ * @see Sample code and further information
*/
public class ScrolledComposite : Composite {
Control content;
Listener contentListener;
Listener filter;
-
+
int minHeight = 0;
int minWidth = 0;
bool expandHorizontal = false;
@@ -117,7 +136,7 @@
* DWT
which is applicable to instances of this
- * class, or must be built by bitwise OR'ing together
+ * class, or must be built by bitwise OR'ing together
* (that is, using the int
"|" operator) two or more
* of those DWT
style constants. The class description
* lists the style constants that are applicable to the class.
@@ -137,47 +156,46 @@
* @see DWT#H_SCROLL
* @see DWT#V_SCROLL
* @see #getStyle()
- */
+ */
public this(Composite parent, int style) {
super(parent, checkStyle(style));
super.setLayout(new ScrolledCompositeLayout());
ScrollBar hBar = getHorizontalBar ();
if (hBar !is null) {
hBar.setVisible(false);
- hBar.addListener (DWT.Selection, new Listener () {
+ hBar.addListener (DWT.Selection, new class() Listener {
public void handleEvent (Event e) {
hScroll();
}
});
}
-
+
ScrollBar vBar = getVerticalBar ();
if (vBar !is null) {
vBar.setVisible(false);
- vBar.addListener (DWT.Selection, new Listener () {
+ vBar.addListener (DWT.Selection, new class() Listener {
public void handleEvent (Event e) {
vScroll();
}
});
}
-
- contentListener = new Listener() {
+
+ contentListener = new class() Listener {
public void handleEvent(Event e) {
if (e.type !is DWT.Resize) return;
layout(false);
}
};
-
- filter = new Listener() {
+
+ filter = new class() Listener {
public void handleEvent(Event event) {
- if ( null !is cast(Control)event.widget ) {
- Control control = cast(Control) event.widget;
+ if (auto control = cast(Control)event.widget ) {
if (contains(control)) showControl(control);
}
}
};
-
- addDisposeListener(new DisposeListener() {
+
+ addDisposeListener(new class() DisposeListener {
public void widgetDisposed(DisposeEvent e) {
getDisplay().removeFilter(DWT.FocusIn, filter);
}
@@ -201,12 +219,12 @@
}
/**
- * Returns the Always Show Scrollbars flag. True if the scrollbars are
- * always shown even if they are not required. False if the scrollbars are only
+ * Returns the Always Show Scrollbars flag. True if the scrollbars are
+ * always shown even if they are not required. False if the scrollbars are only
* visible when some part of the composite needs to be scrolled to be seen.
- * The H_SCROLL and V_SCROLL style bits are also required to enable scrollbars in the
+ * The H_SCROLL and V_SCROLL style bits are also required to enable scrollbars in the
* horizontal and vertical directions.
- *
+ *
* @return the Always Show Scrollbars flag value
*/
public bool getAlwaysShowScrollBars() {
@@ -215,7 +233,7 @@
}
/**
- * Returns true
if the content control
+ * Returns true
if the content control
* will be expanded to fill available horizontal space.
*
* @return the receiver's horizontal expansion state
@@ -224,7 +242,7 @@
*
true
if the content control
+ * Returns true
if the content control
* will be expanded to fill available vertical space.
*
* @return the receiver's vertical expansion state
@@ -242,7 +260,7 @@
* true
if the receiver automatically scrolls to a focused child control
+ * Returns true
if the receiver automatically scrolls to a focused child control
* to make it visible. Otherwise, returns false
.
- *
+ *
+ * @return a bool indicating whether focused child controls are automatically scrolled into the viewport
+ *
* @exception DWTException false
, show a focused control is off.
+ *
+ * If show is false
, show a focused control is off.
* By default, show a focused control is off.
- *
+ *
* @param show true
to show a focused control.
- *
+ *
* @exception DWTException Here is an example which places ten buttons in a stack layout and + * + *
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, DWT.NONE);
* parent.setLayoutData(new GridData(GridData.FILL_BOTH));
* final StackLayout layout = new StackLayout();
@@ -41,7 +52,7 @@
* bArray[i].setText("Button "+i);
* }
* layout.topControl = bArray[0];
- *
+ *
* Button b = new Button(shell, DWT.PUSH);
* b.setText("Show Next Button");
* final int[] index = new int[1];
@@ -52,18 +63,22 @@
* parent.layout();
* }
* });
- *
+ *
* shell.open();
* while (shell !is null && !shell.isDisposed()) {
* if (!display.readAndDispatch())
- * display.sleep();
- * }
+ * display.sleep();
+ * }
* }
*
+ *
+ * @see StackLayout snippets
+ * @see DWT Example: LayoutExample
+ * @see Sample code and further information
*/
public class StackLayout : Layout {
-
+
/**
* marginWidth specifies the number of pixels of horizontal margin
* that will be placed along the left and right edges of the layout.
@@ -85,7 +100,7 @@
*/
public Control topControl;
-protected Point computeSize(Composite composite, int wHint, int hHint, bool flushCache) {
+protected override Point computeSize(Composite composite, int wHint, int hHint, bool flushCache) {
Control children[] = composite.getChildren();
int maxWidth = 0;
int maxHeight = 0;
@@ -101,11 +116,11 @@
return new Point(width, height);
}
-protected bool flushCache(Control control) {
+protected override bool flushCache(Control control) {
return true;
}
-protected void layout(Composite composite, bool flushCache) {
+protected override void layout(Composite composite, bool flushCache) {
Control children[] = composite.getChildren();
Rectangle rect = composite.getClientArea();
rect.x += marginWidth;
@@ -115,30 +130,30 @@
for (int i = 0; i < children.length; i++) {
children[i].setBounds(rect);
children[i].setVisible(children[i] is topControl);
-
+
}
}
String getName () {
- String String = getClass ().getName ();
- int index = String.lastIndexOf ('.');
- if (index is -1) return String;
- return String.substring (index + 1, String.length ());
+ String string = this.classinfo.name;
+ int index = tango.text.Util.locatePrior( string ,'.');
+ if (index is string.length ) return string;
+ return string[ index + 1 .. $ ];
}
/**
- * Returns a String containing a concise, human-readable
+ * Returns a string containing a concise, human-readable
* description of the receiver.
*
- * @return a String representation of the layout
+ * @return a string representation of the layout
*/
-public String toString () {
- String String = getName ()+" {";
- if (marginWidth !is 0) String += "marginWidth="+marginWidth+" ";
- if (marginHeight !is 0) String += "marginHeight="+marginHeight+" ";
- if (topControl !is null) String += "topControl="+topControl+" ";
- String = String.trim();
- String += "}";
- return String;
+public override String toString () {
+ String string = getName ()~" {";
+ if (marginWidth !is 0) string ~= "marginWidth="~to!(String)(marginWidth)~" ";
+ if (marginHeight !is 0) string ~= "marginHeight="~to!(String)(marginHeight)~" ";
+ if (topControl !is null) string ~= "topControl="~to!(String)(topControl)~" ";
+ string = tango.text.Util.trim(string);
+ string ~= "}";
+ return string;
}
}
diff -r fbe68c33eeee -r 6337764516f1 dwt/custom/StyleRange.d
--- a/dwt/custom/StyleRange.d Tue Oct 07 14:41:31 2008 +0200
+++ b/dwt/custom/StyleRange.d Tue Oct 07 16:29:55 2008 +0200
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2007 IBM Corporation and others.
+ * 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
@@ -7,20 +7,44 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ * Frank Benoit 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 : TextStyle, CloneableCompatibility { + /** * the start offset of the range, zero-based from the document start */ public int start; - + /** * the length of the range */ @@ -29,37 +53,46 @@ /** * the font style of the range. It may be a combination of * DWT.NORMAL, DWT.ITALIC or DWT.BOLD - * + * * Note: the font style is not used if thefont
attribute
* is set
*/
public int fontStyle = DWT.NORMAL;
-
+
/**
* Create a new style range with no styles
- *
+ *
* @since 3.2
*/
public this() {
}
+/++
+ + DWT extension for clone implementation
+ +/
+protected this( StyleRange other ){
+ super( other );
+ start = other.start;
+ length = other.length;
+ fontStyle = other.fontStyle;
+}
-/**
+/**
* Create a new style range from an existing text style.
*
- *@param style the text style to copy
+ * @param style the text style to copy
*
- *@since 3.4
+ * @since 3.4
*/
public this(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 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 this(int start, int length, Color foreground, Color background) {
@@ -68,12 +101,12 @@
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 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 DWT.NORMAL, DWT.ITALIC or DWT.BOLD
*/
@@ -90,12 +123,11 @@
* @param object the object to compare with this object
* @return true
if the object is the same as this object and false
otherwise
*
- * @see #toHash()
+ * @see #hashCode()
*/
-public bool opEquals(Object object) {
+public override int opEquals(Object object) {
if (object is this) return true;
- if ( null !is cast(StyleRange)object ) {
- StyleRange style = cast(StyleRange)object;
+ if (auto style = cast(StyleRange) object ) {
if (start !is style.start) return false;
if (length !is style.length) return false;
return similarTo(style);
@@ -104,23 +136,23 @@
}
/**
- * Returns an integer hash code for the receiver. Any two
- * objects that return true
when passed to
- * opEquals
must return the same value for this
+ * 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 #opEquals(Object)
+ * @see #equals(Object)
*/
-public int toHash() {
+public override hash_t toHash() {
return super.toHash() ^ fontStyle;
}
bool isVariableHeight() {
return font !is null || metrics !is null || rise !is 0;
}
/**
- * Returns whether or not the receiver is unstyled (i.e., does not have any
+ * 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.
@@ -139,7 +171,7 @@
}
/**
- * Compares the specified object to this StyleRange and answer if the two
+ * 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.
*
@@ -156,22 +188,18 @@
* 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;
- }
+ */
+public /+override+/ Object clone() {
+ return new StyleRange( this );
}
/**
- * Returns a String containing a concise, human-readable
+ * Returns a string containing a concise, human-readable
* description of the receiver.
*
- * @return a String representation of the StyleRange
+ * @return a string representation of the StyleRange
*/
-public String toString() {
+public override String toString() {
StringBuffer buffer = new StringBuffer();
buffer.append("StyleRange {");
buffer.append(start);
@@ -192,9 +220,10 @@
buffer.append("normal");
}
String str = super.toString();
- int index = str.indexOf('{');
- str = str.substring(index + 1);
- if (str.length() > 1) buffer.append(", ");
+ int index = tango.text.Util.locate( str, '{');
+ if( index is str.length ) index = -1;
+ str = str[ index + 1 .. $ ];
+ if (str.length > 1) buffer.append(", ");
buffer.append(str);
return buffer.toString();
}
diff -r fbe68c33eeee -r 6337764516f1 dwt/custom/StyledText.d
--- a/dwt/custom/StyledText.d Tue Oct 07 14:41:31 2008 +0200
+++ b/dwt/custom/StyledText.d Tue Oct 07 16:29:55 2008 +0200
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2007 IBM Corporation and others.
+ * 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
@@ -7,39 +7,109 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ * Frank Benoit - * In addition to text style attributes, the background color of a line may + * 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 + * 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 + * 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. + * setContent(StyledTextContent) to initialize the widget. *
*
* IMPORTANT: This class is not intended to be subclassed. *
+ * + * @see StyledText snippets + * @see DWT Examples: CustomControlExample, TextEditor + * @see Sample code and further information */ public class StyledText : 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 PREVIOUS_OFFSET_TRAILING = 0; - static final int OFFSET_LEADING = 1; - + alias Canvas.computeSize computeSize; + + static const char TAB = '\t'; + static const String PlatformLineDelimiter = tango.io.model.IFile.FileConst.NewlineString; + static const int BIDI_CARET_WIDTH = 3; + static const int DEFAULT_WIDTH = 64; + static const int DEFAULT_HEIGHT = 64; + static const int V_SCROLL_RATE = 50; + static const int H_SCROLL_RATE = 10; + + static const int ExtendedModify = 3000; + static const int LineGetBackground = 3001; + static const int LineGetStyle = 3002; + static const int TextChanging = 3003; + static const int TextSet = 3004; + static const int VerifyKey = 3005; + static const int TextChanged = 3006; + static const int LineGetSegments = 3007; + static const int PaintObject = 3008; + static const int WordNext = 3009; + static const int WordPrevious = 3010; + + static const int PREVIOUS_OFFSET_TRAILING = 0; + static const int OFFSET_LEADING = 1; + Color selectionBackground; // selection background color Color selectionForeground; // selection foreground color StyledTextContent content; // native content (default or user specified) @@ -118,30 +194,30 @@ int columnX; // keep track of the horizontal caret position when changing lines/pages. Fixes bug 5935 int caretOffset = 0; int caretAlignment; - Point selection = new Point(0, 0); // x and y are start and end caret offsets of selection + Point selection; // 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 bool editable = true; bool wordWrap = false; - bool doubleClickEnabled = true; // see getDoubleClickEnabled - bool overwrite = false; // insert/overwrite edit mode + bool doubleClickEnabled = true; // see getDoubleClickEnabled + bool 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(); + int[int] keyActionMap; Color background = null; // workaround for bug 4791 Color foreground = null; // Clipboard clipboard; int clickCount; int autoScrollDirection = DWT.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 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 lastLineBottom; // the bottom pixel of the last line been replaced - bool isMirrored; - bool bidiColoring = false; // apply the BIDI algorithm on text segments of the same color + bool isMirrored_; + bool bidiColoring = false; // apply the BIDI algorithm on text segments of the same color Image leftCaretBitmap = null; Image rightCaretBitmap = null; int caretDirection = DWT.NULL; @@ -149,32 +225,32 @@ Caret defaultCaret = null; bool updateCaretDirection = true; bool fixedLineHeight; - bool dragDetect = true; + bool dragDetect_ = true; IME ime; - + int alignment; bool justify; int indent; int lineSpacing; - final static bool IS_CARBON, IS_GTK, IS_MOTIF; - static { + const static bool IS_CARBON, IS_GTK, IS_MOTIF; + static this(){ String platform = DWT.getPlatform(); - IS_CARBON = "carbon".opEquals(platform); - IS_GTK = "gtk".opEquals(platform); - IS_MOTIF = "motif".opEquals(platform); + IS_CARBON = ("carbon" == platform); + IS_GTK = ("gtk" == platform); + IS_MOTIF = ("motif" == platform); } /** * The Printing class : printing of a range of text. - * An instance ofPrinting
is returned in the
- * StyledText#print(Printer) API. The run() method may be
+ * An instance of Printing
is returned in the
+ * StyledText#print(Printer) API. The run() method may be
* invoked from any thread.
*/
static class Printing : 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
+ const static int LEFT = 0; // left aligned header/footer segment
+ const static int CENTER = 1; // centered header/footer segment
+ const static int RIGHT = 2; // right aligned header/footer segment
Printer printer;
StyledTextRenderer printerRenderer;
@@ -182,7 +258,7 @@
Rectangle clientArea;
FontData fontData;
Font printerFont;
- Hashtable resources;
+ Resource[Resource] resources;
int tabLength;
GC gc; // printer GC
int pageWidth; // width of a printer page in pixels
@@ -190,30 +266,30 @@
int endPage; // last page to print
int startLine; // first (wrapped) line to print
int endLine; // last (wrapped) line to print
- bool singleLine; // widget single line mode
+ bool singleLine; // widget single line mode
Point selection = null; // selected text
- bool mirrored; // indicates the printing gc should be mirrored
+ bool 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
+ * 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
- */
+ */
this(StyledText styledText, Printer printer, StyledTextPrintOptions printOptions) {
this.printer = printer;
this.printOptions = printOptions;
this.mirrored = (styledText.getStyle() & DWT.MIRRORED) !is 0;
singleLine = styledText.isSingleLine();
startPage = 1;
- endPage = Integer.MAX_VALUE;
+ endPage = int.max;
PrinterData data = printer.getPrinterData();
- if (data.scope is PrinterData.PAGE_RANGE) {
+ if (data.scope_ is PrinterData.PAGE_RANGE) {
startPage = data.startPage;
endPage = data.endPage;
if (endPage < startPage) {
@@ -221,7 +297,7 @@
endPage = startPage;
startPage = temp;
}
- } else if (data.scope is PrinterData.SELECTION) {
+ } else if (data.scope_ is PrinterData.SELECTION) {
selection = styledText.getSelectionRange();
}
printerRenderer = new StyledTextRenderer(printer, null);
@@ -231,7 +307,7 @@
/**
* Caches all line data that needs to be requested from a listener.
*
- * @param printerContent StyledTextContent
to request
+ * @param printerContent StyledTextContent
to request
* line data for.
*/
void cacheLineData(StyledText styledText) {
@@ -252,7 +328,7 @@
if (styledText.isBidi()) {
int[] segments = styledText.getBidiSegments(lineOffset, line);
printerRenderer.setLineSegments(i, 1, segments);
- }
+ }
event = styledText.getLineStyleData(lineOffset, line);
if (event !is null) {
printerRenderer.setLineIndent(i, 1, event.indent);
@@ -268,15 +344,18 @@
}
Point screenDPI = styledText.getDisplay().getDPI();
Point printerDPI = printer.getDPI();
- resources = new Hashtable ();
+ resources = null;
for (int i = 0; i < lineCount; i++) {
Color color = printerRenderer.getLineBackground(i, null);
if (color !is null) {
if (printOptions.printLineBackground) {
- Color printerColor = cast(Color)resources.get(color);
- if (printerColor is null) {
+ Color printerColor;
+ if ( auto p = color in resources ) {
+ printerColor = cast(Color)*p;
+ }
+ else {
printerColor = new Color (printer, color.getRGB());
- resources.put(color, printerColor);
+ resources[color]=printerColor;
}
printerRenderer.setLineBackground(i, 1, printerColor);
} else {
@@ -293,20 +372,26 @@
StyleRange style = styles[i];
Font font = style.font;
if (style.font !is null) {
- Font printerFont = cast(Font)resources.get(font);
- if (printerFont is null) {
+ Font printerFont;
+ if ( auto p = font in resources ) {
+ printerFont = cast(Font)*p;
+ }
+ else {
printerFont = new Font (printer, font.getFontData());
- resources.put(font, printerFont);
+ resources[font]= printerFont;
}
style.font = printerFont;
}
Color color = style.foreground;
if (color !is null) {
- Color printerColor = cast(Color)resources.get(color);
if (printOptions.printTextForeground) {
- if (printerColor is null) {
+ Color printerColor;
+ if ( auto p = color in resources ) {
+ printerColor = cast(Color)*p;
+ }
+ else {
printerColor = new Color (printer, color.getRGB());
- resources.put(color, printerColor);
+ resources[color]=printerColor;
}
style.foreground = printerColor;
} else {
@@ -315,11 +400,14 @@
}
color = style.background;
if (color !is null) {
- Color printerColor = cast(Color)resources.get(color);
if (printOptions.printTextBackground) {
- if (printerColor is null) {
+ Color printerColor;
+ if ( auto p = color in resources ) {
+ printerColor = cast(Color)*p;
+ }
+ else {
printerColor = new Color (printer, color.getRGB());
- resources.put(color, printerColor);
+ resources[color]=printerColor;
}
style.background = printerColor;
} else {
@@ -370,14 +458,10 @@
gc.dispose();
gc = null;
}
- if (resources !is null) {
- Enumeration enumeration = resources.elements();
- while (enumeration.hasMoreElements()) {
- Resource resource = cast(Resource) enumeration.nextElement();
- resource.dispose();
- }
- resources = null;
- }
+ foreach( resource; resources.values ){
+ resource.dispose();
+ }
+ resources = null;
if (printerFont !is null) {
printerFont.dispose();
printerFont = null;
@@ -390,15 +474,15 @@
void init_() {
Rectangle trim = printer.computeTrim(0, 0, 0, 0);
Point dpi = printer.getDPI();
-
- printerFont = new Font(printer, fontData.getName(), fontData.getHeight(), DWT.NORMAL);
+
+ printerFont = new Font( cast(Device)printer, fontData.getName(), fontData.getHeight(), DWT.NORMAL);
clientArea = printer.getClientArea();
pageWidth = clientArea.width;
// one inch margin around text
- clientArea.x = dpi.x + trim.x;
+ clientArea.x = dpi.x + trim.x;
clientArea.y = dpi.y + trim.y;
clientArea.width -= (clientArea.x + trim.width);
- clientArea.height -= (clientArea.y + trim.height);
+ clientArea.height -= (clientArea.y + trim.height);
int style = mirrored ? DWT.RIGHT_TO_LEFT : DWT.LEFT_TO_RIGHT;
gc = new GC(printer, style);
@@ -412,16 +496,16 @@
if (printOptions.footer !is 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 is PrinterData.PAGE_RANGE) {
+ if (data.scope_ is PrinterData.PAGE_RANGE) {
int pageSize = clientArea.height / lineHeight;//WRONG
startLine = (startPage - 1) * pageSize;
- } else if (data.scope is PrinterData.SELECTION) {
+ } else if (data.scope_ is PrinterData.SELECTION) {
startLine = content.getLineAtOffset(selection.x);
if (selection.y > 0) {
endLine = content.getLineAtOffset(selection.x + selection.y - 1);
@@ -477,7 +561,7 @@
}
TextLayout layout = printerRenderer.getTextLayout(i, orientation, width, lineSpacing);
Color lineBackground = printerRenderer.getLineBackground(i, background);
- int paragraphBottom = paintY + layout.getBounds().height;
+ 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);
@@ -507,7 +591,7 @@
printLine(paintX, paintY, gc, foreground, lineBackground, layout, printLayout, i);
gc.setClipping(cast(Rectangle)null);
printDecoration(page, false, printLayout);
- printer.endPage();
+ printer.endPage();
page++;
if (page <= endPage) {
printer.startPage();
@@ -532,7 +616,7 @@
}
/**
* 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
*/
@@ -541,16 +625,16 @@
if (text is null) return;
int lastSegmentIndex = 0;
for (int i = 0; i < 3; i++) {
- int segmentIndex = text.indexOf(StyledTextPrintOptions.SEPARATOR, lastSegmentIndex);
+ int segmentIndex = text.indexOf( StyledTextPrintOptions.SEPARATOR, lastSegmentIndex);
String segment;
- if (segmentIndex is -1) {
+ if (segmentIndex is -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();
+ lastSegmentIndex = segmentIndex + StyledTextPrintOptions.SEPARATOR.length;
}
}
}
@@ -558,22 +642,22 @@
* 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 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, bool header, TextLayout layout) {
+ void printDecorationSegment(String segment, int alignment, int page, bool header, TextLayout layout) {
int pageIndex = segment.indexOf(StyledTextPrintOptions.PAGE_TAG);
- if (pageIndex !is -1) {
- int pageTagLength = StyledTextPrintOptions.PAGE_TAG.length();
+ if (pageIndex !is -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) {
+ segment = buffer.toString().dup;
+ }
+ if (segment.length > 0) {
layout.setText(segment);
int segmentWidth = layout.getBounds().width;
int segmentHeight = printerRenderer.getLineHeight();
@@ -598,7 +682,7 @@
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);
@@ -620,7 +704,7 @@
printLayout.setText("");
}
} else {
- printLayout.setText(String.valueOf(index));
+ printLayout.setText(to!(String)(index));
}
int paintX = x - printMargin - printLayout.getBounds().width;
printLayout.draw(gc, paintX, y);
@@ -639,64 +723,66 @@
jobName = "Printing";
}
if (printer.startJob(jobName)) {
- init();
+ init_();
print();
dispose();
printer.endJob();
}
- }
+ }
}
/**
* The RTFWriter
class is used to write widget content as
- * rich text. The implementation complies with the RTF specification
+ * 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. + * 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 + * 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 + * 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 : TextWriter { - static final int DEFAULT_FOREGROUND = 0; - static final int DEFAULT_BACKGROUND = 1; - Vector colorTable, fontTable; + + alias TextWriter.write write; + + static const int DEFAULT_FOREGROUND = 0; + static const int DEFAULT_BACKGROUND = 1; + Color[] colorTable; + Font[] fontTable; bool WriteUnicode; - + /** * Creates a RTF writer that writes content starting at offset "start" - * in the document.start
and length
can be set to specify partial
+ * in the document. start
and length
can be set to specify partial
* lines.
*
- * @param start start offset of content to write, 0 based from
+ * @param start start offset of content to write, 0 based from
* beginning of document
* @param length length of content to write
*/
public this(int start, int length) {
super(start, length);
- colorTable = new Vector();
- fontTable = new Vector();
- colorTable.addElement(getForeground());
- colorTable.addElement(getBackground());
- fontTable.addElement(getFont());
+ colorTable ~= getForeground();
+ colorTable ~= getBackground();
+ fontTable ~= getFont();
setUnicode();
}
/**
* Closes the RTF writer. Once closed no more content can be written.
- * NOTE: toString()
does not return a valid RTF String until
+ * NOTE: toString()
does not return a valid RTF string until
* close()
has been called.
*/
- public void close() {
+ public override void close() {
if (!isClosed()) {
writeHeader();
write("\n}}\0");
super.close();
}
- }
+ }
/**
* Returns the index of the specified color in the RTF color table.
*
@@ -707,10 +793,16 @@
*/
int getColorIndex(Color color, int defaultIndex) {
if (color is null) return defaultIndex;
- int index = colorTable.indexOf(color);
+ int index = -1;
+ foreach( i, col; colorTable ){
+ if( col == color ){
+ index = i;
+ break;
+ }
+ }
if (index is -1) {
- index = colorTable.size();
- colorTable.addElement(color);
+ index = colorTable.length;
+ colorTable ~= color;
}
return index;
}
@@ -723,10 +815,16 @@
* or "defaultIndex" if "color" is null.
*/
int getFontIndex(Font font) {
- int index = fontTable.indexOf(font);
+ int index = -1;
+ foreach( i, f; colorTable ){
+ if( f == font ){
+ index = i;
+ break;
+ }
+ }
if (index is -1) {
- index = fontTable.size();
- fontTable.addElement(font);
+ index = fontTable.length;
+ fontTable ~= font;
}
return index;
}
@@ -735,68 +833,72 @@
* 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 !is null) {
- int majorIndex = osVersion.indexOf('.');
- if (majorIndex !is -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);
+// const String Win95 = "windows 95";
+// const String Win98 = "windows 98";
+// const String WinME = "windows me";
+// const 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 !is null) {
+// int majorIndex = osVersion.indexOf('.');
+// if (majorIndex !is -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);
+ WriteUnicode = true; // we are on linux-gtk
}
/**
- * Appends the specified segment of "String" to the RTF data.
+ * 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
+ * @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);
+ void write(String string, int start, int end) {
+ start = 0;
+ end = string.length;
+ int incr = 1;
+ for (int index = start; index < end; index+=incr) {
+ dchar ch = firstCodePoint( string[index .. $], incr );
if (ch > 0xFF && WriteUnicode) {
- // write the sub String from the last escaped character
+ // 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( string[start .. index ] );
}
write("\\u");
- write(Integer.toString(cast(short) ch));
+ write( to!(String)( cast(short)ch ));
write(' '); // control word delimiter
- start = index + 1;
+ start = index + incr;
} else if (ch is '}' || ch is '{' || ch is '\\') {
- // write the sub String from the last escaped character
+ // 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(string[start .. index]);
}
write('\\');
- write(ch);
+ write(cast(char)ch); // ok because one of {}\
start = index + 1;
}
}
// write from the last escaped character to the end.
// Fixes bug 21698.
if (start < end) {
- write(String.substring(start, end));
+ write(string[ start .. end]);
}
}
/**
@@ -806,28 +908,31 @@
StringBuffer header = new StringBuffer();
FontData fontData = getFont().getFontData()[0];
header.append("{\\rtf1\\ansi");
- // specify code page, necessary for copy to work in bidi
+ // specify code page, necessary for copy to work in bidi
// systems that don't support Unicode RTF.
- String cpg = System.getProperty("file.encoding").toLowerCase();
+ // PORTING_TODO: String cpg = System.getProperty("file.encoding").toLowerCase();
+ String cpg = "UTF16";
+ /+
if (cpg.startsWith("cp") || cpg.startsWith("ms")) {
cpg = cpg.substring(2, cpg.length());
header.append("\\ansicpg");
header.append(cpg);
}
+ +/
header.append("\\uc0\\deff0{\\fonttbl{\\f0\\fnil ");
header.append(fontData.getName());
header.append(";");
- for (int i = 1; i < fontTable.size(); i++) {
+ for (int i = 1; i < fontTable.length; i++) {
header.append("\\f");
header.append(i);
header.append(" ");
- FontData fd = (cast(Font)fontTable.elementAt(i)).getFontData()[0];
+ FontData fd = (cast(Font)fontTable[i]).getFontData()[0];
header.append(fd.getName());
- header.append(";");
+ header.append(";");
}
header.append("}}\n{\\colortbl");
- for (int i = 0; i < colorTable.size(); i++) {
- Color color = cast(Color) colorTable.elementAt(i);
+ for (int i = 0; i < colorTable.length; i++) {
+ Color color = cast(Color) colorTable[i];
header.append("\\red");
header.append(color.getRed());
header.append("\\green");
@@ -836,7 +941,7 @@
header.append(color.getBlue());
header.append(";");
}
- // some RTF readers ignore the deff0 font tag. Explicitly
+ // 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
@@ -845,20 +950,20 @@
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
+ * 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
+ * @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 DWTException TextWriter
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
+ * 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()
+ * 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.
@@ -1061,23 +1167,23 @@
}
/**
* Closes the writer. Once closed no more content can be written.
- * NOTE: toString()
is not guaranteed to return a valid String unless
+ * NOTE: toString()
is not guaranteed to return a valid string unless
* the writer is closed.
*/
public void close() {
- if (!isClosed) {
- isClosed = true;
- }
- }
- /**
+ 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
+ }
+ /**
+ * 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
*/
@@ -1089,37 +1195,38 @@
* @return a bool specifying whether or not the writer is closed
*/
public bool isClosed() {
- return isClosed;
+ return isClosed_;
}
/**
- * Returns the String. close()
must be called before toString()
- * is guaranteed to return a valid String.
+ * Returns the string. close()
must be called before toString()
+ * is guaranteed to return a valid string.
*
- * @return the String
+ * @return the string
*/
- public String toString() {
+ public override String toString() {
return buffer.toString();
}
/**
- * Appends the given String to the data.
+ * Appends the given string to the data.
*/
- void write(String String) {
- buffer.append(String);
+ void write(String string) {
+ buffer.append(string);
}
/**
- * Inserts the given String to the data at the specified offset.
+ * 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. + * @param string text to insert + * @param offset offset in the existing data to insert "string" at. */ - void write(String String, int offset) { + void write(String string, int offset) { if (offset < 0 || offset > buffer.length()) { return; } - buffer.insert(offset, String); + buffer.select( offset ); + buffer.prepend( string ); } /** * Appends the given int to the data. @@ -1138,19 +1245,19 @@ * * @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 + * @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 DWTException
* The style value is either one of the style constants defined in
* class DWT
which is applicable to instances of this
- * class, or must be built by bitwise OR'ing together
+ * class, or must be built by bitwise OR'ing together
* (that is, using the int
"|" operator) two or more
* of those DWT
style constants. The class description
* lists the style constants that are applicable to the class.
@@ -1211,13 +1318,14 @@
* @see #getStyle
*/
public this(Composite parent, int style) {
+ selection = new Point(0, 0);
super(parent, checkStyle(style));
// set the fg in the OS to ensure that these are the same as StyledText, necessary
// for ensuring that the bg/fg the IME box uses is the same as what StyledText uses
super.setForeground(getForeground());
super.setDragDetect(false);
Display display = getDisplay();
- isMirrored = (super.getStyle() & DWT.MIRRORED) !is 0;
+ isMirrored_ = (super.getStyle() & DWT.MIRRORED) !is 0;
fixedLineHeight = true;
if ((style & DWT.READ_ONLY) !is 0) {
setEditable(false);
@@ -1240,7 +1348,7 @@
}
if (isBidiCaret()) {
createCaretBitmaps();
- Runnable runnable = new Runnable() {
+ Runnable runnable = new class() Runnable {
public void run() {
int direction = BidiUtil.getKeyboardLanguage() is BidiUtil.KEYBOARD_BIDI ? DWT.RIGHT : DWT.LEFT;
if (direction is caretDirection) return;
@@ -1251,7 +1359,7 @@
};
BidiUtil.addLanguageListener(this, runnable);
}
- setCaret(defaultCaret);
+ setCaret(defaultCaret);
calculateScrollBars();
createKeyBindings();
setCursor(display.getSystemCursor(DWT.CURSOR_IBEAM));
@@ -1259,8 +1367,8 @@
initializeAccessible();
setData("DEFAULT_DROP_TARGET_EFFECT", new StyledTextDropTargetEffect(this));
}
-/**
- * Adds an extended modify listener. An ExtendedModify event is sent by the
+/**
+ * Adds an extended modify listener. An ExtendedModify event is sent by the
* widget when the widget text has changed.
*
* @param extendedModifyListener the listener
@@ -1281,15 +1389,15 @@
/**
* Adds a bidirectional segment listener.
*
- * 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 + * 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 + * 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. + * way they are stored. *
* * @param listener the listener @@ -1309,7 +1417,7 @@ addListener(LineGetSegments, new StyledTextListener(listener)); } /** - * Adds a line background listener. A LineGetBackground event is sent by the + * Adds a line background listener. A LineGetBackground event is sent by the * widget to determine the background color for a line. * * @param listener the listener @@ -1330,7 +1438,7 @@ addListener(LineGetBackground, new StyledTextListener(listener)); } /** - * Adds a line style listener. A LineGetStyle event is sent by the widget to + * Adds a line style listener. A LineGetStyle event is sent by the widget to * determine the styles for a line. * * @param listener the listener @@ -1351,8 +1459,8 @@ } addListener(LineGetStyle, new StyledTextListener(listener)); } -/** - * Adds a modify listener. A Modify event is sent by the widget when the widget text +/** + * Adds a modify listener. A Modify event is sent by the widget when the widget text * has changed. * * @param modifyListener the listener @@ -1369,7 +1477,7 @@ if (modifyListener is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); addListener(DWT.Modify, new TypedListener(modifyListener)); } -/** +/** * Adds a paint object listener. A paint object event is sent by the widget when an object * needs to be drawn. * @@ -1381,9 +1489,9 @@ * @exception IllegalArgumentException
* 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.
*
* 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
+ * 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
+ * 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 DWT.SINGLE style. *
* - * @param text the text that may have line delimiters that don't - * match the model line delimiter. Possible line delimiters + * @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 + * @return the converted text that only uses the line delimiter + * specified by the model. Returns only the first line if the widget * has the DWT.SINGLE style. */ -String getModelDelimitedText(String text) { - int length = text.length(); +String getModelDelimitedText(String text) { + int length = text.length; if (length is 0) { return text; - } + } int crIndex = 0; int lfIndex = 0; int i = 0; @@ -1827,10 +1933,10 @@ String delimiter = getLineDelimiter(); while (i < length) { if (crIndex !is -1) { - crIndex = text.indexOf(DWT.CR, i); + crIndex = text.indexOf (DWT.CR, i); } if (lfIndex !is -1) { - lfIndex = text.indexOf(DWT.LF, i); + lfIndex = text.indexOf (DWT.LF, i); } if (lfIndex is -1 && crIndex is -1) { // no more line breaks? break; @@ -1850,7 +1956,7 @@ } convertedText.append(delimiter); } - // copy remaining text if any and if not in single line mode or no + // 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() is 0)) { convertedText.append(text.substring(i)); @@ -1877,9 +1983,9 @@ void createKeyBindings() { int nextKey = isMirrored() ? DWT.ARROW_LEFT : DWT.ARROW_RIGHT; int previousKey = isMirrored() ? DWT.ARROW_RIGHT : DWT.ARROW_LEFT; - + // Navigation - setKeyBinding(DWT.ARROW_UP, ST.LINE_UP); + setKeyBinding(DWT.ARROW_UP, ST.LINE_UP); setKeyBinding(DWT.ARROW_DOWN, ST.LINE_DOWN); if (IS_CARBON) { setKeyBinding(previousKey | DWT.MOD1, ST.LINE_START); @@ -1904,23 +2010,23 @@ setKeyBinding(DWT.PAGE_DOWN | DWT.MOD1, ST.WINDOW_END); setKeyBinding(nextKey, ST.COLUMN_NEXT); setKeyBinding(previousKey, ST.COLUMN_PREVIOUS); - + // Selection - setKeyBinding(DWT.ARROW_UP | DWT.MOD2, ST.SELECT_LINE_UP); + setKeyBinding(DWT.ARROW_UP | DWT.MOD2, ST.SELECT_LINE_UP); setKeyBinding(DWT.ARROW_DOWN | DWT.MOD2, ST.SELECT_LINE_DOWN); if (IS_CARBON) { setKeyBinding(previousKey | DWT.MOD1 | DWT.MOD2, ST.SELECT_LINE_START); setKeyBinding(nextKey | DWT.MOD1 | DWT.MOD2, ST.SELECT_LINE_END); - setKeyBinding(DWT.HOME | DWT.MOD2, ST.SELECT_TEXT_START); + setKeyBinding(DWT.HOME | DWT.MOD2, ST.SELECT_TEXT_START); setKeyBinding(DWT.END | DWT.MOD2, ST.SELECT_TEXT_END); - setKeyBinding(DWT.ARROW_UP | DWT.MOD1 | DWT.MOD2, ST.SELECT_TEXT_START); + setKeyBinding(DWT.ARROW_UP | DWT.MOD1 | DWT.MOD2, ST.SELECT_TEXT_START); setKeyBinding(DWT.ARROW_DOWN | DWT.MOD1 | DWT.MOD2, ST.SELECT_TEXT_END); setKeyBinding(nextKey | DWT.MOD2 | DWT.MOD3, ST.SELECT_WORD_NEXT); setKeyBinding(previousKey | DWT.MOD2 | DWT.MOD3, ST.SELECT_WORD_PREVIOUS); } else { setKeyBinding(DWT.HOME | DWT.MOD2, ST.SELECT_LINE_START); setKeyBinding(DWT.END | DWT.MOD2, ST.SELECT_LINE_END); - setKeyBinding(DWT.HOME | DWT.MOD1 | DWT.MOD2, ST.SELECT_TEXT_START); + setKeyBinding(DWT.HOME | DWT.MOD1 | DWT.MOD2, ST.SELECT_TEXT_START); setKeyBinding(DWT.END | DWT.MOD1 | DWT.MOD2, ST.SELECT_TEXT_END); setKeyBinding(nextKey | DWT.MOD1 | DWT.MOD2, ST.SELECT_WORD_NEXT); setKeyBinding(previousKey | DWT.MOD1 | DWT.MOD2, ST.SELECT_WORD_PREVIOUS); @@ -1930,8 +2036,8 @@ setKeyBinding(DWT.PAGE_UP | DWT.MOD1 | DWT.MOD2, ST.SELECT_WINDOW_START); setKeyBinding(DWT.PAGE_DOWN | DWT.MOD1 | DWT.MOD2, ST.SELECT_WINDOW_END); setKeyBinding(nextKey | DWT.MOD2, ST.SELECT_COLUMN_NEXT); - setKeyBinding(previousKey | DWT.MOD2, ST.SELECT_COLUMN_PREVIOUS); - + setKeyBinding(previousKey | DWT.MOD2, ST.SELECT_COLUMN_PREVIOUS); + // Modification // Cut, Copy, Paste setKeyBinding('X' | DWT.MOD1, ST.CUT); @@ -1952,7 +2058,7 @@ setKeyBinding(DWT.DEL, ST.DELETE_NEXT); setKeyBinding(DWT.BS | DWT.MOD1, ST.DELETE_WORD_PREVIOUS); setKeyBinding(DWT.DEL | DWT.MOD1, ST.DELETE_WORD_NEXT); - + // Miscellaneous setKeyBinding(DWT.INSERT, ST.TOGGLE_OVERWRITE); } @@ -1965,30 +2071,30 @@ int caretWidth = BIDI_CARET_WIDTH; Display display = getDisplay(); if (leftCaretBitmap !is null) { - if (defaultCaret !is null && leftCaretBitmap.opEquals(defaultCaret.getImage())) { + if (defaultCaret !is null && leftCaretBitmap==/*eq*/defaultCaret.getImage()) { defaultCaret.setImage(null); } leftCaretBitmap.dispose(); } int lineHeight = renderer.getLineHeight(); leftCaretBitmap = new Image(display, caretWidth, lineHeight); - GC gc = new GC (leftCaretBitmap); + GC gc = new GC (leftCaretBitmap); gc.setBackground(display.getSystemColor(DWT.COLOR_BLACK)); gc.fillRectangle(0, 0, caretWidth, lineHeight); gc.setForeground(display.getSystemColor(DWT.COLOR_WHITE)); gc.drawLine(0,0,0,lineHeight); gc.drawLine(0,0,caretWidth-1,0); gc.drawLine(0,1,1,1); - gc.dispose(); - + gc.dispose(); + if (rightCaretBitmap !is null) { - if (defaultCaret !is null && rightCaretBitmap.opEquals(defaultCaret.getImage())) { + if (defaultCaret !is null && rightCaretBitmap==/*eq*/defaultCaret.getImage()) { defaultCaret.setImage(null); } rightCaretBitmap.dispose(); } rightCaretBitmap = new Image(display, caretWidth, lineHeight); - gc = new GC (rightCaretBitmap); + gc = new GC (rightCaretBitmap); gc.setBackground(display.getSystemColor(DWT.COLOR_BLACK)); gc.fillRectangle(0, 0, caretWidth, lineHeight); gc.setForeground(display.getSystemColor(DWT.COLOR_WHITE)); @@ -1998,7 +2104,7 @@ gc.dispose(); } /** - * Moves the selected text to the clipboard. The text will be put in the + * Moves the selected text to the clipboard. The text will be put in the * clipboard in plain text format and RTF format. * * @exception DWTException- * If a carriage return was typed replace it with the line break character + * 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) { +void doContent(dchar key) { Event event = new Event(); event.start = selection.x; event.end = selection.y; @@ -2162,18 +2277,18 @@ } } else if (selection.x is selection.y && overwrite && key !is TAB) { // no selection and overwrite mode is on and the typed key is not a - // tab character (tabs are always inserted without overwriting)? + // 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 + // 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}); + if (event.end < lineOffset + line.length) { + event.end+=dcharToString( key ).length; + } + event.text = dcharToString( key ); } else { - event.text = new String(new char[] {key}); + event.text = dcharToString( key ); } if (event.text !is null) { if (textLimit > 0 && content.getCharCount() - (event.end - event.start) >= textLimit) { @@ -2186,12 +2301,12 @@ * 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 + // place caret at end of first line if receiver is in single // line mode. fixes 4820. if (isSingleLine()) { doLineEnd(); } else { - int length = content.getCharCount(); + int length = content.getCharCount(); if (caretOffset < length) { caretOffset = length; showCaret(); @@ -2209,7 +2324,7 @@ } /** * Moves the caret to the start of the selection if a selection exists. - * Otherwise, if no selection exists move the cursor according to the + * Otherwise, if no selection exists move the cursor according to the * cursor selection rules. * * @see #doSelectionCursorPrevious @@ -2225,7 +2340,7 @@ } /** * Moves the caret to the end of the selection if a selection exists. - * Otherwise, if no selection exists move the cursor according to the + * Otherwise, if no selection exists move the cursor according to the * cursor selection rules. * * @see #doSelectionCursorNext @@ -2252,7 +2367,7 @@ } else if (caretOffset < content.getCharCount()) { int line = content.getLineAtOffset(caretOffset); int lineOffset = content.getOffsetAtLine(line); - int lineLength = content.getLine(line).length(); + int lineLength = content.getLine(line).length; if (caretOffset is lineOffset + lineLength) { event.start = caretOffset; event.end = content.getOffsetAtLine(line + 1); @@ -2268,7 +2383,7 @@ */ void doDeleteWordNext() { if (selection.x !is selection.y) { - // if a selection exists, treat the as if + // if a selection exists, treat the as if // only the delete key was pressed doDelete(); } else { @@ -2284,7 +2399,7 @@ */ void doDeleteWordPrevious() { if (selection.x !is selection.y) { - // if a selection exists, treat as if + // if a selection exists, treat as if // only the backspace key was pressed doBackspace(); } else { @@ -2296,8 +2411,8 @@ } } /** - * 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 + * 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(bool select) { @@ -2330,8 +2445,8 @@ int oldColumnX = columnX; int oldHScrollOffset = horizontalScrollOffset; if (select) { - setMouseWordSelectionAnchor(); - // select first and then scroll to reduce flash when key + setMouseWordSelectionAnchor(); + // select first and then scroll to reduce flash when key // repeat scrolls lots of lines doSelection(ST.COLUMN_NEXT); } @@ -2344,7 +2459,7 @@ */ void doLineEnd() { int caretLine = getCaretLine(); - int lineOffset = content.getOffsetAtLine(caretLine); + int lineOffset = content.getOffsetAtLine(caretLine); int lineEndOffset; if (wordWrap) { TextLayout layout = renderer.getTextLayout(caretLine); @@ -2354,7 +2469,7 @@ lineEndOffset = lineOffset + offsets[lineIndex + 1]; renderer.disposeTextLayout(layout); } else { - int lineLength = content.getLine(caretLine).length(); + int lineLength = content.getLine(caretLine).length; lineEndOffset = lineOffset + lineLength; } if (caretOffset < lineEndOffset) { @@ -2384,8 +2499,8 @@ } } /** - * 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 + * 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(bool select) { @@ -2435,25 +2550,25 @@ int line = getLineIndex(y); updateCaretDirection = true; - // allow caret to be placed below first line only if receiver is + // 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 oldCaretAlignment = caretAlignment; int newCaretOffset = getOffsetAtPoint(x, y); - + 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 + + // 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 - if (0 <= y && y < clientAreaHeight && - (0 <= x && x < clientAreaWidth || wordWrap || + if (0 <= y && y < clientAreaHeight && + (0 <= x && x < clientAreaWidth || wordWrap || newCaretLine !is content.getLineAtOffset(caretOffset))) { if (newCaretOffset !is caretOffset || caretAlignment !is oldCaretAlignment) { caretOffset = newCaretOffset; @@ -2470,8 +2585,8 @@ * Updates the selection based on the caret position */ void doMouseSelection() { - if (caretOffset <= selection.x || - (caretOffset > selection.x && + if (caretOffset <= selection.x || + (caretOffset > selection.x && caretOffset < selection.y && selectionAnchor is selection.x)) { doSelection(ST.COLUMN_PREVIOUS); } else { @@ -2479,20 +2594,20 @@ } } /** - * Returns the offset of the word at the specified offset. - * If the current selection : from high index to low index - * (i.e., right to left, or caret is at left border of selection on + * 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 : from - * low index to high index the end offset of the word following + * 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 + // 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) @@ -2517,7 +2632,7 @@ if (line + 1 < content.getLineCount()) { lineEnd = content.getOffsetAtLine(line + 1); } - newCaretOffset = lineEnd; + newCaretOffset = lineEnd; } } } @@ -2527,9 +2642,9 @@ * 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 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. *
* @@ -2546,7 +2661,7 @@ int lineHeight = renderer.getLineHeight(); int lines = (height is -1 ? clientAreaHeight : height) / lineHeight; int scrollLines = Math.min(lineCount - caretLine - 1, lines); - // ensure that scrollLines never gets negative and at least one + // ensure that scrollLines never gets negative and at least one // line is scrolled. fixes bug 5602. scrollLines = Math.max(1, scrollLines); caretOffset = getOffsetAtPoint(columnX, getLinePixel(caretLine + scrollLines)); @@ -2627,10 +2742,10 @@ height = getAvailableHeightBellow(height); scrollVertical(height, true); if (height is 0) setCaretLocation(); - } + } showCaret(); int hScrollChange = oldHScrollOffset - horizontalScrollOffset; - columnX = oldColumnX + hScrollChange; + columnX = oldColumnX + hScrollChange; } /** * Moves the cursor to the end of the last fully visible line. @@ -2652,14 +2767,14 @@ index--; } if (index is -1 && lineIndex > 0) { - bottomOffset = content.getOffsetAtLine(lineIndex - 1) + content.getLine(lineIndex - 1).length(); + 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(); + bottomOffset = content.getOffsetAtLine(lineIndex) + content.getLine(lineIndex).length; } if (caretOffset < bottomOffset) { caretOffset = bottomOffset; @@ -2695,7 +2810,7 @@ } else { topOffset = content.getOffsetAtLine(lineIndex) + layout.getLineOffsets()[index]; } - renderer.disposeTextLayout(layout); + renderer.disposeTextLayout(layout); } else { topOffset = content.getOffsetAtLine(topIndex); } @@ -2708,17 +2823,17 @@ /** * 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 + * 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(bool select, int height) { if (isSingleLine()) return; int oldHScrollOffset = horizontalScrollOffset; - int oldColumnX = columnX; + int oldColumnX = columnX; if (isFixedLineHeight()) { - int caretLine = getCaretLine(); + int caretLine = getCaretLine(); if (caretLine > 0) { int lineHeight = renderer.getLineHeight(); int lines = (height is -1 ? clientAreaHeight : height) / lineHeight; @@ -2798,11 +2913,11 @@ lineHeight = renderer.getLineHeight(--lineIndex); } lineHeight = renderer.getLineHeight(lineIndex); - caretOffset = getOffsetAtPoint(columnX, lineHeight - caretHeight, lineIndex); + caretOffset = getOffsetAtPoint(columnX, lineHeight - caretHeight, lineIndex); if (select) doSelection(ST.COLUMN_PREVIOUS); height = getAvailableHeightAbove(height); scrollVertical(-height, true); - if (height is 0) setCaretLocation(); + if (height is 0) setCaretLocation(); } showCaret(); int hScrollChange = oldHScrollOffset - horizontalScrollOffset; @@ -2813,15 +2928,15 @@ */ void doSelection(int direction) { int redrawStart = -1; - int redrawEnd = -1; + int redrawEnd = -1; if (selectionAnchor is -1) { selectionAnchor = selection.x; - } + } if (direction is ST.COLUMN_PREVIOUS) { if (caretOffset < selection.x) { // grow selection - redrawEnd = selection.x; - redrawStart = selection.x = caretOffset; + redrawEnd = selection.x; + redrawStart = selection.x = caretOffset; // check if selection has reversed direction if (selection.y !is selectionAnchor) { redrawEnd = selection.y; @@ -2829,10 +2944,10 @@ } // test whether selection actually changed. Fixes 1G71EO1 } else if (selectionAnchor is selection.x && caretOffset < selection.y) { - // caret moved towards selection anchor (left side of selection). - // shrink selection + // caret moved towards selection anchor (left side of selection). + // shrink selection redrawEnd = selection.y; - redrawStart = selection.y = caretOffset; + redrawStart = selection.y = caretOffset; } } else { if (caretOffset > selection.y) { @@ -2841,15 +2956,15 @@ redrawEnd = selection.y = caretOffset; // check if selection has reversed direction if (selection.x !is selectionAnchor) { - redrawStart = selection.x; + redrawStart = selection.x; selection.x = selectionAnchor; } - // test whether selection actually changed. Fixes 1G71EO1 + // test whether selection actually changed. Fixes 1G71EO1 } else if (selectionAnchor is selection.y && caretOffset > selection.x) { - // caret moved towards selection anchor (right side of selection). - // shrink selection + // caret moved towards selection anchor (right side of selection). + // shrink selection redrawStart = selection.x; - redrawEnd = selection.x = caretOffset; + redrawEnd = selection.x = caretOffset; } } if (redrawStart !is -1 && redrawEnd !is -1) { @@ -2858,14 +2973,14 @@ } } /** - * Moves the caret to the next character or to the beginning of the + * 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; - if (offsetInLine < content.getLine(caretLine).length()) { + if (offsetInLine < content.getLine(caretLine).length) { TextLayout layout = renderer.getTextLayout(caretLine); offsetInLine = layout.getNextOffset(offsetInLine, DWT.MOVEMENT_CLUSTER); int lineStart = layout.getLineOffsets()[layout.getLineIndex(offsetInLine)]; @@ -2874,14 +2989,14 @@ caretAlignment = offsetInLine is lineStart ? OFFSET_LEADING : PREVIOUS_OFFSET_TRAILING; showCaret(); } else if (caretLine < content.getLineCount() - 1 && !isSingleLine()) { - caretLine++; + caretLine++; caretOffset = content.getOffsetAtLine(caretLine); caretAlignment = PREVIOUS_OFFSET_TRAILING; showCaret(); } } /** - * Moves the caret to the previous character or to the end of the previous + * 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() { @@ -2889,21 +3004,22 @@ int lineOffset = content.getOffsetAtLine(caretLine); int offsetInLine = caretOffset - lineOffset; caretAlignment = OFFSET_LEADING; + if (offsetInLine > 0) { caretOffset = getClusterPrevious(caretOffset, caretLine); showCaret(); } else if (caretLine > 0) { caretLine--; lineOffset = content.getOffsetAtLine(caretLine); - caretOffset = lineOffset + content.getLine(caretLine).length(); + caretOffset = lineOffset + content.getLine(caretLine).length; 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 + * 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 + * 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 @@ -2915,8 +3031,8 @@ 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 + * 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. @@ -2925,17 +3041,17 @@ * direction. */ void doSelectionLineUp() { - int oldColumnX = columnX = getPointAtOffset(caretOffset).x; - doLineUp(true); + 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 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 @@ -2952,8 +3068,8 @@ * 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 + * 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. *
@@ -2974,9 +3090,9 @@ int newCaretOffset = getWordNext(caretOffset, DWT.MOVEMENT_WORD); // Force symmetrical movement for word next and previous. Fixes 14536 caretAlignment = OFFSET_LEADING; - // don't change caret position if in single line mode and the cursor + // don't change caret position if in single line mode and the cursor // would be on a different line. fixes 5673 - if (!isSingleLine() || + if (!isSingleLine() || content.getLineAtOffset(caretOffset) is content.getLineAtOffset(newCaretOffset)) { caretOffset = newCaretOffset; showCaret(); @@ -2999,8 +3115,8 @@ } /** * 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 + * 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() { @@ -3009,8 +3125,8 @@ } /** * 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 + * 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() { @@ -3043,13 +3159,13 @@ doSelectionWordPrevious(); } } -/** +/** * Ends the autoscroll process. */ void endAutoScroll() { autoScrollDirection = DWT.NULL; } -public Color getBackground() { +public override Color getBackground() { checkWidget(); if (background is null) { return getDisplay().getSystemColor(DWT.COLOR_LIST_BACKGROUND); @@ -3058,9 +3174,9 @@ } /** * 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). + * + * 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 DWTException
* * @param lineIndex index of the line to return. * @return the line text without delimiters - * + * * @exception DWTException
- * Note: this API should not be used if a StyleRange attribute causes lines to + * Note: this API should not be used if a StyleRange attribute causes lines to * have different heights (i.e. different fonts, rise, etc). *
* @@ -3583,17 +3701,17 @@ * Returns the line height at the given offset. * * @param offset the offset - * + * * @return line height in pixels - * + * * @exception DWTException- * If there is a LineStyleListener but it does not set any styles, - * the StyledTextEvent.styles field will be initialized to an empty + * 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 + * + * @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 + * @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) { @@ -3701,11 +3819,13 @@ /** * 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 is 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. - * + * 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) { @@ -3733,6 +3853,10 @@ * 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) { @@ -3762,59 +3886,59 @@ return line; } /** - * Returns the x, y location of the upper left corner of the character - * bounding box at the specified offset in the text. The point is + * Returns the x, y location of the upper left corner of the character + * bounding box at the specified offset in the text. The point is * relative to the upper left corner of the widget client area. * - * @param offset offset relative to the start of the content. + * @param offset offset relative to the start of the content. * 0 <= offset <= getCharCount() - * @return x, y location of the upper left corner of the character + * @return x, y location of the upper left corner of the character * bounding box at the specified offset in the text. * @exception DWTException* The return value reflects the character offset that the caret will @@ -3823,9 +3947,9 @@ * the returned offset will be behind the character. *
* - * @param point the origin of character bounding box relative to + * @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 + * @return offset of the character at the given location relative * to the first character in the document. * @exception DWTException
* The ranges array contains start and length pairs. Each pair refers to
@@ -3996,16 +4120,16 @@
* that starts at ranges[n] with length ranges[n+1] uses the style
* at styles[n/2] returned by getStyleRanges(int, int, bool)
.
*
* The ranges array contains start and length pairs. Each pair refers to @@ -4030,19 +4154,19 @@ * * @param start the start offset of the style ranges to return * @param length the number of style ranges to return - * + * * @return the ranges or an empty array if a LineStyleListener has been set. - * + * * @exception DWTException
* Text selections are specified in terms of caret positions. In a text - * widget that contains N characters, there are N+1 caret positions, + * 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 + * @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 cast(RtoL) vs. left-to-right - * cast(LtoR), compare the caretOffset to the start and end of the selection + * 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 is start of selection implies that the selection is RtoL). * @see #getSelectionRange * @exception DWTException* 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 + * 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. + * @param offset the offset to return the style for. * 0 <= offset < getCharCount() must be true. * @return a StyleRange with start is offset and length is 1, indicating - * the style at the given offset. null if a LineStyleListener has been set + * 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 DWTException- * Returns an empty array if a LineStyleListener has been set. - * Should not be called if a LineStyleListener has been set since the + * 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 @@ -4333,7 +4457,7 @@ *- * Returns an empty array if a LineStyleListener has been set. - * Should not be called if a LineStyleListener has been set since the + * 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
@@ -4353,18 +4477,18 @@
* 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 + * 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
@@ -4388,10 +4512,10 @@
* @param start the start offset of the style ranges to return
* @param length the number of style ranges to return
*
- * @return the styles or an empty array if a LineStyleListener has
- * been set. The returned styles will reflect the given range. The first
- * returned StyleRange
will have a starting offset >= start
- * and the last returned StyleRange
will have an ending
+ * @return the styles or an empty array if a LineStyleListener has
+ * been set. The returned styles will reflect the given range. The first
+ * returned StyleRange
will have a starting offset >= start
+ * and the last returned StyleRange
will have an ending
* offset <= start + length - 1
*
* @exception DWTException
- * Returns an empty array if a LineStyleListener has been set. - * Should not be called if a LineStyleListener has been set since the + * 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
@@ -4423,15 +4547,15 @@
* 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
+ * @return the styles or an empty array if a LineStyleListener has
+ * been set. The returned styles will reflect the given range. The first
+ * returned StyleRange
will have a starting offset >= start
+ * and the last returned StyleRange
will have an ending
* offset <= start + length - 1
*
* @exception DWTException - * 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 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. *
* @@ -4623,10 +4747,10 @@ /** * Gets the top pixel. *- * 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 + * 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. *
* @@ -4640,7 +4764,7 @@ checkWidget(); return getVerticalScrollOffset(); } -/** +/** * Returns the vertical scroll increment. * * @return vertical scroll increment. @@ -4679,12 +4803,12 @@ int lineOffset = content.getOffsetAtLine(caretLine); String line = content.getLine(caretLine); int offset = caretOffset - lineOffset; - int lineLength = line.length(); + int lineLength = line.length; if (lineLength is 0) return isMirrored() ? DWT.RIGHT : DWT.LEFT; if (caretAlignment is PREVIOUS_OFFSET_TRAILING && offset > 0) offset--; if (offset is lineLength && offset > 0) offset--; - while (offset > 0 && Character.isDigit(line.charAt(offset))) offset--; - if (offset is 0 && Character.isDigit(line.charAt(offset))) { + while (offset > 0 && tango.text.Unicode.isDigit(line[offset])) offset--; + if (offset is 0 && tango.text.Unicode.isDigit(line[offset])) { return isMirrored() ? DWT.RIGHT : DWT.LEFT; } TextLayout layout = renderer.getTextLayout(caretLine); @@ -4717,7 +4841,7 @@ int lineIndex = content.getLineAtOffset(offset); lineOffset = content.getOffsetAtLine(lineIndex); lineText = content.getLine(lineIndex); - int lineLength = lineText.length(); + int lineLength = lineText.length; if (offset is lineOffset + lineLength) { newOffset = content.getOffsetAtLine(lineIndex + 1); } else { @@ -4742,12 +4866,12 @@ lineText = content.getLine(lineIndex); if (offset is lineOffset) { String nextLineText = content.getLine(lineIndex - 1); - int nextLineOffset = content.getOffsetAtLine(lineIndex - 1); - newOffset = nextLineOffset + nextLineText.length(); + int nextLineOffset = content.getOffsetAtLine(lineIndex - 1); + newOffset = nextLineOffset + nextLineText.length; } else { TextLayout layout = renderer.getTextLayout(lineIndex); newOffset = lineOffset + layout.getPreviousOffset(offset - lineOffset, movement); - renderer.disposeTextLayout(layout); + renderer.disposeTextLayout(layout); } } return sendWordBoundaryEvent(WordPrevious, movement, offset, newOffset, lineText, lineOffset); @@ -4762,7 +4886,7 @@ checkWidget(); return wordWrap; } -/** +/** * Returns the location of the given offset. ** NOTE: Does not return correct values for true italic fonts (vs. slanted fonts). @@ -4775,7 +4899,7 @@ String line = content.getLine(lineIndex); int lineOffset = content.getOffsetAtLine(lineIndex); int offsetInLine = offset - lineOffset; - int lineLength = line.length(); + int lineLength = line.length; if (lineIndex < content.getLineCount() - 1) { int endLineOffset = content.getOffsetAtLine(lineIndex + 1) - 1; if (lineLength < offsetInLine && offsetInLine <= endLineOffset) { @@ -4786,7 +4910,9 @@ TextLayout layout = renderer.getTextLayout(lineIndex); if (lineLength !is 0 && offsetInLine <= lineLength) { if (offsetInLine is lineLength) { - point = layout.getLocation(offsetInLine - 1, true); + // DWT: Instead of go back one byte, go back one codepoint + int offsetInLine_m1 = layout.getPreviousOffset(offsetInLine, DWT.MOVEMENT_CLUSTER); + point = layout.getLocation(offsetInLine_m1, true); } else { switch (caretAlignment) { case OFFSET_LEADING: @@ -4797,7 +4923,9 @@ if (offsetInLine is 0) { point = layout.getLocation(offsetInLine, false); } else { - point = layout.getLocation(offsetInLine - 1, true); + // DWT: Instead of go back one byte, go back one codepoint + int offsetInLine_m1 = layout.getPreviousOffset(offsetInLine, DWT.MOVEMENT_CLUSTER); + point = layout.getLocation(offsetInLine_m1, true); } break; } @@ -4810,32 +4938,30 @@ point.y += getLinePixel(lineIndex); return point; } -/** - * Inserts a String. The old selection is replaced with the new text. - * - * @param String the String +/** + * Inserts a string. The old selection is replaced with the new text. + * + * @param string the string * @see #replaceTextRange(int,int,String) * @exception DWTException
DND.CLIPBOARD
- * clipboard or, if there is no selection, inserts the text at the current
- * caret offset. If the widget has the DWT.SINGLE style and the
+/**
+ * Replaces the selection with the text on the DND.CLIPBOARD
+ * clipboard or, if there is no selection, inserts the text at the current
+ * caret offset. If the widget has the DWT.SINGLE style and the
* clipboard text contains more than one line, only the first line without
* line delimiters is inserted in the widget.
*
@@ -5900,9 +6037,12 @@
* * 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 DWTException * 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 DWTException
* 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
+ * 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
+ * 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
+ * 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.
*
* Note: Because a StyleRange includes the start and length, the
* same instance cannot occur multiple times in the array of styles.
@@ -6316,14 +6472,14 @@
* 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 + * 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 + * 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 DWTException* 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 + * 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 + * @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 + * @return StyledTextEvent that can be used to request line data * for the given line. */ StyledTextEvent sendLineEvent(int eventType, int lineOffset, String line) { @@ -6632,14 +6788,14 @@ } void sendModifyEvent(Event event) { Accessible accessible = getAccessible(); - if (event.text.length() is 0) { + if (event.text.length is 0) { accessible.textChanged(ACC.TEXT_DELETE, event.start, event.end - event.start); } else { if (event.start is event.end) { - accessible.textChanged(ACC.TEXT_INSERT, event.start, event.text.length()); + accessible.textChanged(ACC.TEXT_INSERT, event.start, event.text.length); } else { accessible.textChanged(ACC.TEXT_DELETE, event.start, event.end - event.start); - accessible.textChanged(ACC.TEXT_INSERT, event.start, event.text.length()); + accessible.textChanged(ACC.TEXT_INSERT, event.start, event.text.length); } } notifyListeners(DWT.Modify, event); @@ -6681,22 +6837,22 @@ return newOffset; } /** - * Sets the alignment of the widget. The argument should be one ofDWT.LEFT
,
+ * Sets the alignment of the widget. The argument should be one of DWT.LEFT
,
* DWT.CENTER
or DWT.RIGHT
. The alignment applies for all lines.
*
* Note that if DWT.MULTI
is set, then DWT.WRAP
must also be set
* in order to stabilize the right edge before setting alignment.
*
- * NOTE: The horizontal index is reset to 0 when new text is set in the + * 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 + * @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 DWTException- * NOTE: The horizontal pixel offset is reset to 0 when new text + * 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 + * @param pixel horizontal pixel offset relative to the start * of the line. * @exception DWTException- * 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. + * 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 DWTException- * One action can be associated with N keys. However, each key can only + * 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 DWT.java or a character. + * @param key a key code defined in DWT.java or a character. * Optionally ORd with a state mask. Preferred state masks are one or more of - * DWT.MOD1, DWT.MOD2, DWT.MOD3, since these masks account for modifier platform + * DWT.MOD1, DWT.MOD2, DWT.MOD3, since these masks account for modifier platform * differences. However, there may be cases where using the specific state masks * (i.e., DWT.CTRL, DWT.SHIFT, DWT.ALT, DWT.COMMAND) makes sense. - * @param action one of the predefined actions defined in ST.java. + * @param action one of the predefined actions defined in ST.java. * Use DWT.NULL to remove a key binding. * @exception DWTExceptionDWT.LEFT
,
+ keyActionMap[key]=action;
+ }
+ }
+}
+/**
+ * Sets the alignment of the specified lines. The argument should be one of DWT.LEFT
,
* DWT.CENTER
or DWT.RIGHT
.
*
* Note that if DWT.MULTI
is set, then DWT.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 + * 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. + * 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. - * + * 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 DWTException
* 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. + * 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 + * 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 + * 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. + * 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. + * 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 @@ -7252,7 +7405,7 @@ *- * Should not be called if a LineStyleListener has been set since the listener + * 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 + * 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. + * 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. + * 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 DWTException- * Should not be called if a LineStyleListener has been set since the listener + * 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 + * 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. + * 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. + * 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 DWTException- * Should not be called if a LineStyleListener has been set since the listener + * 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 + * 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. + * 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. + * 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 DWTExceptionDWT.LEFT_TO_RIGHT
or DWT.RIGHT_TO_LEFT
.
*
* @param orientation new orientation style
- *
- * @exception DWTException * Indexing is zero based. Text selections are specified in terms of - * caret positions. In a text widget that contains N characters, there are + * caret positions. In a text widget that contains N characters, there are * N+1 caret positions, ranging from 0..N *
* @@ -7574,13 +7727,13 @@ ** Note that this is a HINT. Some platforms do not allow the application * to change the selection foreground color. @@ -7618,7 +7771,7 @@ * @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 + * 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 + * @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) @@ -7651,7 +7804,7 @@ *- * The new selection may not be visible. Call showSelection to scroll + * 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. + * @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 + * @param sendEvent a Selection event is sent when set to true and when * the selection is reset. */ void setSelection(int start, int length, bool sendEvent) { int end = start + length; + start = content.utf8AdjustOffset(start); + end = content.utf8AdjustOffset(end); if (start > end) { int temp = end; end = start; start = temp; } - // is the selection range different or is the selection direction + // is the selection range different or is the selection direction // different? - if (selection.x !is start || selection.y !is end || - (length > 0 && selectionAnchor !is selection.x) || + if (selection.x !is start || selection.y !is end || + (length > 0 && selectionAnchor !is selection.x) || (length < 0 && selectionAnchor !is selection.y)) { clearSelection(sendEvent); if (length < 0) { @@ -7697,7 +7852,7 @@ internalRedrawRange(selection.x, selection.y - selection.x); } } -/** +/** * Sets the selection. ** The new selection may not be visible. Call showSelection to scroll the selection @@ -7706,13 +7861,13 @@ * * @param start offset of the first selected character * @param length number of characters to select - * + * * @exception DWTException
* 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. + * 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 + * Should not be called if a LineStyleListener has been set since the * listener maintains the styles. *
* @@ -7755,7 +7910,7 @@ *start
and
+/**
+ * Clears the styles in the range specified by start
and
* length
and adds the new styles.
* * The ranges array contains start and length pairs. Each pair refers to @@ -7784,7 +7939,7 @@ * 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 + * Should not be called if a LineStyleListener has been set since the * listener maintains the styles. *
* @@ -7792,19 +7947,19 @@ * @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 DWTException* All styles in the widget will be replaced with the given set of ranges and styles. @@ -7828,25 +7983,25 @@ * 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 + * 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 DWTException
* Note: Because a StyleRange includes the start and length, the
@@ -7956,32 +8111,32 @@
* 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 + * 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 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 DWTException- * Note: Only a single line of text should be set when the DWT.SINGLE + * Note: Only a single line of text should be set when the DWT.SINGLE * style is used. *
* - * @param text new widget content. Replaces existing content. Line styles + * @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 DWTException- * The top index is the index of the line that is currently at the top + * 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 + * @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 DWTException- * If the selection intersects with the replaced text, the selection is + * 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 + * same text remains selected. If the selection is before the replaced text * it is left unchanged. *
* @@ -8276,6 +8430,7 @@ 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) { @@ -8284,7 +8439,7 @@ } 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 + // 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; diff -r fbe68c33eeee -r 6337764516f1 dwt/custom/StyledTextContent.d --- a/dwt/custom/StyledTextContent.d Tue Oct 07 14:41:31 2008 +0200 +++ b/dwt/custom/StyledTextContent.d Tue Oct 07 16:29:55 2008 +0200 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. + * 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 @@ -7,15 +7,19 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Port to the D programming language: + * Frank Benoit* - * @param lineIndex index of the line to return. Does not include - * delimiters of preceding lines. Index 0 is the first line of the + * @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 */ @@ -57,12 +61,12 @@ * 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. + * @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: *
- * NOTE: When there is no text (i.e., no lines), getOffsetAtLine(0) + * 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. + * @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 + * @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 @@ -138,7 +142,8 @@ * Remove the specified text changed listener. *
* - * @param listener the 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
+ * 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
+ * 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
+ * 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
+ * Implementors have to send a TextChangedEvent
to the
+ * textSet method of the TextChangeListeners that were added using
* addTextChangeListener
.
*
*
@@ -203,4 +208,10 @@
* @see TextChangeListener
*/
public void setText(String text);
+
+/++
+ + DWT Extension
+ +/
+int utf8AdjustOffset( int offset );
+
}
diff -r fbe68c33eeee -r 6337764516f1 dwt/custom/StyledTextDropTargetEffect.d
--- a/dwt/custom/StyledTextDropTargetEffect.d Tue Oct 07 14:41:31 2008 +0200
+++ b/dwt/custom/StyledTextDropTargetEffect.d Tue Oct 07 16:29:55 2008 +0200
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2007 IBM Corporation and others.
+ * 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
@@ -7,31 +7,46 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ * Frank Benoit Classes that wish to provide their own drag under effect for a The feedback value is either one of the FEEDBACK constants defined in
- * class The feedback value is either one of the FEEDBACK constants defined in
+ * class
* StyledText
.
- *
+ *
* StyledText
* can extend this class, override the StyledTextDropTargetEffect.dragOver
- * method and override any other applicable methods in StyledTextDropTargetEffect
to
+ * 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.
*
- * DND
which is applicable to instances of this class,
- * or it must be built by bitwise OR'ing together
+ * 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.
+ * of those DND
effect constants.
*
@@ -39,31 +54,32 @@
*
*
StyledTextDropTargetEffect
to handle the drag under effect on the specified
+ * Creates a new 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 this(StyledText styledText) {
super(styledText);
- paintListener = new Listener () {
+ paintListener = new class() Listener {
public void handleEvent (Event event) {
if (currentOffset !is -1) {
StyledText text = cast(StyledText) getControl();
@@ -75,22 +91,22 @@
}
};
}
-
+
/**
* 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) {
+ public override void dragEnter(DropTargetEvent event) {
currentOffset = -1;
scrollBeginTime = 0;
scrollX = -1;
@@ -98,22 +114,22 @@
getControl().removeListener(DWT.Paint, paintListener);
getControl().addListener (DWT.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) {
+ public override void dragLeave(DropTargetEvent event) {
StyledText text = cast(StyledText) getControl();
if (currentOffset !is -1) {
refreshCaret(text, currentOffset, -1);
@@ -127,23 +143,23 @@
/**
* 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) {
+ public override void dragOver(DropTargetEvent event) {
int effect = event.feedback;
StyledText text = cast(StyledText) getControl();
-
+
Point pt = text.getDisplay().map(null, text, event.x, event.y);
if ((effect & DND.FEEDBACK_SCROLL) is 0) {
scrollBeginTime = 0;
@@ -190,7 +206,7 @@
}
}
}
-
+
if ((effect & DND.FEEDBACK_SELECT) !is 0) {
int[] trailing = new int [1];
int newOffset = text.getOffsetAtPoint(pt.x, pt.y, trailing, false);
@@ -220,18 +236,18 @@
/**
* 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) {
+ public override void dropAccept(DropTargetEvent event) {
if (currentOffset !is -1) {
StyledText text = cast(StyledText) getControl();
text.setSelection(currentOffset);
diff -r fbe68c33eeee -r 6337764516f1 dwt/custom/StyledTextEvent.d
--- a/dwt/custom/StyledTextEvent.d Tue Oct 07 14:41:31 2008 +0200
+++ b/dwt/custom/StyledTextEvent.d Tue Oct 07 16:29:55 2008 +0200
@@ -1,4 +1,4 @@
-/*******************************************************************************
+/*******************************************************************************
* 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
@@ -7,15 +7,21 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ * Frank Benoit * StyledTextPrintOptions options = new StyledTextPrintOptions(); - * options.footer = "\t\t<page>"; + * options.footer = "\t\t<page>"; * options.jobName = "Example"; * options.printLineBackground = true; - * - * Runnable runnable = styledText.print(new Printer(), options); + * + * Runnable runnable = styledText.print(new Printer(), options); * runnable.run(); *+ * + * @see Sample code and further information + * * @since 2.1 */ public class StyledTextPrintOptions { @@ -46,7 +53,7 @@ *
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
+ * (StyledTextPrintOptions.PAGE_TAG
). The three regions are
* left aligned, centered and right aligned. They are separated by a tab
* character (StyledTextPrintOptions.SEPARATOR
).
*/
@@ -57,7 +64,7 @@
*
left, center, right = <page> | #CDATA
*Header and footer are defined as three separate regions for arbitrary
* text or the page number placeholder <page>
- * ( Here is an example of using a TableCursor to navigate to a cell and then edit it.
- *
+ *
*
* The style value is either one of the style constants defined in
* class StyledTextPrintOptions.PAGE_TAG
). The three regions are
+ * (StyledTextPrintOptions.PAGE_TAG
). The three regions are
* left aligned, centered and right aligned. They are separated by a tab
* character (StyledTextPrintOptions.SEPARATOR
).
*/
@@ -66,7 +73,7 @@
* Name of the print job.
*/
public String jobName = null;
-
+
/**
* Print the text foreground color. Default value is false
.
*/
@@ -83,19 +90,19 @@
* Print the line background color. Default value is false
.
*/
public bool printLineBackground = false;
-
+
/**
* Print line numbers. Default value is false
.
- *
+ *
* @since 3.3
*/
public bool printLineNumbers = false;
-
+
/**
* Labels used for printing line numbers.
*
* @since 3.4
*/
public String[] lineLabels = null;
-
+
}
diff -r fbe68c33eeee -r 6337764516f1 dwt/custom/StyledTextRenderer.d
--- a/dwt/custom/StyledTextRenderer.d Tue Oct 07 14:41:31 2008 +0200
+++ b/dwt/custom/StyledTextRenderer.d Tue Oct 07 16:29:55 2008 +0200
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2007 IBM Corporation and others.
+ * 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
@@ -7,13 +7,44 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ * Frank Benoit
- *
+ *
*
* 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, DWT.BORDER | DWT.MULTI | DWT.FULL_SELECTION);
* table.setLayoutData(new GridData(GridData.FILL_BOTH));
@@ -41,22 +61,22 @@
* column1.pack();
* column2.pack();
* column3.pack();
- *
+ *
* // create a TableCursor to navigate around the table
* final TableCursor cursor = new TableCursor(table, DWT.NONE);
- * // create an editor to edit the cell when the user hits "ENTER"
+ * // 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
+ * // 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
+ * // 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, DWT.NONE);
@@ -65,7 +85,7 @@
* text.setText(row.getText(column));
* text.addKeyListener(new KeyAdapter() {
* public void keyPressed(KeyEvent e) {
- * // close the text editor and copy the data over
+ * // close the text editor and copy the data over
* // when the user hits "ENTER"
* if (e.character is DWT.CR) {
* TableItem row = cursor.getRow();
@@ -87,9 +107,9 @@
* // This allows the user to select multiple items in the table.
* cursor.addKeyListener(new KeyAdapter() {
* public void keyPressed(KeyEvent e) {
- * if (e.keyCode is DWT.MOD1 ||
- * e.keyCode is DWT.MOD2 ||
- * (e.stateMask & DWT.MOD1) !is 0 ||
+ * if (e.keyCode is DWT.MOD1 ||
+ * e.keyCode is DWT.MOD2 ||
+ * (e.stateMask & DWT.MOD1) !is 0 ||
* (e.stateMask & DWT.MOD2) !is 0) {
* cursor.setVisible(false);
* }
@@ -103,7 +123,7 @@
* if (e.keyCode is DWT.MOD2 && (e.stateMask & DWT.MOD1) !is 0) return;
* if (e.keyCode !is DWT.MOD1 && (e.stateMask & DWT.MOD1) !is 0) return;
* if (e.keyCode !is DWT.MOD2 && (e.stateMask & DWT.MOD2) !is 0) return;
- *
+ *
* TableItem[] selection = table.getSelection();
* TableItem row = (selection.length is 0) ? table.getItem(table.getTopIndex()) : selection[0];
* table.showItem(row);
@@ -112,7 +132,7 @@
* cursor.setFocus();
* }
* });
- *
+ *
* shell.open();
* while (!shell.isDisposed()) {
* if (!display.readAndDispatch())
@@ -121,18 +141,23 @@
* display.dispose();
* }
*
*
- *
+ *
* @since 2.0
- *
+ *
+ * @see TableCursor snippets
+ * @see Sample code and further information
*/
public class TableCursor : Canvas {
+
+ alias Canvas.dispose dispose;
+
Table table;
TableItem row = null;
TableColumn column = null;
@@ -151,7 +176,7 @@
* DWT
which is applicable to instances of this
- * class, or must be built by bitwise OR'ing together
+ * class, or must be built by bitwise OR'ing together
* (that is, using the int
"|" operator) two or more
* of those DWT
style constants. The class description
* lists the style constants that are applicable to the class.
@@ -178,8 +203,8 @@
table = parent;
setBackground(null);
setForeground(null);
-
- Listener listener = new Listener() {
+
+ Listener listener = new class() Listener {
public void handleEvent(Event event) {
switch (event.type) {
case DWT.Dispose :
@@ -203,18 +228,20 @@
case DWT.TRAVERSE_RETURN :
event.doit = false;
break;
+ default:
}
break;
}
+ default:
}
}
};
- int[] events = new int[] {DWT.Dispose, DWT.FocusIn, DWT.FocusOut, DWT.KeyDown, DWT.Paint, DWT.Traverse};
+ int[] events = [DWT.Dispose, DWT.FocusIn, DWT.FocusOut, DWT.KeyDown, DWT.Paint, DWT.Traverse];
for (int i = 0; i < events.length; i++) {
addListener(events[i], listener);
}
- tableListener = new Listener() {
+ tableListener = new class() Listener {
public void handleEvent(Event event) {
switch (event.type) {
case DWT.MouseDown :
@@ -223,13 +250,14 @@
case DWT.FocusIn :
tableFocusIn(event);
break;
+ default:
}
}
};
table.addListener(DWT.FocusIn, tableListener);
table.addListener(DWT.MouseDown, tableListener);
- disposeItemListener = new Listener() {
+ disposeItemListener = new class() Listener {
public void handleEvent(Event event) {
unhookRowColumnListeners();
row = null;
@@ -237,7 +265,7 @@
_resize();
}
};
- disposeColumnListener = new Listener() {
+ disposeColumnListener = new class() Listener {
public void handleEvent(Event event) {
unhookRowColumnListeners();
row = null;
@@ -245,7 +273,7 @@
_resize();
}
};
- resizeListener = new Listener() {
+ resizeListener = new class() Listener {
public void handleEvent(Event event) {
_resize();
}
@@ -285,7 +313,7 @@
* @see SelectionListener
* @see SelectionEvent
* @see #removeSelectionListener(SelectionListener)
- *
+ *
*/
public void addSelectionListener(SelectionListener listener) {
checkWidget();
@@ -316,6 +344,7 @@
case DWT.CR :
notifyListeners(DWT.DefaultSelection, new Event());
return;
+ default:
}
int rowIndex = table.indexOf(row);
int columnIndex = column is null ? 0 : table.indexOf(column);
@@ -328,7 +357,7 @@
break;
case DWT.ARROW_LEFT :
case DWT.ARROW_RIGHT :
- {
+ {
int columnCount = table.getColumnCount();
if (columnCount is 0) break;
int[] order = table.getColumnOrder();
@@ -387,6 +416,7 @@
setRowColumn(index, columnIndex, true);
break;
}
+ default:
}
}
@@ -408,14 +438,14 @@
x += imageSize.width;
}
String text = row.getText(columnIndex);
- if (text.length() > 0) {
+ if (text.length > 0) {
Rectangle bounds = row.getBounds(columnIndex);
- Point extent = gc.StringExtent(text);
+ Point extent = gc.stringExtent(text);
// Temporary code - need a better way to determine table trim
String platform = DWT.getPlatform();
- if ("win32".opEquals(platform)) { //$NON-NLS-1$
+ if ("win32"==platform) { //$NON-NLS-1$
if (table.getColumnCount() is 0 || columnIndex is 0) {
- x += 2;
+ x += 2;
} else {
int alignmnent = column.getAlignment();
switch (alignmnent) {
@@ -428,11 +458,12 @@
case DWT.CENTER:
x += (bounds.width - x - extent.x) / 2;
break;
+ default:
}
}
} else {
if (table.getColumnCount() is 0) {
- x += 5;
+ x += 5;
} else {
int alignmnent = column.getAlignment();
switch (alignmnent) {
@@ -445,6 +476,7 @@
case DWT.CENTER:
x += (bounds.width - x - extent.x) / 2 + 2;
break;
+ default:
}
}
}
@@ -557,7 +589,7 @@
}
}
-public void setVisible(bool visible) {
+public override void setVisible(bool visible) {
checkWidget();
if (visible) _resize();
super.setVisible(visible);
@@ -579,7 +611,7 @@
*
* @see SelectionListener
* @see #addSelectionListener(SelectionListener)
- *
+ *
* @since 3.0
*/
public void removeSelectionListener(SelectionListener listener) {
@@ -588,7 +620,7 @@
DWT.error(DWT.ERROR_NULL_ARGUMENT);
}
removeListener(DWT.Selection, listener);
- removeListener(DWT.DefaultSelection, listener);
+ removeListener(DWT.DefaultSelection, listener);
}
void _resize() {
@@ -669,7 +701,7 @@
*
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) {
+public override void setEditor (Control editor) {
super.setEditor(editor);
resize();
}
@@ -231,7 +251,7 @@
*
* 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
@@ -241,7 +261,7 @@
setColumn(column);
setEditor(editor);
}
-public void layout () {
+public override void layout () {
if (table is null || table.isDisposed()) return;
if (item is null || item.isDisposed()) return;
int columnCount = table.getColumnCount();
diff -r fbe68c33eeee -r 6337764516f1 dwt/custom/TableTree.d
--- a/dwt/custom/TableTree.d Tue Oct 07 14:41:31 2008 +0200
+++ b/dwt/custom/TableTree.d Tue Oct 07 16:29:55 2008 +0200
@@ -7,16 +7,38 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ * Frank Benoit
* Note: Only one of the styles SINGLE, and MULTI may be specified.
*
* The style value is either one of the style constants defined in
* class 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
@@ -486,7 +514,7 @@
* DWT
which is applicable to instances of this
- * class, or must be built by bitwise OR'ing together
+ * class, or must be built by bitwise OR'ing together
* (that is, using the int
"|" operator) two or more
* of those DWT
style constants. The class description
* lists the style constants that are applicable to the class.
@@ -94,40 +119,43 @@
*/
public this(Composite parent, int style) {
super(parent, checkStyle (style));
+ items = EMPTY_ITEMS;
table = new Table(this, style);
- Listener tableListener = new Listener() {
+ Listener tableListener = new class() Listener {
public void handleEvent(Event e) {
switch (e.type) {
case DWT.MouseDown: onMouseDown(e); break;
case DWT.Selection: onSelection(e); break;
case DWT.DefaultSelection: onSelection(e); break;
case DWT.KeyDown: onKeyDown(e); break;
+ default:
}
}
};
- int[] tableEvents = new int[]{DWT.MouseDown,
- DWT.Selection,
- DWT.DefaultSelection,
- DWT.KeyDown};
+ int[] tableEvents = [DWT.MouseDown,
+ DWT.Selection,
+ DWT.DefaultSelection,
+ DWT.KeyDown];
for (int i = 0; i < tableEvents.length; i++) {
table.addListener(tableEvents[i], tableListener);
}
-
- Listener listener = new Listener() {
+
+ Listener listener = new class() Listener {
public void handleEvent(Event e) {
switch (e.type) {
case DWT.Dispose: onDispose(e); break;
case DWT.Resize: onResize(e); break;
case DWT.FocusIn: onFocusIn(e); break;
+ default:
}
}
};
- int[] events = new int[]{DWT.Dispose,
- DWT.Resize,
- DWT.FocusIn};
+ int[] events = [DWT.Dispose,
+ DWT.Resize,
+ DWT.FocusIn];
for (int i = 0; i < events.length; i++) {
addListener(events[i], listener);
- }
+ }
}
int addItem(TableTreeItem item, int index) {
@@ -135,13 +163,13 @@
TableTreeItem[] newItems = new TableTreeItem[items.length + 1];
System.arraycopy(items, 0, newItems, 0, index);
newItems[index] = item;
- System.arraycopy(items, index, newItems, index + 1, items.length - index);
+ System.arraycopy(items, index, newItems, index + 1, items.length - index);
items = newItems;
/* Return the index in the table where this table should be inserted */
- if (index is items.length - 1 )
+ if (index is items.length - 1 )
return table.getItemCount();
- else
+ else
return table.indexOf(items[index+1].tableItem);
}
@@ -207,15 +235,15 @@
addListener (DWT.Collapse, typedListener);
}
private static int checkStyle (int style) {
- int mask = DWT.LEFT_TO_RIGHT | DWT.RIGHT_TO_LEFT;
+ int mask = DWT.LEFT_TO_RIGHT | DWT.RIGHT_TO_LEFT;
style = style & mask;
return style;
-}
-public Point computeSize (int wHint, int hHint, bool changed) {
+}
+public override Point computeSize (int wHint, int hHint, bool changed) {
checkWidget();
return table.computeSize (wHint, hHint, changed);
}
-public Rectangle computeTrim (int x, int y, int width, int height) {
+public override Rectangle computeTrim (int x, int y, int width, int height) {
checkWidget();
return table.computeTrim(x, y, width, height);
}
@@ -248,22 +276,22 @@
notifyListeners(DWT.Expand, event);
}
}
-public Color getBackground () {
+public override Color getBackground () {
// This method must be overridden otherwise, in a TableTree in which the first
// item has no sub items, a grey (Widget background colour) square will appear in
// the first column of the first item.
// It is not possible in the constructor to set the background of the TableTree
- // to be the same as the background of the Table because this interferes with
+ // to be the same as the background of the Table because this interferes with
// the TableTree adapting to changes in the System color settings.
return table.getBackground();
}
-public Rectangle getClientArea () {
+public override Rectangle getClientArea () {
return table.getClientArea();
}
-public Color getForeground () {
+public override Color getForeground () {
return table.getForeground();
}
-public Font getFont () {
+public override Font getFont () {
return table.getFont();
}
/**
@@ -347,7 +375,7 @@
return table.getSelectionCount();
}
-public int getStyle () {
+public override int getStyle () {
checkWidget();
return table.getStyle();
}
@@ -363,23 +391,23 @@
}
void createImages () {
-
+
int itemHeight = sizeImage.getBounds().height;
- // Calculate border around image.
+ // Calculate border around image.
// At least 9 pixels are needed to draw the image
// Leave at least a 6 pixel border.
int indent = Math.min(6, (itemHeight - 9) / 2);
indent = Math.max(0, indent);
- int size = Math.max (10, itemHeight - 2 * indent);
+ int size = Math.max (10, itemHeight - 2 * indent);
size = ((size + 1) / 2) * 2; // size must be an even number
int midpoint = indent + size / 2;
-
+
Color foreground = getForeground();
Color plusMinus = getDisplay().getSystemColor(DWT.COLOR_WIDGET_NORMAL_SHADOW);
Color background = getBackground();
-
+
/* Plus image */
- PaletteData palette = new PaletteData(new RGB[]{foreground.getRGB(), background.getRGB(), plusMinus.getRGB()});
+ PaletteData palette = new PaletteData( [ foreground.getRGB(), background.getRGB(), plusMinus.getRGB()]);
ImageData imageData = new ImageData(itemHeight, itemHeight, 4, palette);
imageData.transparentPixel = 1;
plusImage = new Image(getDisplay(), imageData);
@@ -392,9 +420,9 @@
gc.drawLine(midpoint, indent + 2, midpoint, indent + size - 2);
gc.drawLine(indent + 2, midpoint, indent + size - 2, midpoint);
gc.dispose();
-
+
/* Minus image */
- palette = new PaletteData(new RGB[]{foreground.getRGB(), background.getRGB(), plusMinus.getRGB()});
+ palette = new PaletteData([foreground.getRGB(), background.getRGB(), plusMinus.getRGB()]);
imageData = new ImageData(itemHeight, itemHeight, 4, palette);
imageData.transparentPixel = 1;
minusImage = new Image(getDisplay(), imageData);
@@ -420,7 +448,7 @@
/**
* Gets the index of an item.
- *
+ *
*
Here is an example of using a TableTreeEditor: @@ -41,7 +56,7 @@ * } * 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. @@ -50,23 +65,23 @@ * 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 !is null) oldEditor.dispose(); -* +* * // Identify the selected row -* TableTreeItem item = cast(TableTreeItem)e.item; +* TableTreeItem item = (TableTreeItem)e.item; * if (item is null) return; -* +* * // The control that will be the editor must be a child of the Table * Text newEditor = new Text(table, DWT.NONE); * newEditor.setText(item.getText(EDITABLECOLUMN)); * newEditor.addModifyListener(new ModifyListener() { * public void modifyText(ModifyEvent e) { -* Text text = cast(Text)editor.getEditor(); +* Text text = (Text)editor.getEditor(); * editor.getItem().setText(EDITABLECOLUMN, text.getText()); * } * }); @@ -76,11 +91,13 @@ * } * }); * -* +* * @deprecated As of 3.1 use TreeEditor with Tree, TreeItem and TreeColumn */ public class TableTreeEditor : ControlEditor { + alias ControlEditor.setEditor setEditor; + TableTree tableTree; TableTreeItem item; int column = -1; @@ -96,15 +113,18 @@ super(tableTree.getTable()); this.tableTree = tableTree; - treeListener = new TreeListener () { - final Runnable runnable = new Runnable() { - public void run() { - if (editor is null || editor.isDisposed()) return; - if (TableTreeEditor.this.tableTree.isDisposed()) return; - layout(); - editor.setVisible(true); - } - }; + treeListener = new class() TreeListener { + Runnable runnable; + this() { + runnable = new class() Runnable { + public void run() { + if (editor is null || editor.isDisposed()) return; + if (this.outer.outer.tableTree.isDisposed()) return; + layout(); + editor.setVisible(true); + } + }; + } public void treeCollapsed(TreeEvent e) { if (editor is null || editor.isDisposed ()) return; editor.setVisible(false); @@ -117,8 +137,8 @@ } }; tableTree.addTreeListener(treeListener); - - columnListener = new ControlListener() { + + columnListener = new class() ControlListener { public void controlMoved(ControlEvent e){ layout (); } @@ -126,11 +146,12 @@ layout (); } }; - + // To be consistent with older versions of DWT, grabVertical defaults to true grabVertical = true; } -Rectangle computeBounds () { + +override Rectangle computeBounds () { if (item is null || column is -1 || item.isDisposed() || item.tableItem is null) return new Rectangle(0, 0, 0, 0); Rectangle cell = item.getBounds(column); Rectangle area = tableTree.getClientArea(); @@ -144,11 +165,11 @@ if (grabHorizontal) { editorRect.width = Math.max(cell.width, minimumWidth); } - + if (grabVertical) { editorRect.height = Math.max(cell.height, minimumHeight); } - + if (horizontalAlignment is DWT.RIGHT) { editorRect.x += cell.width - editorRect.width; } else if (horizontalAlignment is DWT.LEFT) { @@ -156,7 +177,7 @@ } else { // default is CENTER editorRect.x += (cell.width - editorRect.width)/2; } - + if (verticalAlignment is DWT.BOTTOM) { editorRect.y += cell.height - editorRect.height; } else if (verticalAlignment is DWT.TOP) { @@ -170,7 +191,7 @@ * 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 () { +public override void dispose () { if (tableTree !is null && !tableTree.isDisposed()) { Table table = tableTree.getTable(); if (table !is null && !table.isDisposed()) { @@ -220,14 +241,14 @@ this.column = -1; } - if (column < 0 || column >= table.getColumnCount()) return; - + 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) { +public void setItem (TableTreeItem item) { this.item = item; layout(); } @@ -237,17 +258,18 @@ * *
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
*/
+alias ControlEditor.setEditor setEditor;
public void setEditor (Control editor, TableTreeItem item, int column) {
setItem(item);
setColumn(column);
setEditor(editor);
}
-public void layout () {
+public override void layout () {
if (tableTree is null || tableTree.isDisposed()) return;
if (item is null || item.isDisposed()) return;
Table table = tableTree.getTable();
@@ -256,4 +278,5 @@
if (columnCount > 0 && (column < 0 || column >= columnCount)) return;
super.layout();
}
+
}
diff -r fbe68c33eeee -r 6337764516f1 dwt/custom/TableTreeItem.d
--- a/dwt/custom/TableTreeItem.d Tue Oct 07 14:41:31 2008 +0200
+++ b/dwt/custom/TableTreeItem.d Tue Oct 07 16:29:55 2008 +0200
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2007 IBM Corporation and others.
+ * 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
@@ -7,28 +7,43 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ * Frank Benoit
* The style value is either one of the style constants defined in
* class
* The style value is either one of the style constants defined in
* class
* The style value is either one of the style constants defined in
* class
* The style value is either one of the style constants defined in
* class DWT
which is applicable to instances of this
- * class, or must be built by bitwise OR'ing together
+ * class, or must be built by bitwise OR'ing together
* (that is, using the int
"|" operator) two or more
* of those DWT
style constants. The class description
* lists the style constants that are applicable to the class.
@@ -76,7 +91,7 @@
* DWT
which is applicable to instances of this
- * class, or must be built by bitwise OR'ing together
+ * class, or must be built by bitwise OR'ing together
* (that is, using the int
"|" operator) two or more
* of those DWT
style constants. The class description
* lists the style constants that are applicable to the class.
@@ -109,7 +124,7 @@
* DWT
which is applicable to instances of this
- * class, or must be built by bitwise OR'ing together
+ * class, or must be built by bitwise OR'ing together
* (that is, using the int
"|" operator) two or more
* of those DWT
style constants. The class description
* lists the style constants that are applicable to the class.
@@ -141,7 +156,7 @@
* DWT
which is applicable to instances of this
- * class, or must be built by bitwise OR'ing together
+ * class, or must be built by bitwise OR'ing together
* (that is, using the int
"|" operator) two or more
* of those DWT
style constants. The class description
* lists the style constants that are applicable to the class.
@@ -167,11 +182,16 @@
}
this(TableTree parent, TableTreeItem parentItem, int style, int index) {
+
+ items = TableTree.EMPTY_ITEMS;
+ texts = TableTree.EMPTY_TEXTS;
+ images = TableTree.EMPTY_IMAGES;
+
super(parent, style);
this.parent = parent;
this.parentItem = parentItem;
if (parentItem is null) {
-
+
/* Root items are visible immediately */
int tableIndex = parent.addItem(this, index);
tableItem = new TableItem(parent.getTable(), style, tableIndex);
@@ -206,7 +226,7 @@
void addItem(TableTreeItem item, int index) {
if (item is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
if (index < 0 || index > items.length) DWT.error(DWT.ERROR_INVALID_ARGUMENT);
-
+
/* Now that item has a sub-node it must indicate that it can be expanded */
if (items.length is 0 && index is 0) {
if (tableItem !is null) {
@@ -214,7 +234,7 @@
tableItem.setImage(0, image);
}
}
-
+
/* Put the item in the items list */
TableTreeItem[] newItems = new TableTreeItem[items.length + 1];
System.arraycopy(items, 0, newItems, 0, index);
@@ -228,14 +248,14 @@
* Returns the receiver's background color.
*
* @return the background color
- *
+ *
* @exception DWTException
*
- *
+ *
* @since 2.0
- *
+ *
*/
public Color getBackground () {
checkWidget ();
@@ -290,7 +310,7 @@
*
* 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. + * not affect the receiver. *
* * @return the receiver's items @@ -468,7 +488,7 @@ //checkWidget(); return parentItem; } -public String getText () { +public override String getText () { checkWidget(); return getText(0); } @@ -497,7 +517,7 @@ /** * 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 @@ -508,7 +528,7 @@ * */ public int indexOf (TableTreeItem item) { - //checkWidget(); + //checkWidget(); for (int i = 0; i < items.length; i++) { if (items[i] is item) return i; } @@ -529,7 +549,7 @@ items[i].expandAll(notify); } } -int expandedIndexOf (TableTreeItem item) { +int expandedIndexOf (TableTreeItem item) { int index = 0; for (int i = 0; i < items.length; i++) { if (items[i] is item) return index; @@ -549,7 +569,7 @@ return count; } -public void dispose () { +public override void dispose () { if (isDisposed()) return; for (int i = items.length - 1; i >= 0; i--) { items[i].dispose(); @@ -593,17 +613,17 @@ * if the argument is null. * * @param color the new color (or null) - * + * * @exception IllegalArgumentException
*
- * @param source the object that will be sending the TextChangedEvent,
- * cannot be null
+ * @param source the object that will be sending the TextChangedEvent,
+ * cannot be null
*/
public this(StyledTextContent source) {
- super(source);
+ super(cast(Object)source);
}
}
diff -r fbe68c33eeee -r 6337764516f1 dwt/custom/TextChangingEvent.d
--- a/dwt/custom/TextChangingEvent.d Tue Oct 07 14:41:31 2008 +0200
+++ b/dwt/custom/TextChangingEvent.d Tue Oct 07 16:29:55 2008 +0200
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * 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
@@ -7,15 +7,23 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ * Frank Benoit
*
- * @param source the object that will be sending the new TextChangingEvent,
- * cannot be null
+ * @param source the object that will be sending the new TextChangingEvent,
+ * cannot be null
*/
public this(StyledTextContent source) {
- super(source);
+ super( cast(Object)source);
}
this(StyledTextContent source, StyledTextEvent e) {
- super(source);
+ super( cast(Object)source);
start = e.start;
replaceCharCount = e.replaceCharCount;
newCharCount = e.newCharCount;
diff -r fbe68c33eeee -r 6337764516f1 dwt/custom/TreeEditor.d
--- a/dwt/custom/TreeEditor.d Tue Oct 07 14:41:31 2008 +0200
+++ b/dwt/custom/TreeEditor.d Tue Oct 07 16:29:55 2008 +0200
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2007 IBM Corporation and others.
+ * 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
@@ -7,14 +7,27 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ * Frank Benoit 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
@@ -281,7 +306,7 @@
setColumn(column);
setEditor(editor);
}
-public void setEditor (Control editor) {
+public override void setEditor (Control editor) {
super.setEditor(editor);
resize();
}
@@ -291,7 +316,7 @@
*
* 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
*/
@@ -300,12 +325,13 @@
setEditor(editor);
}
-public void layout () {
+public override void layout () {
if (tree is null || tree.isDisposed()) return;
- if (item is null || item.isDisposed()) return;
+ if (item is null || item.isDisposed()) return;
int columnCount = tree.getColumnCount();
if (columnCount is 0 && column !is 0) return;
if (columnCount > 0 && (column < 0 || column >= columnCount)) return;
super.layout();
}
+
}
diff -r fbe68c33eeee -r 6337764516f1 dwt/custom/VerifyKeyListener.d
--- a/dwt/custom/VerifyKeyListener.d Tue Oct 07 14:41:31 2008 +0200
+++ b/dwt/custom/VerifyKeyListener.d Tue Oct 07 16:29:55 2008 +0200
@@ -1,5 +1,5 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 IBM Corporation and others.
+/*******************************************************************************
+ * 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
@@ -7,12 +7,23 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ * Frank Benoit
@@ -28,11 +43,13 @@
*
* IMPORTANT: This class is not intended to be subclassed.
*
* The style value is either one of the style constants defined in
* class TreeItem
that is to be edited.
+*
+* @param item the item to be edited
+*/
public void setItem (TreeItem item) {
this.item = item;
resize();
@@ -269,7 +294,7 @@
*
*
diff -r fbe68c33eeee -r 6337764516f1 dwt/custom/ViewForm.d
--- a/dwt/custom/ViewForm.d Tue Oct 07 14:41:31 2008 +0200
+++ b/dwt/custom/ViewForm.d Tue Oct 07 16:29:55 2008 +0200
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2007 IBM Corporation and others.
+ * 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
@@ -7,17 +7,32 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ * Frank Benoit
DWT
which is applicable to instances of this
- * class, or must be built by bitwise OR'ing together
+ * class, or must be built by bitwise OR'ing together
* (that is, using the int
"|" operator) two or more
* of those DWT
style constants. The class description
* lists the style constants that are applicable to the class.
@@ -144,25 +168,26 @@
* @see DWT#BORDER
* @see DWT#FLAT
* @see #getStyle()
- */
+ */
public this(Composite parent, int style) {
super(parent, checkStyle(style));
super.setLayout(new ViewFormLayout());
-
+
setBorderVisible((style & DWT.BORDER) !is 0);
-
- Listener listener = new Listener() {
+
+ Listener listener = new class() Listener {
public void handleEvent(Event e) {
switch (e.type) {
case DWT.Dispose: onDispose(); break;
case DWT.Paint: onPaint(e.gc); break;
case DWT.Resize: onResize(); break;
+ default:
}
}
};
-
- int[] events = new int[] {DWT.Dispose, DWT.Paint, DWT.Resize};
-
+
+ int[] events = [DWT.Dispose, DWT.Paint, DWT.Resize];
+
for (int i = 0; i < events.length; i++) {
addListener(events[i], listener);
}
@@ -176,12 +201,12 @@
//protected void checkSubclass () {
// String name = getClass().getName ();
// String validName = ViewForm.class.getName();
-// if (!validName.opEquals(name)) {
+// if (!validName.equals(name)) {
// DWT.error (DWT.ERROR_INVALID_SUBCLASS);
// }
//}
-public Rectangle computeTrim (int x, int y, int width, int height) {
+public override Rectangle computeTrim (int x, int y, int width, int height) {
checkWidget ();
int trimX = x - borderLeft - highlight;
int trimY = y - borderTop - highlight;
@@ -189,7 +214,7 @@
int trimHeight = height + borderTop + borderBottom + 2*highlight;
return new Rectangle(trimX, trimY, trimWidth, trimHeight);
}
-public Rectangle getClientArea() {
+public override Rectangle getClientArea() {
checkWidget();
Rectangle clientArea = super.getClientArea();
clientArea.x += borderLeft;
@@ -200,7 +225,7 @@
}
/**
* Returns the content area.
-*
+*
* @return the control in the content area of the pane or null
*/
public Control getContent() {
@@ -210,7 +235,7 @@
/**
* 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() {
@@ -220,7 +245,7 @@
/**
* 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() {
@@ -230,7 +255,7 @@
/**
* 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() {
@@ -257,9 +282,9 @@
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};
+ int[] shape = [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(DWT.COLOR_LIST_SELECTION);
gc.setBackground(highlightColor);
gc.fillPolygon(shape);
@@ -280,16 +305,16 @@
if (oldSize.x < size.x) {
width = size.x - oldSize.x + borderRight + highlight;
} else if (oldSize.x > size.x) {
- width = borderRight + highlight;
+ 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;
+ height = size.y - oldSize.y + borderBottom + highlight;
}
if (oldSize.y > size.y) {
- height = borderBottom + highlight;
+ height = borderBottom + highlight;
}
redraw(0, size.y - height, size.x, height, false);
}
@@ -297,11 +322,11 @@
}
/**
* Sets the content.
-* Setting the content to null will remove it from
+* 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 DWTException
*
*/
-public void setLayout (Layout layout) {
+public override void setLayout (Layout layout) {
checkWidget();
return;
}
@@ -348,11 +373,11 @@
/**
* 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 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 DWTException
*
*
*
*
*