comparison org.eclipse.swt.gtk.linux.x86/src/org/eclipse/swt/custom/StyledTextRenderer.d @ 120:536e43f63c81

Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661 ===D2=== * added [Try]Immutable/Const/Shared templates to work with differenses in D1/D2 instead of version statements used these templates to work with strict type storage rules of dmd-2.053 * com.ibm.icu now also compilable with D2, but not tested yet * small fixes Snippet288 - shared data is in TLS ===Phobos=== * fixed critical bugs in Phobos implemention completely incorrect segfault prone fromStringz (Linux's port ruthless killer) terrible, incorrect StringBuffer realization (StyledText killer) * fixed small bugs as well Snippet72 - misprint in the snippet * implemented missed functionality for Phobos ByteArrayOutputStream implemented (image loading available) formatting correctly works for all DWT's cases As a result, folowing snippets now works with Phobos (Snippet### - what is fixed): Snippet24, 42, 111, 115, 130, 235, 276 - bad string formatting Snippet48, 282 - crash on image loading Snippet163, 189, 211, 213, 217, 218, 222 - crash on copy/cut in StyledText Snippet244 - hang-up ===Tango=== * few changes for the latest Tango trunc-r5661 * few small performance improvments ===General=== * implMissing-s for only one version changed to implMissingInTango/InPhobos * incorrect calls to Format in toString-s fixed * fixed loading \uXXXX characters in ResourceBundle * added good UTF-8 support for StyledText, TextLayout (Win32) and friends UTF functions revised and tested. It is now in java.nonstandard.*Utf modules StyledText and TextLayout (Win32) modules revised for UTF-8 support * removed small diferences in most identical files in *.swt.* folders *.swt.internal.image, *.swt.events and *.swt.custom are identical in Win32/Linux32 now 179 of 576 (~31%) files in *.swt.* folders are fully identical * Win32: snippets now have right subsystem, pretty icons and native system style controls * small fixes in snippets Snippet44 - it's not Snippet44 Snippet212 - functions work with different images and offsets arrays Win32: Snippet282 - crash on close if the button has an image Snippet293 - setGrayed is commented and others Win32: As a result, folowing snippets now works Snippet68 - color doesn't change Snippet163, 189, 211, 213, 217, 218, 222 - UTF-8 issues (see above) Snippet193 - no tabel headers
author Denis Shelomovskij <verylonglogin.reg@gmail.com>
date Sat, 09 Jul 2011 15:50:20 +0300
parents c01d033c633a
children
comparison
equal deleted inserted replaced
119:d00e8db0a568 120:536e43f63c81
37 import org.eclipse.swt.custom.TextChangingEvent; 37 import org.eclipse.swt.custom.TextChangingEvent;
38 import org.eclipse.swt.custom.ST; 38 import org.eclipse.swt.custom.ST;
39 import org.eclipse.swt.custom.StyledTextEvent; 39 import org.eclipse.swt.custom.StyledTextEvent;
40 40
41 import java.lang.all; 41 import java.lang.all;
42 42 import java.nonstandard.UnsafeUtf;
43 version(Tango){
44 static import tango.text.Util;
45 static import tango.text.convert.Utf;
46 import tango.util.Convert;
47 } else { // Phobos
48 import std.conv;
49 }
50 43
51 /** 44 /**
52 * A StyledTextRenderer renders the content of a StyledText widget. 45 * A StyledTextRenderer renders the content of a StyledText widget.
53 * This class can be used to render to the display or to a printer. 46 * This class can be used to render to the display or to a printer.
54 */ 47 */
363 if (font !is null) gc.setFont(font); 356 if (font !is null) gc.setFont(font);
364 String string = ""; 357 String string = "";
365 int type = bullet.type & (ST.BULLET_DOT|ST.BULLET_NUMBER|ST.BULLET_LETTER_LOWER|ST.BULLET_LETTER_UPPER); 358 int type = bullet.type & (ST.BULLET_DOT|ST.BULLET_NUMBER|ST.BULLET_LETTER_LOWER|ST.BULLET_LETTER_UPPER);
366 switch (type) { 359 switch (type) {
367 case ST.BULLET_DOT: string = "\u2022"; break; 360 case ST.BULLET_DOT: string = "\u2022"; break;
368 case ST.BULLET_NUMBER: string = to!(String)(index); break; 361 case ST.BULLET_NUMBER: string = String_valueOf(index); break;
369 case ST.BULLET_LETTER_LOWER: string = [cast(char) (index % 26 + 97)]; break; 362 case ST.BULLET_LETTER_LOWER: string = [cast(char) (index % 26 + 97)]; break;
370 case ST.BULLET_LETTER_UPPER: string = [cast(char) (index % 26 + 65)]; break; 363 case ST.BULLET_LETTER_UPPER: string = [cast(char) (index % 26 + 65)]; break;
371 default: 364 default:
372 } 365 }
373 if ((bullet.type & ST.BULLET_TEXT) !is 0) string ~= bullet.text; 366 if ((bullet.type & ST.BULLET_TEXT) !is 0) string ~= bullet.text;
404 } else { 397 } else {
405 gc.setBackground(widgetBackground); 398 gc.setBackground(widgetBackground);
406 styledText.drawBackground(gc, client.x, paintY, client.width, height); 399 styledText.drawBackground(gc, client.x, paintY, client.width, height);
407 } 400 }
408 gc.setForeground(widgetForeground); 401 gc.setForeground(widgetForeground);
409 if (selectionStart is selectionEnd || (selectionEnd <= 0 && selectionStart > lineLength - 1)) { 402 if (selectionStart is selectionEnd || (selectionEnd <= 0 && selectionStart >= lineLength)) {
410 layout.draw(gc, paintX, paintY); 403 layout.draw(gc, paintX, paintY);
411 } else { 404 } else {
412 int start = Math.max(0, selectionStart); 405 int start = Math.max(0, selectionStart);
413 int end = Math.min(lineLength, selectionEnd); 406 int end = Math.min(lineLength, selectionEnd);
414 Color selectionFg = styledText.getSelectionForeground(); 407 Color selectionFg = styledText.getSelectionForeground();
420 flags = SWT.DELIMITER_SELECTION; 413 flags = SWT.DELIMITER_SELECTION;
421 } 414 }
422 if (selectionStart <= lineLength && lineLength < selectionEnd ) { 415 if (selectionStart <= lineLength && lineLength < selectionEnd ) {
423 flags |= SWT.LAST_LINE_SELECTION; 416 flags |= SWT.LAST_LINE_SELECTION;
424 } 417 }
425 layout.draw(gc, paintX, paintY, start, end - 1, selectionFg, selectionBg, flags); 418 layout.draw(gc, paintX, paintY, start, end > 0 ? line.offsetBefore(end) : end - 1, selectionFg, selectionBg, flags);
426 } 419 }
427 420
428 // draw objects 421 // draw objects
429 Bullet bullet = null; 422 Bullet bullet = null;
430 int bulletIndex = -1; 423 int bulletIndex = -1;
601 } 594 }
602 return high; 595 return high;
603 } 596 }
604 int[] getRanges(int start, int length) { 597 int[] getRanges(int start, int length) {
605 int[] newRanges; 598 int[] newRanges;
606 int end = start + length - 1; 599 int end = start + length - 1; //not a valid index, but OK
607 if (ranges !is null) { 600 if (ranges !is null) {
608 int rangeCount = styleCount << 1; 601 int rangeCount = styleCount << 1;
609 int rangeStart = getRangeIndex(start, -1, rangeCount); 602 int rangeStart = getRangeIndex(start, -1, rangeCount);
610 if (rangeStart >= rangeCount) return null; 603 if (rangeStart >= rangeCount) return null;
611 if (ranges[rangeStart] > end) return null; 604 if (ranges[rangeStart] > end) return null;
633 } 626 }
634 return newRanges; 627 return newRanges;
635 } 628 }
636 StyleRange[] getStyleRanges(int start, int length, bool includeRanges) { 629 StyleRange[] getStyleRanges(int start, int length, bool includeRanges) {
637 StyleRange[] newStyles; 630 StyleRange[] newStyles;
638 int end = start + length - 1; 631 int end = start + length - 1; //not a valid index, but OK
639 if (ranges !is null) { 632 if (ranges !is null) {
640 int rangeCount = styleCount << 1; 633 int rangeCount = styleCount << 1;
641 int rangeStart = getRangeIndex(start, -1, rangeCount); 634 int rangeStart = getRangeIndex(start, -1, rangeCount);
642 if (rangeStart >= rangeCount) return null; 635 if (rangeStart >= rangeCount) return null;
643 if (ranges[rangeStart] > end) return null; 636 if (ranges[rangeStart] > end) return null;
852 start = ranges[i] - lineOffset; 845 start = ranges[i] - lineOffset;
853 end = Math.min(length, start + ranges[i + 1]); 846 end = Math.min(length, start + ranges[i + 1]);
854 } 847 }
855 if (start >= length) break; 848 if (start >= length) break;
856 if (lastOffset < start) { 849 if (lastOffset < start) {
857 layout.setStyle(null, lastOffset, start - 1); 850 layout.setStyle(null, lastOffset, line.offsetBefore(start));
858 } 851 }
859 layout.setStyle(getStyleRange(styles[i >> 1]), start, end); 852 layout.setStyle(getStyleRange(styles[i >> 1]), start, end);
860 lastOffset = Math.max(lastOffset, end); 853 lastOffset = Math.max(lastOffset, end);
861 } 854 }
862 } else { 855 } else {
869 start = styles[i].start - lineOffset; 862 start = styles[i].start - lineOffset;
870 end = Math.min(length, start + styles[i].length); 863 end = Math.min(length, start + styles[i].length);
871 } 864 }
872 if (start >= length) break; 865 if (start >= length) break;
873 if (lastOffset < start) { 866 if (lastOffset < start) {
874 layout.setStyle(null, lastOffset, start - 1); 867 layout.setStyle(null, lastOffset, line.offsetBefore(start));
875 } 868 }
876 layout.setStyle(getStyleRange(styles[i]), start, end); 869 layout.setStyle(getStyleRange(styles[i]), start, end);
877 lastOffset = Math.max(lastOffset, end); 870 lastOffset = Math.max(lastOffset, end);
878 } 871 }
879 } 872 }
910 } 903 }
911 } 904 }
912 } 905 }
913 } else { 906 } else {
914 int start = compositionOffset - lineOffset; 907 int start = compositionOffset - lineOffset;
915 int end = start + compositionLength - 1; 908 int end = line.offsetBefore(start + compositionLength);
916 TextStyle userStyle = layout.getStyle(start); 909 TextStyle userStyle = layout.getStyle(start);
917 if (userStyle is null) { 910 if (userStyle is null) {
918 if (start > 0) userStyle = layout.getStyle(start - 1); 911 if (start > 0) userStyle = layout.getStyle(line.offsetBefore(start));
919 if (userStyle is null && end + 1 < length) userStyle = layout.getStyle(end + 1); 912 if (userStyle is null && line.offsetAfter(end) < length) userStyle = layout.getStyle(line.offsetAfter(end));
920 if (userStyle !is null) { 913 if (userStyle !is null) {
921 TextStyle newStyle = new TextStyle(); 914 TextStyle newStyle = new TextStyle();
922 newStyle.font = userStyle.font; 915 newStyle.font = userStyle.font;
923 newStyle.foreground = userStyle.foreground; 916 newStyle.foreground = userStyle.foreground;
924 newStyle.background = userStyle.background; 917 newStyle.background = userStyle.background;