diff options
author | Felipe Heidrich <fheidric> | 2005-10-18 21:53:06 +0000 |
---|---|---|
committer | Felipe Heidrich <fheidric> | 2005-10-18 21:53:06 +0000 |
commit | 630a3feebb5502f50c8ae9bf88292efd98dc911c (patch) | |
tree | 4537f440d2669d5a7b6f90012639079222be8726 /bundles | |
parent | 166233a02615ac1e2681ccfd00cba112f3ec895b (diff) | |
download | eclipse.platform.swt-630a3feebb5502f50c8ae9bf88292efd98dc911c.tar.gz eclipse.platform.swt-630a3feebb5502f50c8ae9bf88292efd98dc911c.tar.xz eclipse.platform.swt-630a3feebb5502f50c8ae9bf88292efd98dc911c.zip |
*** empty log message ***
Diffstat (limited to 'bundles')
8 files changed, 276 insertions, 56 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/BidiSegmentEvent.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/BidiSegmentEvent.java index a2ebca761c..8e0aa94f6a 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/BidiSegmentEvent.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/BidiSegmentEvent.java @@ -58,11 +58,20 @@ import org.eclipse.swt.events.*; * </pre> */ public class BidiSegmentEvent extends 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; diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/EmbeddedObject.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/EmbeddedObject.java new file mode 100644 index 0000000000..28fa54574c --- /dev/null +++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/EmbeddedObject.java @@ -0,0 +1,131 @@ + +/* UNDER CONSTRUCTION - DO NOT USE THIS CLASS */ + +/******************************************************************************* + * Copyright (c) 2000, 2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.swt.custom; + +import org.eclipse.swt.*; +import org.eclipse.swt.graphics.*; +import org.eclipse.swt.widgets.*; + +/** + * The Interface that needs to be implemented by object to be embedded in + * a StyledText. + * <p> + * + * @see StyledText + */ +public interface EmbeddedObject { + public int getAscent(); + public int getDescent(); + public int getAdvance(); + public void draw(GC gc, int x, int y, int ascent, int descent); + + /** + * Helper class to embedded a Control in a StyledText + * + */ + public class EmbeddedControl implements EmbeddedObject { + Control control; + int alignment; + + /** + * + * + * @param control the control + * @param alignment the vertical alignment for the control + * SWT.TOP == top of the line + * SWT.CENTER == baseline + * SWT.BOTTOM == bottom of the line + */ + public EmbeddedControl(Control control, int alignment) { + if (control == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + if (control.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); + this.control = control; + this.alignment = alignment & (SWT.TOP | SWT.CENTER | SWT.BOTTOM); + if (this.alignment == 0) this.alignment = SWT.CENTER; + } + + public int getAscent() { + return control.getSize().y; + } + public int getDescent() { + return 0; + } + public int getAdvance() { + return control.getSize().x; + } + public void draw(GC gc, int x, int y, int ascent, int descent) { + switch (alignment) { + case SWT.TOP: + control.setLocation(x, y); + break; + case SWT.CENTER: + control.setLocation(x, y + ascent - getAscent()); + break; + case SWT.BOTTOM: + control.setLocation(x, y + ascent + descent - getAscent()); + break; + } + } + } + + /** + * Helper class to embedded a Image in a StyledText + * + */ + public class EmbeddedImage implements EmbeddedObject { + Image image; + int alignment; + + /** + * + * + * @param control the control + * @param alignment the vertical alignment for the control + * SWT.TOP == top of the line + * SWT.CENTER == baseline + * SWT.BOTTOM == bottom of the line + */ + public EmbeddedImage(Image image, int alignment) { + if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + if (image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); + this.image = image; + this.alignment = alignment & (SWT.TOP | SWT.CENTER | SWT.BOTTOM); + if (this.alignment == 0) this.alignment = SWT.CENTER; + } + + public int getAscent() { + return image.getBounds().height; + } + public int getDescent() { + return 0; + } + public int getAdvance() { + return image.getBounds().width; + } + public void draw(GC gc, int x, int y, int ascent, int descent) { + switch (alignment) { + case SWT.TOP: + gc.drawImage(image, x, y); + break; + case SWT.CENTER: + gc.drawImage(image, x, y + ascent - getAscent()); + break; + case SWT.BOTTOM: + gc.drawImage(image, x, y + ascent + descent - getAscent()); + break; + } + } + } +} + diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/LineBackgroundEvent.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/LineBackgroundEvent.java index aa1737c49e..c093a7d200 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/LineBackgroundEvent.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/LineBackgroundEvent.java @@ -17,9 +17,21 @@ import org.eclipse.swt.graphics.*; * This event is sent when a line is about to be drawn. */ public class LineBackgroundEvent extends TypedEvent { - public int lineOffset; // line start offset - public String lineText; // line text - public Color lineBackground; // line background color + + /** + * line start offset + */ + public int lineOffset; + + /** + * line text + */ + public String lineText; + + /** + * line background color + */ + public Color lineBackground; static final long serialVersionUID = 3978711687853324342L; diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/LineStyleEvent.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/LineStyleEvent.java index f11c24c683..289f742d65 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/LineStyleEvent.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/LineStyleEvent.java @@ -16,10 +16,40 @@ import org.eclipse.swt.events.*; * This event is sent when a line is about to be drawn. */ public class LineStyleEvent extends TypedEvent { - public int lineOffset; // line start offset - public String lineText; // line text - public StyleRange[] styles; // array of StyleRanges + + /** + * line start offset + */ + public int lineOffset; + + /** + * line text + */ + public String lineText; + + /** + * line styles + */ + public StyleRange[] styles; + /* API UNDER CONSTRUCTION - DO NOT USE THIS FIELD + * + * line alignment (output) + */ + public int alignment; + + /* API UNDER CONSTRUCTION - DO NOT USE THIS FIELD + * + * line indent (output) + */ + public int indent; + + /* API UNDER CONSTRUCTION - DO NOT USE THIS FIELD + * + * line justification (output) + */ + public boolean justify; + static final long serialVersionUID = 3906081274027192884L; public LineStyleEvent(StyledTextEvent e) { diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyleRange.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyleRange.java index 5e704fdedb..6f78d0a5e9 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyleRange.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyleRange.java @@ -60,6 +60,22 @@ public class StyleRange implements CloneableCompatibility { */ public Font font; + /* + * API UNDER CONSTRUCTION - DO NOT USE THIS FIELD + * + * baseline rise + * + */ + public int rise; + + /* + * API UNDER CONSTRUCTION - DO NOT USE THIS FIELD + * + * embedded object + * + */ + public EmbeddedObject object; + public StyleRange() { } @@ -147,9 +163,11 @@ public boolean isUnstyled() { if (foreground != null) return false; if (background != null) return false; if (font != null) return false; + if (object != null) return false; if (fontStyle != SWT.NORMAL) return false; if (underline) return false; if (strikeout) return false; + if (rise != 0) return false; return true; } @@ -178,9 +196,15 @@ public boolean similarTo(StyleRange style) { } else if (style.font != null) { return false; } + if (object != null) { + if (!object.equals(style.object)) return false; + } else if (style.object != null) { + return false; + } if (fontStyle != style.fontStyle) return false; if (underline != style.underline) return false; if (strikeout != style.strikeout) return false; + if (rise != style.rise) return false; return true; } @@ -193,8 +217,10 @@ public boolean similarTo(StyleRange style) { public Object clone() { StyleRange style = new StyleRange(start, length, foreground, background, fontStyle); style.font = font; + style.object = object; style.underline = underline; style.strikeout = strikeout; + style.rise = rise; return style; } diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextEvent.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextEvent.java index 418ab93a5d..e44bd92253 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextEvent.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextEvent.java @@ -19,6 +19,9 @@ import org.eclipse.swt.widgets.*; class StyledTextEvent extends Event { // used by LineStyleEvent StyleRange[] styles; + int alignment; + int indent; + boolean justify; // used by LineBackgroundEvent Color lineBackground; // used by BidiSegmentEvent diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextListener.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextListener.java index 7774dbd699..310a32a516 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextListener.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextListener.java @@ -45,6 +45,9 @@ public void handleEvent(Event e) { LineStyleEvent lineStyleEvent = new LineStyleEvent((StyledTextEvent) e); ((LineStyleListener) eventListener).lineGetStyle(lineStyleEvent); ((StyledTextEvent) e).styles = lineStyleEvent.styles; + ((StyledTextEvent) e).alignment = lineStyleEvent.alignment; + ((StyledTextEvent) e).indent = lineStyleEvent.indent; + ((StyledTextEvent) e).justify = lineStyleEvent.justify; break; case StyledText.VerifyKey: VerifyEvent verifyEvent = new VerifyEvent(e); diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextRenderer2.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextRenderer2.java index d666c0ab4b..ae81772f11 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextRenderer2.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextRenderer2.java @@ -194,7 +194,7 @@ int drawLine(String line, int lineIndex, int paintX, int paintY, GC gc, Color wi } } } - y += lineBounds.height; + y += lineBounds.height + layout.getSpacing(); } } gc.setForeground(widgetForeground); @@ -204,10 +204,30 @@ int drawLine(String line, int lineIndex, int paintX, int paintY, GC gc, Color wi } else { int start = Math.max(0, selectionStart - lineOffset); int end = Math.min(lineLength, selectionEnd - lineOffset); - Color selectionFk = styledText.getSelectionForeground(); - Color selectionBk = styledText.getSelectionBackground(); - layout.draw(gc, paintX, paintY, start, end - 1, selectionFk, selectionBk); + Color selectionFg = styledText.getSelectionForeground(); + Color selectionBg = styledText.getSelectionBackground(); + layout.draw(gc, paintX, paintY, start, end - 1, selectionFg, selectionBg); } + + //place the objects + event = styledText.sendLineEvent(StyledText2.LineGetStyle, lineOffset, line); + if (event != null && event.styles != null) { + StyleRange[] styles = event.styles; + for (int i = 0; i < styles.length; i++) { + StyleRange range = styles[i]; + int start = range.start; + if (lineOffset <= start && start < lineOffset + lineLength) { + EmbeddedObject object = range.object; + if (object != null) { + int offset = start - lineOffset; + Point point = layout.getLocation(offset, false); + FontMetrics metrics = layout.getLineMetrics(layout.getLineIndex(offset)); + range.object.draw(gc, point.x + paintX, point.y + paintY, metrics.getAscent(), metrics.getDescent()); + } + } + } + } + int height = layout.getBounds().height; disposeTextLayout(layout); return height; @@ -223,7 +243,7 @@ void drawLine(int paintX, int paintY, GC gc, Color foreground, Color background, for (int i = 0; i < lineCount; i++) { Rectangle rect = layout.getLineBounds(i); rect.x += paintX; - rect.y += paintY; + rect.y += paintY + layout.getSpacing(); gc.fillRectangle(rect); } } @@ -240,28 +260,6 @@ int getLineEndSpace() { return lineEndSpaceWidth; } /** - * Returns the text segments that should be treated as if they - * had a different direction than the surrounding text. - * </p> - * - * @param lineOffset offset of the first character in the line. - * 0 based from the beginning of the document. - * @param line text of the line to specify bidi segments for - * @return text segments that should be treated as if they had a - * different direction than the surrounding text. Only the start - * index of a segment is specified, relative to the start of the - * line. Always starts with 0 and ends with the line length. - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the segment indices returned - * by the listener do not start with 0, are not in ascending order, - * exceed the line length or have duplicates</li> - * </ul> - */ -private int[] getBidiSegments(int lineOffset, String lineText) { - if (styledText == null || !styledText.isBidi()) return null; - return styledText.getBidiSegments(lineOffset, lineText); -} -/** * Returns the Font for a StyleRange */ Font getFont (StyleRange styleRange) { @@ -315,22 +313,6 @@ int getAverageCharWidth () { return averageCharWidth; } /** - * Returns the line style data for the given line or null if there is - * none. If there is a LineStyleListener but it does not set any styles, - * the StyledTextEvent.styles field will be initialized to an empty - * array. - * </p> - * - * @param lineOffset offset of the line start relative to the start of - * the content. - * @param line line to get line styles for - * @return line style data for the given line. Styles may start before - * line start and end after line end - */ -private StyledTextEvent getLineStyleData(int lineOffset, String line) { - return styledText != null ? styledText.getLineStyleData(lineOffset, line) : null; -} -/** * */ private int getOrientation () { @@ -359,10 +341,29 @@ int getWidth () { return styledText != null ? styledText.getWrapWidth() : -1; } TextLayout getTextLayout(String line, int lineOffset) { - int[] bidiSegments = getBidiSegments(lineOffset, line); - StyledTextEvent event = getLineStyleData(lineOffset, line); - StyleRange[] styles = event != null ? event.styles : null; - return getTextLayout(line, lineOffset, bidiSegments, styles); + StyleRange[] styles = null; + int indent = styledText.lineIndent; + int spacing = styledText.lineSpacing; + int alignment = styledText.alignment; + boolean justify = styledText.justify; + int[] segments = styledText.getBidiSegments(lineOffset, line); + StyledTextEvent event = styledText.getLineStyleData(lineOffset, line); + if (event != null) { + styles = event.styles; + if (event.alignment != -1) { + alignment = event.alignment & (SWT.CENTER | SWT.LEFT | SWT.RIGHT); + } + if (event.indent != -1) { + indent = event.indent; + } + justify |= event.justify; + } + TextLayout layout = getTextLayout(line, lineOffset, segments, styles); + layout.setAlignment(alignment); + layout.setJustify(justify); + layout.setIndent(indent); + layout.setSpacing(spacing); + return layout; } /** * Returns TextLayout given a line, a list of styles, and a list of bidi segments @@ -398,6 +399,11 @@ TextLayout getTextLayout(String line, int lineOffset, int[] bidiSegments, StyleR TextStyle textStyle = new TextStyle(getFont(style), style.foreground, style.background); textStyle.underline = style.underline; textStyle.strikeout = style.strikeout; + textStyle.rise = style.rise; + EmbeddedObject object = style.object; + if (object != null) { + textStyle.metrics = new GlyphMetrics(object.getAscent(), object.getDescent(), object.getAdvance()); + } layout.setStyle(textStyle, start, end - 1); lastOffset = Math.max(lastOffset, end); } |