1 /******************************************************************************* 2 * Copyright (c) 2000, 2008 IBM Corporation and others. 3 * All rights reserved. This program and the accompanying materials 4 * are made available under the terms of the Eclipse Public License v1.0 5 * which accompanies this distribution, and is available at 6 * http://www.eclipse.org/legal/epl-v10.html 7 * 8 * Contributors: 9 * IBM Corporation - initial API and implementation 10 * Port to the D programming language: 11 * Frank Benoit <benoit@tionex.de> 12 *******************************************************************************/ 13 module org.eclipse.swt.custom.StyledTextContent; 14 15 import java.lang.all; 16 17 import org.eclipse.swt.custom.TextChangeListener; 18 /** 19 * Clients may implement the StyledTextContent interface to provide a 20 * custom store for the StyledText widget content. The StyledText widget 21 * interacts with its StyledTextContent in order to access and update 22 * the text that is being displayed and edited in the widget. 23 * A custom content implementation can be set in the widget using the 24 * StyledText.setContent API. 25 */ 26 public interface StyledTextContent { 27 28 /** 29 * Called by StyledText to add itself as an Observer to content changes. 30 * See TextChangeListener for a description of the listener methods that 31 * are called when text changes occur. 32 * <p> 33 * 34 * @param listener the listener 35 * @exception IllegalArgumentException <ul> 36 * <li>ERROR_NULL_ARGUMENT when listener is null</li> 37 * </ul> 38 */ 39 public void addTextChangeListener(TextChangeListener listener); 40 41 /** 42 * Return the number of characters in the content. 43 * <p> 44 * 45 * @return the number of characters in the content. 46 */ 47 public int getCharCount(); 48 49 /** 50 * Return the line at the given line index without delimiters. 51 * <p> 52 * 53 * @param lineIndex index of the line to return. Does not include 54 * delimiters of preceding lines. Index 0 is the first line of the 55 * content. 56 * @return the line text without delimiters 57 */ 58 public String getLine(int lineIndex); 59 60 /** 61 * Return the line index at the given character offset. 62 * <p> 63 * 64 * @param offset offset of the line to return. The first character of the 65 * document is at offset 0. An offset of getLength() is valid and should 66 * answer the number of lines. 67 * @return the line index. The first line is at index 0. If the character 68 * at offset is a delimiter character, answer the line index of the line 69 * that is delimited. 70 * For example, if text = "\r\n\r\n", and delimiter = "\r\n", then: 71 * <ul> 72 * <li>getLineAtOffset(0) is 0 73 * <li>getLineAtOffset(1) is 0 74 * <li>getLineAtOffset(2) is 1 75 * <li>getLineAtOffset(3) is 1 76 * <li>getLineAtOffset(4) is 2 77 * </ul> 78 */ 79 public int getLineAtOffset(int offset); 80 81 /** 82 * Return the number of lines. Should answer 1 when no text is specified. 83 * The StyledText widget relies on this behavior for drawing the cursor. 84 * <p> 85 * 86 * @return the number of lines. For example: 87 * <ul> 88 * <li> text value is> getLineCount 89 * <li> null is> 1 90 * <li> "" is> 1 91 * <li> "a\n" is> 2 92 * <li> "\n\n" is> 3 93 * </ul> 94 */ 95 public int getLineCount(); 96 97 /** 98 * Return the line delimiter that should be used by the StyledText 99 * widget when inserting new lines. New lines entered using key strokes 100 * and paste operations use this line delimiter. 101 * Implementors may use System.getProperty("line.separator") to return 102 * the platform line delimiter. 103 * <p> 104 * 105 * @return the line delimiter that should be used by the StyledText widget 106 * when inserting new lines. 107 */ 108 public String getLineDelimiter(); 109 110 /** 111 * Return the character offset of the first character of the given line. 112 * <p> 113 * <b>NOTE:</b> When there is no text (i.e., no lines), getOffsetAtLine(0) 114 * is a valid call that should return 0. 115 * </p> 116 * 117 * @param lineIndex index of the line. The first line is at index 0. 118 * @return offset offset of the first character of the line. The first 119 * character of the document is at offset 0. The return value should 120 * include line delimiters. 121 * For example, if text = "\r\ntest\r\n" and delimiter = "\r\n", then: 122 * <ul> 123 * <li>getOffsetAtLine(0) is 0 124 * <li>getOffsetAtLine(1) is 2 125 * <li>getOffsetAtLine(2) is 8 126 * </ul> 127 */ 128 public int getOffsetAtLine(int lineIndex); 129 130 /** 131 * Returns a string representing the content at the given range. 132 * <p> 133 * 134 * @param start the start offset of the text to return. Offset 0 is the 135 * first character of the document. 136 * @param length the length of the text to return 137 * @return the text at the given range 138 */ 139 public String getTextRange(int start, int length); 140 141 /** 142 * Remove the specified text changed listener. 143 * <p> 144 * 145 * @param listener the listener which should no longer be notified 146 * 147 * @exception IllegalArgumentException <ul> 148 * <li>ERROR_NULL_ARGUMENT when listener is null</li> 149 * </ul> 150 */ 151 public void removeTextChangeListener(TextChangeListener listener); 152 153 /** 154 * Replace the text with "newText" starting at position "start" 155 * for a length of "replaceLength". 156 * <p> 157 * Implementors have to notify the TextChangeListeners that were added 158 * using <code>addTextChangeListener</code> before and after the content 159 * is changed. A <code>TextChangingEvent</code> has to be sent to the 160 * textChanging method before the content is changed and a 161 * <code>TextChangedEvent</code> has to be sent to the textChanged method 162 * after the content has changed. 163 * The text change that occurs after the <code>TextChangingEvent</code> 164 * has been sent has to be consistent with the data provided in the 165 * <code>TextChangingEvent</code>. 166 * This data will be cached by the widget and will be used when the 167 * <code>TextChangedEvent</code> is received. 168 * <p> 169 * The <code>TextChangingEvent</code> should be set as follows: 170 * <ul> 171 * <li>event.start = start of the replaced text 172 * <li>event.newText = text that is going to be inserted or empty String 173 * if no text will be inserted 174 * <li>event.replaceCharCount = length of text that is going to be replaced 175 * <li>event.newCharCount = length of text that is going to be inserted 176 * <li>event.replaceLineCount = number of lines that are going to be replaced 177 * <li>event.newLineCount = number of new lines that are going to be inserted 178 * </ul> 179 * <b>NOTE:</b> newLineCount is the number of inserted lines and replaceLineCount 180 * is the number of deleted lines based on the change that occurs visually. 181 * For example: 182 * <ul> 183 * <li>(replaceText, newText) is> (replaceLineCount, newLineCount) 184 * <li>("", "\n") is> (0, 1) 185 * <li>("\n\n", "a") is> (2, 0) 186 * <li>("a", "\n\n") is> (0, 2) 187 * <li>("\n", "") is> (1, 0) 188 * </ul> 189 * </p> 190 * 191 * @param start start offset of text to replace, none of the offsets include 192 * delimiters of preceding lines, offset 0 is the first character of the 193 * document 194 * @param replaceLength length of text to replace 195 * @param text text to replace 196 * @see TextChangeListener 197 */ 198 public void replaceTextRange(int start, int replaceLength, String text); 199 200 /** 201 * Set text to "text". 202 * Implementors have to send a <code>TextChangedEvent</code> to the 203 * textSet method of the TextChangeListeners that were added using 204 * <code>addTextChangeListener</code>. 205 * <p> 206 * 207 * @param text the new text 208 * @see TextChangeListener 209 */ 210 public void setText(String text); 211 212 }