diff options
author | Felipe Heidrich <fheidric> | 2005-10-21 21:55:30 +0000 |
---|---|---|
committer | Felipe Heidrich <fheidric> | 2005-10-21 21:55:30 +0000 |
commit | 1fd9631de19294ee7e312bac1eaea0ddeef51ecd (patch) | |
tree | 1851f974720265cde02a808f4d9faf68455d5f14 | |
parent | 02f95eacfdded39651c1ac1ac9f4a4858e930540 (diff) | |
download | eclipse.platform.swt-1fd9631de19294ee7e312bac1eaea0ddeef51ecd.tar.gz eclipse.platform.swt-1fd9631de19294ee7e312bac1eaea0ddeef51ecd.tar.xz eclipse.platform.swt-1fd9631de19294ee7e312bac1eaea0ddeef51ecd.zip |
*** empty log message ***
8 files changed, 478 insertions, 129 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 8287718739..e7f276dce3 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 @@ -20,7 +20,21 @@ class DefaultLineStyler implements LineStyleListener, LineBackgroundListener { int styleCount = 0; // the number of styles int lineExpandExp = 1; // the expansion exponent, used to increase the lines array exponentially int lineCount = 0; - Color lineBackgrounds[]; + LineInfo lines[]; + + final static int BACKGROUND = 1 << 0; + final static int ALIGNMENT = 1 << 1; + final static int INDENT = 1 << 2; + final static int JUSTIFY = 1 << 3; + + class LineInfo { + int flags; + Color background; + int alignment; + int indent; + boolean justify; + EmbeddedObject object; + } /** * Creates a new default line styler. @@ -31,7 +45,7 @@ class DefaultLineStyler implements LineStyleListener, LineBackgroundListener { public DefaultLineStyler(StyledTextContent content) { this.content = content; lineCount = content.getLineCount(); - lineBackgrounds = new Color[lineCount]; + lines = new LineInfo[lineCount]; } /** * Inserts a style at the given location. @@ -196,30 +210,6 @@ void clearStyle(StyleRange clearStyle) { } deleteStyles(deleteStyle, deleteCount); } -/** - * Increases the <code>linebackgrounds</code> array to accomodate new line background - * information. - * <p> - * - * @param numLines the number to increase the array by - */ -void expandLinesBy(int numLines) { - int size = lineBackgrounds.length; - if (size - lineCount >= numLines) return; - Color[] newLines = new Color[size + Math.max(Compatibility.pow2(lineExpandExp), numLines)]; - System.arraycopy(lineBackgrounds, 0, newLines, 0, size); - lineBackgrounds = newLines; - lineExpandExp++; -} -/** - * Deletes the style at <code>index</code>. - * <p> - * - * @param index the index of the style to be deleted - */ -void deleteStyle(int index) { - deleteStyles(index, 1); -} /** * Delete count styles starting at <code>index</code>. * <p> @@ -256,7 +246,9 @@ StyleRange [] getStyleRanges() { */ public void lineGetBackground(LineBackgroundEvent event) { int lineIndex = content.getLineAtOffset(event.lineOffset); - event.lineBackground = lineBackgrounds[lineIndex]; + if (lines[lineIndex] != null) { + event.lineBackground = lines[lineIndex].background; + } } /** * Handles the get line style information callback. @@ -291,6 +283,13 @@ public void lineGetStyle(LineStyleEvent event) { } event.styles = new StyleRange[lineStyles.size()]; lineStyles.copyInto(event.styles); + int lineIndex = content.getLineAtOffset(lineStart); + LineInfo info = lines[lineIndex]; + if (info != null) { + 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; + } } /** * Searches for the first style in the <code>start</code> - <code>end</code> range. @@ -316,17 +315,40 @@ int searchForStyle(int start, int end) { } return high; } -/** - * Updates the line background colors to reflect a new color. Called by StyledText. - * <p> - * - * @param startLine index of the first line to color - * @param count number of lines to color starting at startLine - * @param background the background color for the lines - */ +void setLineAlignment(int startLine, int count, int alignment) { + for (int i = startLine; i < startLine + count; i++) { + if (lines[i] == null) { + lines[i] = new LineInfo(); + } + lines[i].flags |= ALIGNMENT; + lines[i].alignment = alignment; + } +} void setLineBackground(int startLine, int count, Color background) { for (int i = startLine; i < startLine + count; i++) { - lineBackgrounds[i] = background; + if (lines[i] == null) { + lines[i] = new LineInfo(); + } + lines[i].flags |= BACKGROUND; + lines[i].background = background; + } +} +void setLineIndent(int startLine, int count, int indent) { + for (int i = startLine; i < startLine + count; i++) { + if (lines[i] == null) { + lines[i] = new LineInfo(); + } + lines[i].flags |= INDENT; + lines[i].indent = indent; + } +} +void setLineJustify(int startLine, int count, boolean justify) { + for (int i = startLine; i < startLine + count; i++) { + if (lines[i] == null) { + lines[i] = new LineInfo(); + } + lines[i].flags |= JUSTIFY; + lines[i].justify = justify; } } /** @@ -413,7 +435,7 @@ void setStyleRange(StyleRange newStyle) { styles[i] = newStyle; added = true; } else { - deleteStyle(i); + deleteStyles(i, 1); i--; } } else { @@ -506,20 +528,26 @@ public void textChanging(TextChangingEvent event) { */ void linesChanging(int start, int delta) { if (delta == 0) return; - boolean inserting = delta > 0; - if (inserting) { + if (delta > 0) { // shift the lines down to make room for new lines - expandLinesBy(delta); + int size = lines.length; + if (size - lineCount < delta) { + LineInfo[] newLines = new LineInfo[size + Math.max(Compatibility.pow2(lineExpandExp), delta)]; + System.arraycopy(lines, 0, newLines, 0, size); + lines = newLines; + lineExpandExp++; + } + for (int i = lineCount-1; i >= start; i--) { - lineBackgrounds[i + delta]=lineBackgrounds[i]; + lines[i + delta] = lines[i]; } for (int i = start; i < start + delta; i++) { - lineBackgrounds[i] = null; + lines[i] = null; } } else { // shift up the lines for (int i = start - delta; i < lineCount; i++) { - lineBackgrounds[i + delta] = lineBackgrounds[i]; + lines[i + delta] = lines[i]; } } lineCount += delta; @@ -626,16 +654,33 @@ Point getOverlappingStyles(int start, int length) { } return new Point(high, count); } -/** - * Returns the background color of a line. Called by StyledText. It is safe to return - * the existing Color object since the colors are set and managed by the client. - * <p> - * - * @param index the line index - * @return the background color of the line at the given index - */ -Color getLineBackground(int index) { - return lineBackgrounds[index]; +int getLineAlignment(int index, int defaultAlignment) { + LineInfo info = lines[index]; + if (info != null && (info.flags & ALIGNMENT) != 0) { + return info.alignment; + } + return defaultAlignment; +} +Color getLineBackground(int index, Color defaultBackground) { + LineInfo info = lines[index]; + if (info != null && (info.flags & BACKGROUND) != 0) { + return info.background; + } + return defaultBackground; +} +int getLineIndent(int index, int defaultIndent) { + LineInfo info = lines[index]; + if (info != null && (info.flags & INDENT) != 0) { + return info.indent; + } + return defaultIndent; +} +boolean getLineJustify(int index, boolean defaultJustify) { + LineInfo info = lines[index]; + if (info != null && (info.flags & JUSTIFY) != 0) { + return info.justify; + } + return defaultJustify; } /** * Returns the style for the character at <code>offset</code>. Called by StyledText. @@ -677,7 +722,9 @@ StyleRange[] getStyleRangesFor(int offset, int length) { } return ranges; } -void release () { +void dispose () { styles = null; + lines = null; + content = null; } } 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 28fa54574c..8fb4687b1c 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 @@ -24,17 +24,17 @@ import org.eclipse.swt.widgets.*; * * @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); +public abstract class EmbeddedObject { + public abstract int getAscent(); + public abstract int getDescent(); + public abstract int getAdvance(); + public abstract 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 { + public class EmbeddedControl extends EmbeddedObject { Control control; int alignment; @@ -83,7 +83,7 @@ public interface EmbeddedObject { * Helper class to embedded a Image in a StyledText * */ - public class EmbeddedImage implements EmbeddedObject { + public class EmbeddedImage extends EmbeddedObject { Image image; int alignment; @@ -127,5 +127,31 @@ public interface EmbeddedObject { } } } + + /** + * + * + * + */ + public class Bullet extends EmbeddedObject { + + /** + * @param style bullet image, check mark image, number, roman, + */ + public Bullet(int style, int level, int index) { + + } + public int getAscent() { + return 0; + } + public int getDescent() { + return 0; + } + public int getAdvance() { + return 0; + } + public void draw(GC gc, int x, int y, int ascent, int descent) { + } + } } 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 700a945602..75ecc7345e 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 @@ -34,22 +34,28 @@ public class LineStyleEvent extends TypedEvent { /* API UNDER CONSTRUCTION - DO NOT USE THIS FIELD * - * line alignment (output) + * line alignment (input, output) */ public int alignment; /* API UNDER CONSTRUCTION - DO NOT USE THIS FIELD * - * line indent (output) + * line indent (input, output) */ public int indent; /* API UNDER CONSTRUCTION - DO NOT USE THIS FIELD * - * line justification (output) + * line justification (input, output) */ public boolean justify; + /* API UNDER CONSTRUCTION - DO NOT USE THIS FIELD + * + * line bullet (input) + */ + public EmbeddedObject.Bullet bullet; + static final long serialVersionUID = 3906081274027192884L; public LineStyleEvent(StyledTextEvent e) { @@ -57,7 +63,8 @@ public LineStyleEvent(StyledTextEvent e) { lineOffset = e.detail; lineText = e.text; styles = e.styles; - alignment = -1; - indent = -1; + alignment = e.alignment; + indent = e.indent; + justify = e.justify; } } diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java index 61429ef68d..916e8a667e 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java @@ -3668,7 +3668,7 @@ public Color getLineBackground(int index) { SWT.error(SWT.ERROR_INVALID_ARGUMENT); } if (!userLineBackground) { - lineBackground = defaultLineStyler.getLineBackground(index); + lineBackground = defaultLineStyler.getLineBackground(index, null); } return lineBackground; } @@ -4999,7 +4999,7 @@ void handleDispose(Event event) { rightCaretBitmap = null; } if (defaultLineStyler != null) { - defaultLineStyler.release(); + defaultLineStyler.dispose(); defaultLineStyler = null; } if (isBidiCaret()) { 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 0ebf00eadd..9a6fa8b516 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 @@ -1492,7 +1492,19 @@ public void addExtendedModifyListener(ExtendedModifyListener extendedModifyListe StyledTextListener typedListener = new StyledTextListener(extendedModifyListener); addListener(ExtendedModify, typedListener); } -public void setAlignment (int alignment) { +/** + * Sets the default alignment of the receiver + * <p> + * + * @param alignment alignment + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * @see #setLineAlignment(int, int, int) + * @since 3.2 + */ +public void setAlignment(int alignment) { checkWidget(); alignment &= (SWT.LEFT | SWT.RIGHT | SWT.CENTER); if (alignment == 0 || this.alignment == alignment); @@ -2057,6 +2069,22 @@ public void copy(int clipboardType) { } } /** + * Returns the default alignment of the receiver + * <p> + * + * @return the alignment + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * @see #getLineAlignment(int) + * @since 3.2 + */ +public int getAlignment() { + checkWidget(); + return alignment; +} +/** * Returns a string that uses only the line delimiter specified by the * StyledTextContent implementation. * Returns only the first line if the widget has the SWT.SINGLE style. @@ -3334,6 +3362,33 @@ public int getHorizontalPixel() { checkWidget(); return horizontalScrollOffset; } +/** + * Returns the default indent of the receiver + * <p> + * + * @return the 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> + * @see #getLineIndent(int) + * @since 3.2 + */ +public int getIndent() { + checkWidget(); + return lineIndent; +} +/** + * Returns the default justify of the receiver + * + * @return justify + * + * @since 3.2 + */ +public boolean getJustify() { + checkWidget(); + return justify; +} /** * Returns the action assigned to the key. * Returns SWT.NULL if there is no action associated with the key. @@ -3371,6 +3426,30 @@ public int getCharCount() { return content.getCharCount(); } /** + * Returns the alignment of the line at the given index. + * <p> + * + * @param index the index of the line + * @return the line alignment + * + * @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> + * @see #getAlignment() + * @since 3.2 + */ +public int getLineAlignment(int index) { + checkWidget(); + if (index < 0 || index > content.getLineCount()) { + SWT.error(SWT.ERROR_INVALID_ARGUMENT); + } + return defaultLineStyler.getLineAlignment(index, alignment); +} +/** * Returns the line at the specified offset in the text * where 0 <= offset <= getCharCount() so that getLineAtOffset(getCharCount()) * returns the line of the insert location. @@ -3416,7 +3495,7 @@ public Color getLineBackground(int index) { if (index < 0 || index > content.getLineCount()) { SWT.error(SWT.ERROR_INVALID_ARGUMENT); } - return !userLineBackground ? defaultLineStyler.getLineBackground(index) : null; + return userLineBackground ? null : defaultLineStyler.getLineBackground(index, null); } /** * Returns the line background data for the given line or null if @@ -3489,6 +3568,69 @@ public int getLineHeight() { return lineHeight; } /** + * Returns the indent of the line at the given index. + * <p> + * + * @param index the index of the line + * @return the 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 index is invalid</li> + * </ul> + * @see #getIndent() + * @since 3.2 + */ +public int getLineIndent(int index) { + checkWidget(); + if (index < 0 || index > content.getLineCount()) { + SWT.error(SWT.ERROR_INVALID_ARGUMENT); + } + return defaultLineStyler.getLineIndent(index, lineIndent); +} +/** + * Returns the justify of the line at the given index. + * <p> + * + * @param index the index of the line + * @return the line justify + * + * @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> + * @see #getJustify() + * @since 3.2 + */ +public boolean getLineJustify(int index) { + checkWidget(); + if (index < 0 || index > content.getLineCount()) { + SWT.error(SWT.ERROR_INVALID_ARGUMENT); + } + return defaultLineStyler.getLineJustify(index, justify); +} +/** + * Returns the line spacing of the receiver + * <p> + * + * @return the line spacing + * @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> + * @since 3.2 + */ +public int getLineSpacing() { + checkWidget(); + return lineSpacing; +} +/** * 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 @@ -4776,7 +4918,7 @@ void handleDispose(Event event) { rightCaretBitmap = null; } if (defaultLineStyler != null) { - defaultLineStyler.release(); + defaultLineStyler.dispose(); defaultLineStyler = null; } if (isBidiCaret()) { @@ -5409,11 +5551,29 @@ public void invokeAction(int action) { } } /** + * Returns whether or not the given lines are visible. + * <p> + * + * @return true if any of the lines is visible + * false if none of the lines is visible + */ +boolean isAreaVisible(int firstLine, int lastLine) { + int partialTopIndex = getPartialTopIndex(); + int partialBottomIndex = getPartialBottomIndex(); + return !(firstLine > partialBottomIndex || lastLine < partialTopIndex); +} +/** * Temporary until SWT provides this */ boolean isBidi() { return IS_GTK || BidiUtil.isBidiPlatform() || isMirrored; } +boolean isBidiCaret() { + return BidiUtil.isBidiPlatform(); +} +boolean isFixedLineHeight() { + return fixedLineHeight; +} /** * Returns whether the given offset is inside a multi byte line delimiter. * Example: @@ -5442,18 +5602,6 @@ boolean isMirrored() { return isMirrored; } /** - * Returns whether or not the given lines are visible. - * <p> - * - * @return true if any of the lines is visible - * false if none of the lines is visible - */ -boolean isAreaVisible(int firstLine, int lastLine) { - int partialTopIndex = getPartialTopIndex(); - int partialBottomIndex = getPartialBottomIndex(); - return !(firstLine > partialBottomIndex || lastLine < partialTopIndex); -} -/** * Returns whether the widget can have only one line. * <p> * @@ -5682,6 +5830,26 @@ public void redraw(int x, int y, int width, int height, boolean all) { resetCache(firstLine, lastLine - firstLine + 1); } } +void redrawLines(int startLine, int lineCount) { + // do nothing if redraw range is completely invisible + int partialBottomIndex = getPartialBottomIndex(); + if (startLine > partialBottomIndex || startLine + lineCount - 1 < topIndex) { + return; + } + // only redraw visible lines + if (startLine < topIndex) { + lineCount -= topIndex - startLine; + startLine = topIndex; + } + if (startLine + lineCount - 1 > partialBottomIndex) { + lineCount = partialBottomIndex - startLine + 1; + } + startLine -= topIndex; + int redrawTop = getLinePixel(startLine); + int redrawBottom = getLinePixel(startLine + lineCount); + int redrawWidth = getClientArea().width - leftMargin - rightMargin; + super.redraw(leftMargin, redrawTop, redrawWidth, redrawBottom - redrawTop, true); +} /** * Redraws the specified text range. * <p> @@ -5929,7 +6097,7 @@ 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) { + if (range != null && (range.font != null || range.rise != 0)) { if (!isFixedLineHeight()) { lineCache.setAllLinesDefaultHeight(); } @@ -6214,6 +6382,9 @@ StyledTextEvent sendLineEvent(int eventType, int lineOffset, String line) { event = new StyledTextEvent(content); event.detail = lineOffset; event.text = line; + event.alignment = alignment; + event.indent = lineIndent; + event.justify = justify; notifyListeners(eventType, event); } return event; @@ -6507,9 +6678,6 @@ public void setEditable(boolean editable) { checkWidget(); this.editable = editable; } -void setLineHeightVariable () { - fixedLineHeight = false; -} /** * Sets a new font to render text with. * <p> @@ -6631,6 +6799,32 @@ public void setHorizontalPixel(int pixel) { } scrollHorizontal(pixel - horizontalScrollOffset, true); } +/** + * Sets the default indent of the receiver + * <p> + * + * @param lineIndent 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> + * @see #setLineIndent(int, int, int) + * @since 3.2 + */ +public void setIndent(int lineIndent) { + checkWidget(); + if (this.lineIndent == lineIndent || lineIndent < 0) return; + this.lineIndent = lineIndent; + setCaretLocation(); + super.redraw(); +} +/** + * Set the default justify of the receiver + * + * @param justify + * + * @since 3.2 + */ public void setJustify(boolean justify) { checkWidget(); if (this.justify == justify) return; @@ -6638,6 +6832,38 @@ public void setJustify(boolean justify) { setCaretLocation(); super.redraw(); } +/** + * Sets the alignment of the specified lines. + * <p> + * + * @param startLine first line the alignment is applied to, 0 based + * @param lineCount number of lines the alignment applies to. + * @param alignment line alignment + * + * @exception SWTException <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> + * @see #setAlignment(int) + * @since 3.2 + */ +public void setLineAlignment(int startLine, int lineCount, int alignment) { + checkWidget(); + if (userLineStyle) return; + if (startLine < 0 || startLine + lineCount > content.getLineCount()) { + SWT.error(SWT.ERROR_INVALID_ARGUMENT); + } + + defaultLineStyler.setLineAlignment(startLine, lineCount, alignment); + redrawLines(startLine, lineCount); + int caretLine = getCaretLine(); + if (startLine <= caretLine && caretLine < startLine + lineCount) { + setCaretLocation(); + } +} /** * Sets the background color of the specified lines. * The background color is drawn for the width of the widget. All @@ -6672,42 +6898,93 @@ public void setJustify(boolean justify) { * </ul> */ public void setLineBackground(int startLine, int lineCount, Color background) { - checkWidget(); - - // this API can not be used if the client is providing the line background - if (userLineBackground) { - return; - } + checkWidget(); + if (userLineBackground) return; if (startLine < 0 || startLine + lineCount > content.getLineCount()) { SWT.error(SWT.ERROR_INVALID_ARGUMENT); } + defaultLineStyler.setLineBackground(startLine, lineCount, background); - // do nothing if redraw range is completely invisible - int partialBottomIndex = getPartialBottomIndex(); - if (startLine > partialBottomIndex || startLine + lineCount - 1 < topIndex) { - return; - } - // only redraw visible lines - if (startLine < topIndex) { - lineCount -= topIndex - startLine; - startLine = topIndex; + redrawLines(startLine, lineCount); +} +void setLineHeightVariable () { + fixedLineHeight = false; +} +/** + * Sets the indent of the specified lines. + * <p> + * + * @param startLine first line the indent is applied to, 0 based + * @param lineCount number of lines the indent applies to. + * @param indent line indent + * + * @exception SWTException <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> + * @see #setIndent(int) + * @since 3.2 + */ +public void setLineIndent(int startLine, int lineCount, int indent) { + checkWidget(); + if (userLineStyle) return; + if (startLine < 0 || startLine + lineCount > content.getLineCount()) { + SWT.error(SWT.ERROR_INVALID_ARGUMENT); } - if (startLine + lineCount - 1 > partialBottomIndex) { - lineCount = partialBottomIndex - startLine + 1; + + defaultLineStyler.setLineIndent(startLine, lineCount, indent); + redrawLines(startLine, lineCount); + int caretLine = getCaretLine(); + if (startLine <= caretLine && caretLine < startLine + lineCount) { + setCaretLocation(); } - startLine -= topIndex; - int redrawTop = getLinePixel(startLine); - int redrawBottom = getLinePixel(startLine + lineCount); - int redrawWidth = getClientArea().width - leftMargin - rightMargin; - super.redraw(leftMargin, redrawTop, redrawWidth, redrawBottom - redrawTop, true); } -public void setLineIndent(int lineIndent) { +/** + * Sets the justify of the specified lines. + * <p> + * + * @param startLine first line the justify is applied to, 0 based + * @param lineCount number of lines the justify 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> + * @see #setJustify(boolean) + * @since 3.2 + */ +public void setLineJustify(int startLine, int lineCount, boolean justify) { checkWidget(); - if (this.lineIndent == lineIndent || lineIndent < 0) return; - this.lineIndent = lineIndent; - setCaretLocation(); - super.redraw(); + if (userLineStyle) return; + if (startLine < 0 || startLine + lineCount > content.getLineCount()) { + SWT.error(SWT.ERROR_INVALID_ARGUMENT); + } + + defaultLineStyler.setLineJustify(startLine, lineCount, justify); + redrawLines(startLine, lineCount); + int caretLine = getCaretLine(); + if (startLine <= caretLine && caretLine < startLine + lineCount) { + setCaretLocation(); + } } +/** + * Sets the line spacing of the receiver + * <p> + * + * @param lineSpacing line spacing + * @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> + * @since 3.2 + */ public void setLineSpacing(int lineSpacing) { checkWidget(); if (this.lineSpacing == lineSpacing || lineSpacing < 0) return; @@ -7060,7 +7337,7 @@ public void setStyleRange(StyleRange range) { } defaultLineStyler.setStyleRange(range); if (range != null) { - if (range.font != null) { + if (range.font != null || range.rise != 0) { if (!isFixedLineHeight()) { lineCache.setAllLinesDefaultHeight(); } @@ -7132,7 +7409,7 @@ public void setStyleRanges(StyleRange[] ranges) { for (int i = 0; i < ranges.length; i++) { StyleRange range = ranges[i]; - if (range != null && range.font != null) { + if (range != null && (range.font != null || range.rise != 0)) { if (!isFixedLineHeight()) { lineCache.setAllLinesDefaultHeight(); } @@ -7423,12 +7700,6 @@ public void showSelection() { showLocation(endPos); } } -boolean isBidiCaret() { - return BidiUtil.isBidiPlatform(); -} -boolean isFixedLineHeight() { - return fixedLineHeight; -} /** * Updates the selection and caret position depending on the text change. * If the selection intersects with the replaced text, the selection is 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 e44bd92253..4f1899fb5e 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 @@ -22,6 +22,7 @@ class StyledTextEvent extends Event { int alignment; int indent; boolean justify; + EmbeddedObject.Bullet bullet; // 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 310a32a516..17f78064de 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 @@ -48,6 +48,7 @@ public void handleEvent(Event e) { ((StyledTextEvent) e).alignment = lineStyleEvent.alignment; ((StyledTextEvent) e).indent = lineStyleEvent.indent; ((StyledTextEvent) e).justify = lineStyleEvent.justify; + ((StyledTextEvent) e).bullet = lineStyleEvent.bullet; 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 ae81772f11..d89b289b71 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 @@ -350,13 +350,9 @@ TextLayout getTextLayout(String line, int lineOffset) { 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; + alignment = event.alignment & (SWT.CENTER | SWT.LEFT | SWT.RIGHT); + indent = event.indent; + justify = event.justify; } TextLayout layout = getTextLayout(line, lineOffset, segments, styles); layout.setAlignment(alignment); |