Mercurial > projects > dwt-win
comparison dwt/custom/StyledTextRenderer.d @ 213:36f5cb12e1a2
Update to SWT 3.4M7
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 17 May 2008 17:34:28 +0200 |
parents | ab60f3309436 |
children | fd9c62a2998e |
comparison
equal
deleted
inserted
replaced
212:ab60f3309436 | 213:36f5cb12e1a2 |
---|---|
25 import dwt.graphics.Point; | 25 import dwt.graphics.Point; |
26 import dwt.graphics.Rectangle; | 26 import dwt.graphics.Rectangle; |
27 import dwt.graphics.TextLayout; | 27 import dwt.graphics.TextLayout; |
28 import dwt.graphics.TextStyle; | 28 import dwt.graphics.TextStyle; |
29 import dwt.widgets.Display; | 29 import dwt.widgets.Display; |
30 import dwt.widgets.IME; | |
30 import dwt.widgets.ScrollBar; | 31 import dwt.widgets.ScrollBar; |
31 import dwt.custom.StyledText; | 32 import dwt.custom.StyledText; |
32 import dwt.custom.Bullet; | 33 import dwt.custom.Bullet; |
33 import dwt.custom.StyleRange; | 34 import dwt.custom.StyleRange; |
34 import dwt.custom.StyledText; | 35 import dwt.custom.StyledText; |
389 int lineLength = line.length; | 390 int lineLength = line.length; |
390 Point selection = styledText.getSelection(); | 391 Point selection = styledText.getSelection(); |
391 int selectionStart = selection.x - lineOffset; | 392 int selectionStart = selection.x - lineOffset; |
392 int selectionEnd = selection.y - lineOffset; | 393 int selectionEnd = selection.y - lineOffset; |
393 Rectangle client = styledText.getClientArea(); | 394 Rectangle client = styledText.getClientArea(); |
394 Color lineBackground = getLineBackground(lineIndex, widgetBackground); | 395 Color lineBackground = getLineBackground(lineIndex, null); |
395 StyledTextEvent event = styledText.getLineBackgroundData(lineOffset, line); | 396 StyledTextEvent event = styledText.getLineBackgroundData(lineOffset, line); |
396 if (event !is null && event.lineBackground !is null) lineBackground = event.lineBackground; | 397 if (event !is null && event.lineBackground !is null) lineBackground = event.lineBackground; |
397 | |
398 int height = layout.getBounds().height; | 398 int height = layout.getBounds().height; |
399 gc.setBackground(lineBackground); | 399 if (lineBackground !is null) { |
400 styledText.drawBackground(gc, client.x, paintY, client.width, height); | 400 gc.setBackground(lineBackground); |
401 | 401 gc.fillRectangle(client.x, paintY, client.width, height); |
402 } else { | |
403 gc.setBackground(widgetBackground); | |
404 styledText.drawBackground(gc, client.x, paintY, client.width, height); | |
405 } | |
402 gc.setForeground(widgetForeground); | 406 gc.setForeground(widgetForeground); |
403 gc.setBackground(lineBackground); | |
404 if (selectionStart is selectionEnd || (selectionEnd <= 0 && selectionStart > lineLength - 1)) { | 407 if (selectionStart is selectionEnd || (selectionEnd <= 0 && selectionStart > lineLength - 1)) { |
405 layout.draw(gc, paintX, paintY); | 408 layout.draw(gc, paintX, paintY); |
406 } else { | 409 } else { |
407 int start = Math.max(0, selectionStart); | 410 int start = Math.max(0, selectionStart); |
408 int end = Math.min(lineLength, selectionEnd); | 411 int end = Math.min(lineLength, selectionEnd); |
661 style.length = style.start + style.length - start; | 664 style.length = style.start + style.length - start; |
662 style.start = start; | 665 style.start = start; |
663 } | 666 } |
664 style = newStyles[newStyles.length - 1]; | 667 style = newStyles[newStyles.length - 1]; |
665 if (end < style.start + style.length - 1) { | 668 if (end < style.start + style.length - 1) { |
666 if (!includeRanges || ranges is null) newStyles[newStyles.length - 1] = style = cast(StyleRange)style.clone(); | 669 if (end < style.start) { |
667 style.length = end - style.start + 1; | 670 StyleRange[] tmp = new StyleRange[newStyles.length - 1]; |
671 System.arraycopy(newStyles, 0, tmp, 0, newStyles.length - 1); | |
672 newStyles = tmp; | |
673 } else { | |
674 if (!includeRanges || ranges is null) newStyles[newStyles.length - 1] = style = cast(StyleRange)style.clone(); | |
675 style.length = end - style.start + 1; | |
676 } | |
668 } | 677 } |
669 return newStyles; | 678 return newStyles; |
670 } | 679 } |
671 StyleRange getStyleRange(StyleRange style) { | 680 StyleRange getStyleRange(StyleRange style) { |
672 if (style.start is 0 && style.length is 0 && style.fontStyle is DWT.NORMAL) return style; | 681 if (style.start is 0 && style.length is 0 && style.fontStyle is DWT.NORMAL) return style; |
866 lastOffset = Math.max(lastOffset, end); | 875 lastOffset = Math.max(lastOffset, end); |
867 } | 876 } |
868 } | 877 } |
869 } | 878 } |
870 if (lastOffset < length) layout.setStyle(null, lastOffset, length); | 879 if (lastOffset < length) layout.setStyle(null, lastOffset, length); |
880 if (styledText !is null && styledText.ime !is null) { | |
881 IME ime = styledText.ime; | |
882 int compositionOffset = ime.getCompositionOffset(); | |
883 if (compositionOffset !is -1) { | |
884 int commitCount = ime.getCommitCount(); | |
885 int compositionLength = ime.getText().length; | |
886 if (compositionLength !is commitCount) { | |
887 int compositionLine = content.getLineAtOffset(compositionOffset); | |
888 if (compositionLine is lineIndex) { | |
889 int[] imeRanges = ime.getRanges(); | |
890 TextStyle[] imeStyles = ime.getStyles(); | |
891 if (imeRanges.length > 0) { | |
892 for (int i = 0; i < imeStyles.length; i++) { | |
893 int start = imeRanges[i*2] - lineOffset; | |
894 int end = imeRanges[i*2+1] - lineOffset; | |
895 TextStyle imeStyle = imeStyles[i], userStyle; | |
896 for (int j = start; j <= end; j++) { | |
897 userStyle = layout.getStyle(j); | |
898 if (userStyle is null && j > 0) userStyle = layout.getStyle(j - 1); | |
899 if (userStyle is null && j + 1 < length) userStyle = layout.getStyle(j + 1); | |
900 if (userStyle is null) { | |
901 layout.setStyle(imeStyle, j, j); | |
902 } else { | |
903 TextStyle newStyle = new TextStyle(imeStyle); | |
904 if (newStyle.font is null) newStyle.font = userStyle.font; | |
905 if (newStyle.foreground is null) newStyle.foreground = userStyle.foreground; | |
906 if (newStyle.background is null) newStyle.background = userStyle.background; | |
907 layout.setStyle(newStyle, j, j); | |
908 } | |
909 } | |
910 } | |
911 } else { | |
912 int start = compositionOffset - lineOffset; | |
913 int end = start + compositionLength - 1; | |
914 TextStyle userStyle = layout.getStyle(start); | |
915 if (userStyle is null) { | |
916 if (start > 0) userStyle = layout.getStyle(start - 1); | |
917 if (userStyle is null && end + 1 < length) userStyle = layout.getStyle(end + 1); | |
918 if (userStyle !is null) { | |
919 TextStyle newStyle = new TextStyle(); | |
920 newStyle.font = userStyle.font; | |
921 newStyle.foreground = userStyle.foreground; | |
922 newStyle.background = userStyle.background; | |
923 layout.setStyle(newStyle, start, end); | |
924 } | |
925 } | |
926 } | |
927 } | |
928 } | |
929 } | |
930 } | |
931 | |
871 if (styledText !is null && styledText.isFixedLineHeight()) { | 932 if (styledText !is null && styledText.isFixedLineHeight()) { |
872 int index = -1; | 933 int index = -1; |
873 int lineCount = layout.getLineCount(); | 934 int lineCount = layout.getLineCount(); |
874 int height = getLineHeight(); | 935 int height = getLineHeight(); |
875 for (int i = 0; i < lineCount; i++) { | 936 for (int i = 0; i < lineCount; i++) { |