diff options
author | Felipe Heidrich <fheidric> | 2005-10-24 18:06:01 +0000 |
---|---|---|
committer | Felipe Heidrich <fheidric> | 2005-10-24 18:06:01 +0000 |
commit | 0d43d09e9488d7eb2fa7bed929606aa894ae06d3 (patch) | |
tree | 4dc9da4f66ce74c4e490be407e7be22f57e4473c | |
parent | 365d9e3002ce9e8ba155a42ea16cecffc7fe94e0 (diff) | |
download | eclipse.platform.swt-0d43d09e9488d7eb2fa7bed929606aa894ae06d3.tar.gz eclipse.platform.swt-0d43d09e9488d7eb2fa7bed929606aa894ae06d3.tar.xz eclipse.platform.swt-0d43d09e9488d7eb2fa7bed929606aa894ae06d3.zip |
bullet support
5 files changed, 119 insertions, 28 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/DefaultLineStyler.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/DefaultLineStyler.java index e7f276dce3..d2ef5f0497 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/DefaultLineStyler.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/DefaultLineStyler.java @@ -26,6 +26,7 @@ class DefaultLineStyler implements LineStyleListener, LineBackgroundListener { final static int ALIGNMENT = 1 << 1; final static int INDENT = 1 << 2; final static int JUSTIFY = 1 << 3; + final static int BULLET = 1 << 4; class LineInfo { int flags; @@ -33,7 +34,7 @@ class DefaultLineStyler implements LineStyleListener, LineBackgroundListener { int alignment; int indent; boolean justify; - EmbeddedObject object; + EmbeddedObject.Bullet bullet; } /** @@ -289,6 +290,7 @@ public void lineGetStyle(LineStyleEvent event) { if ((info.flags & ALIGNMENT) != 0) event.alignment = info.alignment; if ((info.flags & INDENT) != 0) event.indent = info.indent; if ((info.flags & JUSTIFY) != 0) event.justify = info.justify; + if ((info.flags & BULLET) != 0) event.bullet = info.bullet; } } /** @@ -351,6 +353,15 @@ void setLineJustify(int startLine, int count, boolean justify) { lines[i].justify = justify; } } +void setLineBullet(int startLine, int count, EmbeddedObject.Bullet bullet) { + for (int i = startLine; i < startLine + count; i++) { + if (lines[i] == null) { + lines[i] = new LineInfo(); + } + lines[i].flags |= BULLET; + lines[i].bullet = bullet; + } +} /** * Update the styles to reflect the new style. <code>newStyle</code> will * replace any old style for the range. When this method is called, the @@ -682,6 +693,13 @@ boolean getLineJustify(int index, boolean defaultJustify) { } return defaultJustify; } +EmbeddedObject.Bullet getLineBullet(int index, EmbeddedObject.Bullet defaultBullet) { + LineInfo info = lines[index]; + if (info != null && (info.flags & BULLET) != 0) { + return info.bullet; + } + return defaultBullet; +} /** * Returns the style for the character at <code>offset</code>. Called by StyledText. * Returns a new style. Does not return the existing style. 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 index 8fb4687b1c..2a47a811af 100644 --- 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 @@ -34,7 +34,7 @@ public abstract class EmbeddedObject { * Helper class to embedded a Control in a StyledText * */ - public class EmbeddedControl extends EmbeddedObject { + public static class EmbeddedControl extends EmbeddedObject { Control control; int alignment; @@ -83,7 +83,7 @@ public abstract class EmbeddedObject { * Helper class to embedded a Image in a StyledText * */ - public class EmbeddedImage extends EmbeddedObject { + public static class EmbeddedImage extends EmbeddedObject { Image image; int alignment; @@ -133,7 +133,7 @@ public abstract class EmbeddedObject { * * */ - public class Bullet extends EmbeddedObject { + public static class Bullet extends EmbeddedObject { /** * @param style bullet image, check mark image, number, roman, @@ -142,15 +142,20 @@ public abstract class EmbeddedObject { } public int getAscent() { - return 0; + return 8; } public int getDescent() { return 0; } public int getAdvance() { - return 0; + return 50; } public void draw(GC gc, int x, int y, int ascent, int descent) { + gc.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK)); + int height = Math.max(6, Math.min(10, ascent / 2)); + gc.setAntialias(SWT.ON); + gc.fillOval(x + 50 - height - 4, y + ascent - height, height, height); + gc.setAdvanced(false); } } } 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 6f78d0a5e9..1229a44ffa 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 @@ -171,6 +171,9 @@ public boolean isUnstyled() { return true; } +boolean isVariableLineHeight() { + return font != null || object != null || rise != 0; +} /** * 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 diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText2.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText2.java index 9a6fa8b516..1d3ecd8e0c 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText2.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText2.java @@ -1642,7 +1642,7 @@ public void addLineStyleListener(LineStyleListener listener) { if (isFixedLineHeight()) { lineCache.setAllLinesDefaultHeight(); } - setLineHeightVariable(); + setVariableLineHeight(); StyledTextListener typedListener = new StyledTextListener(listener); addListener(LineGetStyle, typedListener); } @@ -3498,6 +3498,29 @@ public Color getLineBackground(int index) { return userLineBackground ? null : defaultLineStyler.getLineBackground(index, null); } /** + * Returns the bullet of the line at the given index. + * <p> + * + * @param index the index of the line + * @return the line bullet + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * @exception IllegalArgumentException <ul> + * <li>ERROR_INVALID_ARGUMENT when the index is invalid</li> + * </ul> + * @since 3.2 + */ +public EmbeddedObject.Bullet getLineBullet(int index) { + checkWidget(); + if (index < 0 || index > content.getLineCount()) { + SWT.error(SWT.ERROR_INVALID_ARGUMENT); + } + return defaultLineStyler.getLineBullet(index, null); +} +/** * Returns the line background data for the given line or null if * there is none. * <p> @@ -6097,11 +6120,11 @@ public void replaceStyleRanges(int start, int length, StyleRange[] ranges) { defaultLineStyler.replaceStyleRanges(start, length, ranges); for (int i = 0; i < ranges.length; i++) { StyleRange range = ranges[i]; - if (range != null && (range.font != null || range.rise != 0)) { + if (range.isVariableLineHeight()) { if (!isFixedLineHeight()) { lineCache.setAllLinesDefaultHeight(); } - setLineHeightVariable(); + setVariableLineHeight(); break; } } @@ -6426,7 +6449,7 @@ public void setWordWrap(boolean wrap) { if ((getStyle() & SWT.SINGLE) != 0) return; if (wordWrap == wrap) return; wordWrap = wrap; - setLineHeightVariable(); + setVariableLineHeight(); resetCache(0, content.getLineCount()); horizontalScrollOffset = 0; ScrollBar horizontalBar = getHorizontalBar(); @@ -6907,7 +6930,38 @@ public void setLineBackground(int startLine, int lineCount, Color background) { defaultLineStyler.setLineBackground(startLine, lineCount, background); redrawLines(startLine, lineCount); } -void setLineHeightVariable () { +/** + * Sets the bullet of the specified lines. + * <p> + * + * @param startLine first line the bullet is applied to, 0 based + * @param lineCount number of lines the bullet applies to. + * @param indent line indent + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * @exception IllegalArgumentException <ul> + * <li>ERROR_INVALID_ARGUMENT when the specified line range is invalid</li> + * </ul> + * @since 3.2 + */ +public void setLineBullet(int startLine, int lineCount, EmbeddedObject.Bullet bullet) { + checkWidget(); + if (userLineStyle) return; + if (startLine < 0 || startLine + lineCount > content.getLineCount()) { + SWT.error(SWT.ERROR_INVALID_ARGUMENT); + } + + defaultLineStyler.setLineBullet(startLine, lineCount, bullet); + redrawLines(startLine, lineCount); + int caretLine = getCaretLine(); + if (startLine <= caretLine && caretLine < startLine + lineCount) { + setCaretLocation(); + } +} +void setVariableLineHeight () { fixedLineHeight = false; } /** @@ -6989,7 +7043,7 @@ public void setLineSpacing(int lineSpacing) { checkWidget(); if (this.lineSpacing == lineSpacing || lineSpacing < 0) return; this.lineSpacing = lineSpacing; - setLineHeightVariable(); + setVariableLineHeight(); resetCache(0, content.getLineCount()); setCaretLocation(); super.redraw(); @@ -7337,11 +7391,11 @@ public void setStyleRange(StyleRange range) { } defaultLineStyler.setStyleRange(range); if (range != null) { - if (range.font != null || range.rise != 0) { + if (range.isVariableLineHeight()) { if (!isFixedLineHeight()) { lineCache.setAllLinesDefaultHeight(); } - setLineHeightVariable(); + setVariableLineHeight(); } int firstLine = content.getLineAtOffset(range.start); int lastLine = content.getLineAtOffset(range.start + range.length); @@ -7409,11 +7463,11 @@ public void setStyleRanges(StyleRange[] ranges) { for (int i = 0; i < ranges.length; i++) { StyleRange range = ranges[i]; - if (range != null && (range.font != null || range.rise != 0)) { + if (range.isVariableLineHeight()) { if (!isFixedLineHeight()) { lineCache.setAllLinesDefaultHeight(); } - setLineHeightVariable(); + setVariableLineHeight(); break; } } 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 d89b289b71..44c44ef5bb 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 @@ -211,19 +211,27 @@ int drawLine(String line, int lineIndex, int paintX, int paintY, GC gc, Color wi //place the objects event = styledText.sendLineEvent(StyledText2.LineGetStyle, lineOffset, line); - if (event != null && event.styles != null) { + if (event != null) { + EmbeddedObject bullet = event.bullet; + if (bullet != null) { + FontMetrics metrics = layout.getLineMetrics(0); + bullet.draw(gc, paintX, paintY, metrics.getAscent(), metrics.getDescent()); + } + 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()); - } + if (styles != null) { + 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()); + } + } } } } @@ -353,6 +361,9 @@ TextLayout getTextLayout(String line, int lineOffset) { alignment = event.alignment & (SWT.CENTER | SWT.LEFT | SWT.RIGHT); indent = event.indent; justify = event.justify; + if (event.bullet != null) { + indent += event.bullet.getAdvance(); + } } TextLayout layout = getTextLayout(line, lineOffset, segments, styles); layout.setAlignment(alignment); |