Mercurial > projects > dwt-linux
changeset 97:5eaabd099f15
BidiSegmentEvent, Bullet, StyledTextContent, StyledTextEvent, TextChangeListener, TextChangedEvent, TextChangingEvent
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Fri, 18 Jan 2008 02:39:07 +0100 |
parents | 9ec02606e09d |
children | bf44a537c2e9 |
files | dwt/custom/BidiSegmentEvent.d dwt/custom/Bullet.d dwt/custom/StyledTextContent.d dwt/custom/StyledTextEvent.d dwt/custom/TextChangeListener.d dwt/custom/TextChangedEvent.d dwt/custom/TextChangingEvent.d |
diffstat | 7 files changed, 644 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dwt/custom/BidiSegmentEvent.d Fri Jan 18 02:39:07 2008 +0100 @@ -0,0 +1,83 @@ +/******************************************************************************* + * 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 + *******************************************************************************/ +module dwt.custom.BidiSegmentEvent; + + +import dwt.events.TypedEvent; +import dwt.custom.StyledTextEvent; + +/** + * This event is sent to BidiSegmentListeners when a line is to + * be measured or rendered in a bidi locale. The segments field is + * used to specify text ranges in the line that should be treated as + * separate segments for bidi reordering. Each segment will be reordered + * and rendered separately. + * <p> + * 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: + * <ul> + * <li>first element must be 0 + * <li>elements must be in ascending order and must not have duplicates + * <li>elements must not exceed the line length + * </ul> + * In addition, the last element may be set to the end of the line + * but this is not required. + * + * The segments field may be left null if the entire line should + * be reordered as is. + * </p> + * A BidiSegmentListener may be used when adjacent segments of + * right-to-left text should not be reordered relative to each other. + * For example, within a Java editor, you may wish multiple + * right-to-left string literals to be reordered differently than the + * bidi algorithm specifies. + * + * Example: + * <pre> + * stored line = "R1R2R3" + "R4R5R6" + * R1 to R6 are right-to-left characters. The quotation marks + * are part of the line text. The line is 13 characters long. + * + * segments = null: + * entire line will be reordered and thus the two R2L segments + * swapped (as per the bidi algorithm). + * visual line (rendered on screen) = "R6R5R4" + "R3R2R1" + * + * segments = [0, 5, 8] + * "R1R2R3" will be reordered, followed by [blank]+[blank] and + * "R4R5R6". + * visual line = "R3R2R1" + "R6R5R4" + * </pre> + */ +public class BidiSegmentEvent : TypedEvent { + + /** + * line start offset + */ + public int lineOffset; + + /** + * line text + */ + public char[] lineText; + + /** + * bidi segments, see above + */ + public int[] segments; + +this(StyledTextEvent e) { + super(cast(Object)e); + lineOffset = e.detail; + lineText = e.text; +} +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dwt/custom/Bullet.d Fri Jan 18 02:39:07 2008 +0100 @@ -0,0 +1,137 @@ +/******************************************************************************* + * Copyright (c) 2000, 2006 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 + *******************************************************************************/ +module dwt.custom.Bullet; + +import dwt.DWT; +import dwt.custom.StyleRange; +import dwt.custom.ST; +import dwt.dwthelper.System; + +/** + * Instances of this class represent bullets in the <code>StyledText</code>. + * <p> + * 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. + * </p> + * <p> + * Application code does <em>not</em> need to explicitly release the + * resources managed by each instance when those instances are no longer + * required, and thus no <code>dispose()</code> method is provided. + * </p> + * + * @see StyledText#setLineBullet(int, int, Bullet) + * + * @since 3.2 + */ +public class Bullet { + public int type; + public StyleRange style; + public char[] text; + int[] linesIndices; + int count; + +/** + * Create a new bullet the specified style, the type is set to ST.BULLET_DOT. + * The style must have a glyph metrics set. + * + * @param style the style + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT when the style or the glyph metrics are null</li> + * </ul> + */ +public this(StyleRange style) { + this(ST.BULLET_DOT, style); +} +/** + * Create a new bullet the specified style and type. + * The style must have a glyph metrics set. + * + * @param style the style + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT when the style or the glyph metrics are null</li> + * </ul> + */ +public this(int type, StyleRange style) { + if (style is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); + if (style.metrics is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); + this.type = type; + this.style = style; +} +void addIndices (int startLine, int lineCount) { + if (linesIndices is null) { + linesIndices = new int[lineCount]; + count = lineCount; + for (int i = 0; i < lineCount; i++) linesIndices[i] = startLine + i; + } else { + int modifyStart = 0; + while (modifyStart < count) { + if (startLine <= linesIndices[modifyStart]) break; + modifyStart++; + } + int modifyEnd = modifyStart; + while (modifyEnd < count) { + if (startLine + lineCount <= linesIndices[modifyEnd]) break; + modifyEnd++; + } + int newSize = modifyStart + lineCount + count - modifyEnd; + if (newSize > linesIndices.length) { + int[] newLinesIndices = new int[newSize]; + System.arraycopy(linesIndices, 0, newLinesIndices, 0, count); + linesIndices = newLinesIndices; + } + System.arraycopy(linesIndices, modifyEnd, linesIndices, modifyStart + lineCount, count - modifyEnd); + for (int i = 0; i < lineCount; i++) linesIndices[modifyStart + i] = startLine + i; + count = newSize; + } +} +int indexOf (int lineIndex) { + for (int i = 0; i < count; i++) { + if (linesIndices[i] is lineIndex) return i; + } + return -1; +} +public override hash_t toHash() { + return style.toHash() ^ type; +} +int[] removeIndices (int startLine, int replaceLineCount, int newLineCount, bool update) { + if (count is 0) return null; + if (startLine > linesIndices[count - 1]) return null; + int endLine = startLine + replaceLineCount; + int delta = newLineCount - replaceLineCount; + for (int i = 0; i < count; i++) { + int index = linesIndices[i]; + if (startLine <= index) { + int j = i; + while (j < count) { + if (linesIndices[j] >= endLine) break; + j++; + } + if (update) { + for (int k = j; k < count; k++) linesIndices[k] += delta; + } + int[] redrawLines = new int[count - j]; + System.arraycopy(linesIndices, j, redrawLines, 0, count - j); + System.arraycopy(linesIndices, j, linesIndices, i, count - j); + count -= (j - i); + return redrawLines; + } + } + for (int i = 0; i < count; i++) linesIndices[i] += delta; + return null; +} +int size() { + return count; +} +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dwt/custom/StyledTextContent.d Fri Jan 18 02:39:07 2008 +0100 @@ -0,0 +1,206 @@ +/******************************************************************************* + * Copyright (c) 2000, 2006 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 + *******************************************************************************/ +module dwt.custom.StyledTextContent; + +import dwt.custom.TextChangeListener; +/** + * Clients may implement the StyledTextContent interface to provide a + * custom store for the StyledText widget content. The StyledText widget + * interacts with its StyledTextContent in order to access and update + * the text that is being displayed and edited in the widget. + * A custom content implementation can be set in the widget using the + * StyledText.setContent API. + */ +public interface StyledTextContent { + +/** + * Called by StyledText to add itself as an Observer to content changes. + * See TextChangeListener for a description of the listener methods that + * are called when text changes occur. + * <p> + * + * @param listener the listener + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT when listener is null</li> + * </ul> + */ +public void addTextChangeListener(TextChangeListener listener); + +/** + * Return the number of characters in the content. + * <p> + * + * @return the number of characters in the content. + */ +public int getCharCount(); + +/** + * Return the line at the given line index without delimiters. + * <p> + * + * @param lineIndex index of the line to return. Does not include + * delimiters of preceding lines. Index 0 is the first line of the + * content. + * @return the line text without delimiters + */ +public char[] getLine(int lineIndex); + +/** + * Return the line index at the given character offset. + * <p> + * + * @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: + * <ul> + * <li>getLineAtOffset(0) is 0 + * <li>getLineAtOffset(1) is 0 + * <li>getLineAtOffset(2) is 1 + * <li>getLineAtOffset(3) is 1 + * <li>getLineAtOffset(4) is 2 + * </ul> + */ +public int getLineAtOffset(int offset); + +/** + * Return the number of lines. Should answer 1 when no text is specified. + * The StyledText widget relies on this behavior for drawing the cursor. + * <p> + * + * @return the number of lines. For example: + * <ul> + * <li> text value is> getLineCount + * <li> null is> 1 + * <li> "" is> 1 + * <li> "a\n" is> 2 + * <li> "\n\n" is> 3 + * </ul> + */ +public int getLineCount(); + +/** + * Return the line delimiter that should be used by the StyledText + * widget when inserting new lines. New lines entered using key strokes + * and paste operations use this line delimiter. + * Implementors may use System.getProperty("line.separator") to return + * the platform line delimiter. + * <p> + * + * @return the line delimiter that should be used by the StyledText widget + * when inserting new lines. + */ +public char[] getLineDelimiter(); + +/** + * Return the character offset of the first character of the given line. + * <p> + * <b>NOTE:</b> When there is no text (i.e., no lines), getOffsetAtLine(0) + * is a valid call that should return 0. + * </p> + * + * @param lineIndex index of the line. The first line is at index 0. + * @return offset offset of the first character of the line. The first + * character of the document is at offset 0. The return value should + * include line delimiters. + * For example, if text = "\r\ntest\r\n" and delimiter = "\r\n", then: + * <ul> + * <li>getOffsetAtLine(0) is 0 + * <li>getOffsetAtLine(1) is 2 + * <li>getOffsetAtLine(2) is 8 + * </ul> + */ +public int getOffsetAtLine(int lineIndex); + +/** + * Returns a string representing the content at the given range. + * <p> + * + * @param start the start offset of the text to return. Offset 0 is the + * first character of the document. + * @param length the length of the text to return + * @return the text at the given range + */ +public char[] getTextRange(int start, int length); + +/** + * Remove the specified text changed listener. + * <p> + * + * @param listener the listener + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT when listener is null</li> + * </ul> + */ +public void removeTextChangeListener(TextChangeListener listener); + +/** + * Replace the text with "newText" starting at position "start" + * for a length of "replaceLength". + * <p> + * Implementors have to notify the TextChangeListeners that were added + * using <code>addTextChangeListener</code> before and after the content + * is changed. A <code>TextChangingEvent</code> has to be sent to the + * textChanging method before the content is changed and a + * <code>TextChangedEvent</code> has to be sent to the textChanged method + * after the content has changed. + * The text change that occurs after the <code>TextChangingEvent</code> + * has been sent has to be consistent with the data provided in the + * <code>TextChangingEvent</code>. + * This data will be cached by the widget and will be used when the + * <code>TextChangedEvent</code> is received. + * <p> + * The <code>TextChangingEvent</code> should be set as follows: + * <ul> + * <li>event.start = start of the replaced text + * <li>event.newText = text that is going to be inserted or empty String + * if no text will be inserted + * <li>event.replaceCharCount = length of text that is going to be replaced + * <li>event.newCharCount = length of text that is going to be inserted + * <li>event.replaceLineCount = number of lines that are going to be replaced + * <li>event.newLineCount = number of new lines that are going to be inserted + * </ul> + * <b>NOTE:</b> newLineCount is the number of inserted lines and replaceLineCount + * is the number of deleted lines based on the change that occurs visually. + * For example: + * <ul> + * <li>(replaceText, newText) is> (replaceLineCount, newLineCount) + * <li>("", "\n") is> (0, 1) + * <li>("\n\n", "a") is> (2, 0) + * <li>("a", "\n\n") is> (0, 2) + * <li>("\n", "") is> (1, 0) + * </ul> + * </p> + * + * @param start start offset of text to replace, none of the offsets include + * delimiters of preceding lines, offset 0 is the first character of the + * document + * @param replaceLength length of text to replace + * @param text text to replace + * @see TextChangeListener + */ +public void replaceTextRange(int start, int replaceLength, char[] text); + +/** + * Set text to "text". + * Implementors have to send a <code>TextChangedEvent</code> to the + * textSet method of the TextChangeListeners that were added using + * <code>addTextChangeListener</code>. + * <p> + * + * @param text the new text + * @see TextChangeListener + */ +public void setText(char[] text); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dwt/custom/StyledTextEvent.d Fri Jan 18 02:39:07 2008 +0100 @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2000, 2007 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +module dwt.custom.StyledTextEvent; + + +import dwt.graphics.Color; +import dwt.widgets.Event; +import dwt.custom.StyleRange; +import dwt.custom.Bullet; +import dwt.custom.StyledTextContent; + +/** + * + */ +class StyledTextEvent : Event { + // used by LineStyleEvent + int[] ranges; + StyleRange[] styles; + int alignment; + int indent; + bool justify; + Bullet bullet; + int bulletIndex; + // used by LineBackgroundEvent + Color lineBackground; + // used by BidiSegmentEvent + int[] segments; + // used by TextChangedEvent + int replaceCharCount; + int newCharCount; + int replaceLineCount; + int newLineCount; + // used by PaintObjectEvent + int x; + int y; + int ascent; + int descent; + StyleRange style; + +this (StyledTextContent content) { + data = cast(Object)content; +} +} + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dwt/custom/TextChangeListener.d Fri Jan 18 02:39:07 2008 +0100 @@ -0,0 +1,63 @@ +/******************************************************************************* + * Copyright (c) 2000, 2003 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 + *******************************************************************************/ +module dwt.custom.TextChangeListener; + + +import dwt.internal.DWTEventListener; +import dwt.custom.TextChangingEvent; +import dwt.custom.TextChangedEvent; + +/** + * The StyledText widget implements this listener to receive + * notifications when changes to the model occur. + * It is not intended to be implemented by clients or by + * implementors of StyledTextContent. + * Clients should listen to the ModifyEvent or ExtendedModifyEvent + * that is sent by the StyledText widget to receive text change + * notifications. + * Implementors of StyledTextContent should call the textChanging + * and textChanged methods when text changes occur as described + * below. If the entire text is replaced the textSet method + * should be called instead. + */ +public interface TextChangeListener : DWTEventListener { + +/** + * This method is called when the content is about to be changed. + * Callers also need to call the textChanged method after the + * content change has been applied. The widget only updates the + * screen properly when it receives both events. + * + * @param event the text changing event. All event fields need + * to be set by the sender. + * @see TextChangingEvent + */ +public void textChanging(TextChangingEvent event); +/** + * This method is called when the content has changed. + * Callers need to have called the textChanging method prior to + * applying the content change and calling this method. The widget + * only updates the screen properly when it receives both events. + * + * @param event the text changed event + */ +public void textChanged(TextChangedEvent event); +/** + * This method is called instead of the textChanging/textChanged + * combination when the entire old content has been replaced + * (e.g., by a call to StyledTextContent.setText()). + * + * @param event the text changed event + */ +public void textSet(TextChangedEvent event); +} + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dwt/custom/TextChangedEvent.d Fri Jan 18 02:39:07 2008 +0100 @@ -0,0 +1,31 @@ +/******************************************************************************* + * 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 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +module dwt.custom.TextChangedEvent; + +import dwt.events.TypedEvent; +import dwt.custom.StyledTextContent; +/** + * This event is sent by the StyledTextContent implementor when a change to + * the text occurs. + */ +public class TextChangedEvent : TypedEvent { + +/** + * Create the TextChangedEvent to be used by the StyledTextContent implementor. + * <p> + * + * @param source the object that will be sending the TextChangedEvent, + * cannot be null + */ +public this(StyledTextContent source) { + super(cast(Object)source); +} +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dwt/custom/TextChangingEvent.d Fri Jan 18 02:39:07 2008 +0100 @@ -0,0 +1,71 @@ +/******************************************************************************* + * 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 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +module dwt.custom.TextChangingEvent; + + +import dwt.events.TypedEvent; +import dwt.custom.StyledTextContent; +import dwt.custom.StyledTextEvent; + +/** + * This event is sent by the StyledTextContent implementor when a change + * to the text is about to occur. + */ +public class TextChangingEvent : TypedEvent { + /** + * Start offset of the text that is going to be replaced + */ + public int start; + /** + * Text that is going to be inserted or empty string + * if no text will be inserted + */ + public char[] newText; + /** + * Length of text that is going to be replaced + */ + public int replaceCharCount; + /** + * Length of text that is going to be inserted + */ + public int newCharCount; + /** + * Number of lines that are going to be replaced + */ + public int replaceLineCount; + /** + * Number of new lines that are going to be inserted + */ + public int newLineCount; + + static final long serialVersionUID = 3257290210114352439L; + +/** + * Create the TextChangedEvent to be used by the StyledTextContent implementor. + * <p> + * + * @param source the object that will be sending the new TextChangingEvent, + * cannot be null + */ +public this(StyledTextContent source) { + super( cast(Object)source); +} +this(StyledTextContent source, StyledTextEvent e) { + super( cast(Object)source); + start = e.start; + replaceCharCount = e.replaceCharCount; + newCharCount = e.newCharCount; + replaceLineCount = e.replaceLineCount; + newLineCount = e.newLineCount; + newText = e.text; +} + +}