Mercurial > projects > dwt-win
diff dwt/custom/StyledText.d @ 212:ab60f3309436
reverted the char[] to String and use the an alias.
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 05 May 2008 00:12:38 +0200 |
parents | 184ab53b7785 |
children | 36f5cb12e1a2 |
line wrap: on
line diff
--- a/dwt/custom/StyledText.d Sat Apr 26 10:01:48 2008 +0200 +++ b/dwt/custom/StyledText.d Mon May 05 00:12:38 2008 +0200 @@ -148,7 +148,7 @@ alias Canvas.computeSize computeSize; static const char TAB = '\t'; - static const char[] PlatformLineDelimiter = tango.io.FileConst.FileConst.NewlineString; + static const String PlatformLineDelimiter = tango.io.FileConst.FileConst.NewlineString; static const int BIDI_CARET_WIDTH = 3; static const int DEFAULT_WIDTH = 64; static const int DEFAULT_HEIGHT = 64; @@ -229,7 +229,7 @@ const static bool IS_CARBON, IS_GTK, IS_MOTIF; static this(){ - char[] platform = DWT.getPlatform(); + String platform = DWT.getPlatform(); IS_CARBON = ("carbon" == platform); IS_GTK = ("gtk" == platform); IS_MOTIF = ("motif" == platform); @@ -313,7 +313,7 @@ if (styledText.isListening(LineGetBackground) || (styledText.isBidi() && styledText.isListening(LineGetSegments)) || styledText.isListening(LineGetStyle)) { StyledTextContent content = printerRenderer.content; for (int i = 0; i < lineCount; i++) { - char[] line = content.getLine(i); + String line = content.getLine(i); int lineOffset = content.getOffsetAtLine(i); StyledTextEvent event = styledText.getLineBackgroundData(lineOffset, line); if (event !is null && event.lineBackground !is null) { @@ -601,12 +601,12 @@ * @param header true = print the header, false = print the footer */ void printDecoration(int page, bool header, TextLayout layout) { - char[] text = header ? printOptions.header : printOptions.footer; + String text = header ? printOptions.header : printOptions.footer; if (text is null) return; int lastSegmentIndex = 0; for (int i = 0; i < 3; i++) { int segmentIndex = tango.text.Util.locatePattern( text, StyledTextPrintOptions.SEPARATOR, lastSegmentIndex); - char[] segment; + String segment; if (segmentIndex is text.length ) { segment = text[ lastSegmentIndex .. $ ].dup; printDecorationSegment(segment, i, page, header, layout); @@ -628,7 +628,7 @@ * @param page page number to print, if specified in the decoration segment. * @param header true = print the header, false = print the footer */ - void printDecorationSegment(char[] segment, int alignment, int page, bool header, TextLayout layout) { + void printDecorationSegment(String segment, int alignment, int page, bool header, TextLayout layout) { int pageIndex = tango.text.Util.locatePattern( segment, StyledTextPrintOptions.PAGE_TAG ); if (pageIndex !is segment.length ) { int pageTagLength = StyledTextPrintOptions.PAGE_TAG.length; @@ -676,7 +676,7 @@ FontMetrics metrics = layout.getLineMetrics(0); printLayout.setAscent(metrics.getAscent() + metrics.getDescent()); printLayout.setDescent(metrics.getDescent()); - printLayout.setText( to!(char[])(index) ); + printLayout.setText( to!(String)(index) ); int paintX = x - printMargin - printLayout.getBounds().width; printLayout.draw(gc, paintX, y); printLayout.setAscent(-1); @@ -689,7 +689,7 @@ * Starts a print job and prints the pages specified in the constructor. */ public void run() { - char[] jobName = printOptions.jobName; + String jobName = printOptions.jobName; if (jobName is null) { jobName = "Printing"; } @@ -804,12 +804,12 @@ * Don't write Unicode RTF on Windows 95/98/ME or NT. */ void setUnicode() { -// const char[] Win95 = "windows 95"; -// const char[] Win98 = "windows 98"; -// const char[] WinME = "windows me"; -// const char[] WinNT = "windows nt"; -// char[] osName = System.getProperty("os.name").toLowerCase(); -// char[] osVersion = System.getProperty("os.version"); +// const String Win95 = "windows 95"; +// const String Win98 = "windows 98"; +// const String WinME = "windows me"; +// const String WinNT = "windows nt"; +// String osName = System.getProperty("os.name").toLowerCase(); +// String osVersion = System.getProperty("os.version"); // int majorVersion = 0; // // if (osName.startsWith(WinNT) && osVersion !is null) { @@ -839,7 +839,7 @@ * @param start start offset of segment. 0 based. * @param end end offset of segment */ - void write(char[] string, int start, int end) { + void write(String string, int start, int end) { wchar[] wstring = tango.text.convert.Utf.toString16( string[ start .. end ] ); start = 0; end = wstring.length; @@ -852,7 +852,7 @@ write(tango.text.convert.Utf.toString(wstring[start .. index ])); } write("\\u"); - write( to!(char[])( cast(short)ch )); + write( to!(String)( cast(short)ch )); write(' '); // control word delimiter start = index + 1; } else if (ch is '}' || ch is '{' || ch is '\\') { @@ -881,8 +881,8 @@ header.append("{\\rtf1\\ansi"); // specify code page, necessary for copy to work in bidi // systems that don't support Unicode RTF. - // PORTING_TODO: char[] cpg = System.getProperty("file.encoding").toLowerCase(); - char[] cpg = "UTF16"; + // PORTING_TODO: String cpg = System.getProperty("file.encoding").toLowerCase(); + String cpg = "UTF16"; /+ if (cpg.startsWith("cp") || cpg.startsWith("ms")) { cpg = cpg.substring(2, cpg.length()); @@ -934,7 +934,7 @@ * <li>ERROR_IO when the writer is closed.</li> * </ul> */ - public override void writeLine(char[] line, int lineOffset) { + public override void writeLine(String line, int lineOffset) { if (isClosed()) { DWT.error(DWT.ERROR_IO); } @@ -971,7 +971,7 @@ * <li>ERROR_IO when the writer is closed.</li> * </ul> */ - public override void writeLineDelimiter(char[] lineDelimiter) { + public override void writeLineDelimiter(String lineDelimiter) { if (isClosed()) { DWT.error(DWT.ERROR_IO); } @@ -996,7 +996,7 @@ * @param lineBackground line background color to use for formatting. * May be null. */ - void writeStyledLine(char[] line, int lineOffset, int ranges[], StyleRange[] styles, Color lineBackground, int indent, int alignment, bool justify) { + void writeStyledLine(String line, int lineOffset, int ranges[], StyleRange[] styles, Color lineBackground, int indent, int alignment, bool justify) { int lineLength = line.length; int startOffset = getStart(); int writeOffset = startOffset - lineOffset; @@ -1174,13 +1174,13 @@ * * @return the string */ - public override char[] toString() { + public override String toString() { return buffer.toString(); } /** * Appends the given string to the data. */ - void write(char[] string) { + void write(String string) { buffer.append(string); } /** @@ -1192,7 +1192,7 @@ * @param string text to insert * @param offset offset in the existing data to insert "string" at. */ - void write(char[] string, int offset) { + void write(String string, int offset) { if (offset < 0 || offset > buffer.length()) { return; } @@ -1223,7 +1223,7 @@ * <li>ERROR_IO when the writer is closed.</li> * </ul> */ - public void writeLine(char[] line, int lineOffset) { + public void writeLine(String line, int lineOffset) { if (isClosed_) { DWT.error(DWT.ERROR_IO); } @@ -1250,7 +1250,7 @@ * <li>ERROR_IO when the writer is closed.</li> * </ul> */ - public void writeLineDelimiter(char[] lineDelimiter) { + public void writeLineDelimiter(String lineDelimiter) { if (isClosed_) { DWT.error(DWT.ERROR_IO); } @@ -1567,7 +1567,7 @@ * Appends a string to the text at the end of the widget. * * @param string the string to be appended - * @see #replaceTextRange(int,int,char[]) + * @see #replaceTextRange(int,int,String) * @exception DWTException <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> @@ -1576,7 +1576,7 @@ * <li>ERROR_NULL_ARGUMENT when listener is null</li> * </ul> */ -public void append(char[] string) { +public void append(String string) { checkWidget(); if (string is null) { DWT.error(DWT.ERROR_NULL_ARGUMENT); @@ -1891,7 +1891,7 @@ * specified by the model. Returns only the first line if the widget * has the DWT.SINGLE style. */ -char[] getModelDelimitedText(char[] text) { +String getModelDelimitedText(String text) { int length = text.length; if (length is 0) { return text; @@ -1900,7 +1900,7 @@ int lfIndex = 0; int i = 0; StringBuffer convertedText = new StringBuffer(length); - char[] delimiter = getLineDelimiter(); + String delimiter = getLineDelimiter(); while (i < length) { if (crIndex !is -1) { crIndex = tango.text.Util.locate( text, DWT.CR, i); @@ -2255,7 +2255,7 @@ // tab character (tabs are always inserted without overwriting)? int lineIndex = content.getLineAtOffset(event.end); int lineOffset = content.getOffsetAtLine(lineIndex); - char[] line = content.getLine(lineIndex); + String line = content.getLine(lineIndex); // replace character at caret offset if the caret is not at the // end of the line if (event.end < lineOffset + line.length) { @@ -3246,7 +3246,7 @@ } Rectangle getBoundsAtOffset(int offset) { int lineIndex = content.getLineAtOffset(offset); - char[] line = content.getLine(lineIndex); + String line = content.getLine(lineIndex); Rectangle bounds; if (line.length !is 0) { int offsetInLine = offset - content.getOffsetAtLine(lineIndex); @@ -3574,7 +3574,7 @@ * @param line line to get line background data for * @return line background data for the given line. */ -StyledTextEvent getLineBackgroundData(int lineOffset, char[] line) { +StyledTextEvent getLineBackgroundData(int lineOffset, String line) { return sendLineEvent(LineGetBackground, lineOffset, line); } /** @@ -3615,7 +3615,7 @@ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */ -public char[] getLineDelimiter() { +public String getLineDelimiter() { checkWidget(); return content.getLineDelimiter(); } @@ -3753,7 +3753,7 @@ * @return line style data for the given line. Styles may start before * line start and end after line end */ -StyledTextEvent getLineStyleData(int lineOffset, char[] line) { +StyledTextEvent getLineStyleData(int lineOffset, String line) { return sendLineEvent(LineGetStyle, lineOffset, line); } /** @@ -3915,7 +3915,7 @@ int x = point.x + horizontalScrollOffset - leftMargin ; int y = point.y - getLinePixel(lineIndex); int offsetInLine = layout.getOffset(x, y, trailing); - char[] line = content.getLine(lineIndex); + String line = content.getLine(lineIndex); if (offsetInLine !is line.length - 1) { offsetInLine = Math.min(line.length, offsetInLine + trailing[0]); } @@ -3953,7 +3953,7 @@ offsetInLine += trailing[0]; caretAlignment = PREVIOUS_OFFSET_TRAILING; } else { - char[] line = content.getLine(lineIndex); + String line = content.getLine(lineIndex); int level; int offset = offsetInLine; while (offset > 0 && tango.text.Unicode.isDigit(line[offset])) offset--; @@ -4023,11 +4023,11 @@ * @return the content in the specified range using the platform line * delimiter to separate lines as written by the specified TextWriter. */ -char[] getPlatformDelimitedText(TextWriter writer) { +String getPlatformDelimitedText(TextWriter writer) { int end = writer.getStart() + writer.getCharCount(); int startLine = content.getLineAtOffset(writer.getStart()); int endLine = content.getLineAtOffset(end); - char[] endLineText = content.getLine(endLine); + String endLineText = content.getLine(endLine); int endLineOffset = content.getOffsetAtLine(endLine); for (int i = startLine; i <= endLine; i++) { @@ -4216,7 +4216,7 @@ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */ -public char[] getSelectionText() { +public String getSelectionText() { checkWidget(); return content.getTextRange(selection.x, selection.y - selection.x); } @@ -4248,7 +4248,7 @@ * exceed the line length or have duplicates</li> * </ul> */ -int [] getBidiSegments(int lineOffset, char[] line) { +int [] getBidiSegments(int lineOffset, String line) { if (!isBidi()) return null; if (!isListening(LineGetSegments)) { return getBidiSegmentsCompatibility(line, lineOffset); @@ -4285,7 +4285,7 @@ * @see #getBidiSegments * Supports deprecated setBidiColoring API. Remove when API is removed. */ -int [] getBidiSegmentsCompatibility(char[] line, int lineOffset) { +int [] getBidiSegmentsCompatibility(String line, int lineOffset) { int lineLength = line.length; if (!bidiColoring) { return [0, lineLength]; @@ -4539,14 +4539,14 @@ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */ -public char[] getText() { +public String getText() { checkWidget(); return content.getTextRange(0, getCharCount()); } /** * Returns the widget content between the two offsets. * - * @param start offset of the first character in the returned char[] + * @param start offset of the first character in the returned String * @param end offset of the last character in the returned String * @return widget content starting at start and ending at end * @see #getTextRange(int,int) @@ -4558,7 +4558,7 @@ * <li>ERROR_INVALID_RANGE when start and/or end are outside the widget content</li> * </ul> */ -public char[] getText(int start, int end) { +public String getText(int start, int end) { checkWidget(); int contentLength = getCharCount(); if (start < 0 || start >= contentLength || end < 0 || end >= contentLength || start > end) { @@ -4600,7 +4600,7 @@ if (i is lineStart && i is lineEnd) { rect = layout.getBounds(start - lineOffset, end - lineOffset); } else if (i is lineStart) { - char[] line = content.getLine(i); + String line = content.getLine(i); rect = layout.getBounds(start - lineOffset, line.length); } else if (i is lineEnd) { rect = layout.getBounds(0, end - lineOffset); @@ -4633,7 +4633,7 @@ * <li>ERROR_INVALID_RANGE when start and/or length are outside the widget content</li> * </ul> */ -public char[] getTextRange(int start, int length) { +public String getTextRange(int start, int length) { checkWidget(); int contentLength = getCharCount(); int end = start + length; @@ -4730,7 +4730,7 @@ updateCaretDirection = false; int caretLine = getCaretLine(); int lineOffset = content.getOffsetAtLine(caretLine); - char[] line = content.getLine(caretLine); + String line = content.getLine(caretLine); int offset = caretOffset - lineOffset; int lineLength = line.length; if (lineLength is 0) return isMirrored() ? DWT.RIGHT : DWT.LEFT; @@ -4760,7 +4760,7 @@ } int getWordNext (int offset, int movement) { int newOffset, lineOffset; - char[] lineText; + String lineText; if (offset >= getCharCount()) { newOffset = offset; int lineIndex = content.getLineCount() - 1; @@ -4783,7 +4783,7 @@ } int getWordPrevious(int offset, int movement) { int newOffset, lineOffset; - char[] lineText; + String lineText; if (offset <= 0) { newOffset = 0; int lineIndex = content.getLineAtOffset(newOffset); @@ -4794,7 +4794,7 @@ lineOffset = content.getOffsetAtLine(lineIndex); lineText = content.getLine(lineIndex); if (offset is lineOffset) { - char[] nextLineText = content.getLine(lineIndex - 1); + String nextLineText = content.getLine(lineIndex - 1); int nextLineOffset = content.getOffsetAtLine(lineIndex - 1); newOffset = nextLineOffset + nextLineText.length; } else { @@ -4825,7 +4825,7 @@ */ Point getPointAtOffset(int offset) { int lineIndex = content.getLineAtOffset(offset); - char[] line = content.getLine(lineIndex); + String line = content.getLine(lineIndex); int lineOffset = content.getOffsetAtLine(lineIndex); int offsetInLine = offset - lineOffset; int lineLength = line.length; @@ -4867,7 +4867,7 @@ * Inserts a string. The old selection is replaced with the new text. * * @param string the string - * @see #replaceTextRange(int,int,char[]) + * @see #replaceTextRange(int,int,String) * @exception DWTException <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> @@ -4876,7 +4876,7 @@ * <li>ERROR_NULL_ARGUMENT when string is null</li> * </ul> */ -public void insert(char[] string) { +public void insert(String string) { checkWidget(); if (string is null) { DWT.error(DWT.ERROR_NULL_ARGUMENT); @@ -5210,7 +5210,7 @@ //paste clipboard selection if (event.button is 2) { auto o = cast(ArrayWrapperString)getClipboardContent(DND.SELECTION_CLIPBOARD); - char[] text = o.array; + String text = o.array; if (text !is null && text.length > 0) { // position cursor doMouseLocationChange(event.x, event.y, false); @@ -5526,7 +5526,7 @@ final Accessible accessible = getAccessible(); accessible.addAccessibleListener(new class() AccessibleAdapter { public void getName (AccessibleEvent e) { - char[] name = null; + String name = null; Label label = getAssociatedLabel (); if (label !is null) { name = stripMnemonic (label.getText()); @@ -5537,10 +5537,10 @@ e.result = getToolTipText(); } public void getKeyboardShortcut(AccessibleEvent e) { - char[] shortcut = null; + String shortcut = null; Label label = getAssociatedLabel (); if (label !is null) { - char[] text = label.getText (); + String text = label.getText (); if (text !is null) { dchar mnemonic = _findMnemonic (text); if (mnemonic !is '\0') { @@ -5600,7 +5600,7 @@ } return null; } -char[] stripMnemonic (char[] string) { +String stripMnemonic (String string) { int index = 0; int length_ = string.length; do { @@ -5618,7 +5618,7 @@ * an '&' character in the given string. If there are no '&' * characters in the given string, return '\0'. */ -dchar _findMnemonic (char[] string) { +dchar _findMnemonic (String string) { if (string is null) return '\0'; int index = 0; int length_ = string.length; @@ -5918,7 +5918,7 @@ */ public void paste(){ checkWidget(); - char[] text = (cast(ArrayWrapperString) getClipboardContent(DND.CLIPBOARD)).array; + String text = (cast(ArrayWrapperString) getClipboardContent(DND.CLIPBOARD)).array; if (text !is null && text.length > 0) { Event event = new Event(); event.start = selection.x; @@ -6395,7 +6395,7 @@ * <li>ERROR_NULL_ARGUMENT when string is null</li> * </ul> */ -public void replaceTextRange(int start, int length, char[] text) { +public void replaceTextRange(int start, int length, String text) { checkWidget(); if (text is null) { DWT.error(DWT.ERROR_NULL_ARGUMENT); @@ -6638,7 +6638,7 @@ * @return StyledTextEvent that can be used to request line data * for the given line. */ -StyledTextEvent sendLineEvent(int eventType, int lineOffset, char[] line) { +StyledTextEvent sendLineEvent(int eventType, int lineOffset, String line) { StyledTextEvent event = null; if (isListening(eventType)) { event = new StyledTextEvent(content); @@ -6675,7 +6675,7 @@ event.y = selection.y; notifyListeners(DWT.Selection, event); } -int sendWordBoundaryEvent(int eventType, int movement, int offset, int newOffset, char[] lineText, int lineOffset) { +int sendWordBoundaryEvent(int eventType, int movement, int offset, int newOffset, String lineText, int lineOffset) { if (isListening(eventType)) { StyledTextEvent event = new StyledTextEvent(content); event.detail = lineOffset; @@ -6874,7 +6874,7 @@ if (clipboardType is DND.SELECTION_CLIPBOARD && !(IS_MOTIF || IS_GTK)) return; TextTransfer plainTextTransfer = TextTransfer.getInstance(); TextWriter plainTextWriter = new TextWriter(start, length); - char[] plainText = getPlatformDelimitedText(plainTextWriter); + String plainText = getPlatformDelimitedText(plainTextWriter); Object[] data; Transfer[] types; if (clipboardType is DND.SELECTION_CLIPBOARD) { @@ -6883,7 +6883,7 @@ } else { RTFTransfer rtfTransfer = RTFTransfer.getInstance(); RTFWriter rtfWriter = new RTFWriter(start, length); - char[] rtfText = getPlatformDelimitedText(rtfWriter); + String rtfText = getPlatformDelimitedText(rtfWriter); data = [ cast(Object) new ArrayWrapperString(rtfText), new ArrayWrapperString(plainText) ]; types = [ cast(Transfer)rtfTransfer, plainTextTransfer]; } @@ -8034,7 +8034,7 @@ * <li>ERROR_NULL_ARGUMENT when string is null</li> * </ul> */ -public void setText(char[] text) { +public void setText(String text) { checkWidget(); if (text is null) { DWT.error(DWT.ERROR_NULL_ARGUMENT);