comparison dwt/custom/CTabItem.d @ 238:380bad9f6852

reverted char[] to String
author Frank Benoit <benoit@tionex.de>
date Mon, 05 May 2008 00:42:55 +0200
parents f2e04420fd6c
children ce446666f5a2
comparison
equal deleted inserted replaced
237:98b80b00af79 238:380bad9f6852
9 * IBM Corporation - initial API and implementation 9 * IBM Corporation - initial API and implementation
10 * Port to the D programming language: 10 * Port to the D programming language:
11 * Frank Benoit <benoit@tionex.de> 11 * Frank Benoit <benoit@tionex.de>
12 *******************************************************************************/ 12 *******************************************************************************/
13 module dwt.custom.CTabItem; 13 module dwt.custom.CTabItem;
14
15 import dwt.dwthelper.utils;
14 16
15 17
16 18
17 import dwt.DWT; 19 import dwt.DWT;
18 import dwt.DWTException; 20 import dwt.DWTException;
46 public class CTabItem : Item { 48 public class CTabItem : Item {
47 CTabFolder parent; 49 CTabFolder parent;
48 int x,y,width,height = 0; 50 int x,y,width,height = 0;
49 Control control; // the tab page 51 Control control; // the tab page
50 52
51 char[] toolTipText; 53 String toolTipText;
52 char[] shortenedText; 54 String shortenedText;
53 int shortenedTextWidth; 55 int shortenedTextWidth;
54 56
55 // Appearance 57 // Appearance
56 Font font; 58 Font font;
57 Image disabledImage; 59 Image disabledImage;
66 static final int BOTTOM_MARGIN = 2; 68 static final int BOTTOM_MARGIN = 2;
67 static final int LEFT_MARGIN = 4; 69 static final int LEFT_MARGIN = 4;
68 static final int RIGHT_MARGIN = 4; 70 static final int RIGHT_MARGIN = 4;
69 static final int INTERNAL_SPACING = 4; 71 static final int INTERNAL_SPACING = 4;
70 static final int FLAGS = DWT.DRAW_TRANSPARENT | DWT.DRAW_MNEMONIC; 72 static final int FLAGS = DWT.DRAW_TRANSPARENT | DWT.DRAW_MNEMONIC;
71 static final char[] ELLIPSIS = "..."; //$NON-NLS-1$ // could use the ellipsis glyph on some platforms "\u2026" 73 static final String ELLIPSIS = "..."; //$NON-NLS-1$ // could use the ellipsis glyph on some platforms "\u2026"
72 74
73 /** 75 /**
74 * Constructs a new instance of this class given its parent 76 * Constructs a new instance of this class given its parent
75 * (which must be a <code>CTabFolder</code>) and a style value 77 * (which must be a <code>CTabFolder</code>) and a style value
76 * describing its behavior and appearance. The item is added 78 * describing its behavior and appearance. The item is added
146 */ 148 */
147 bool useEllipses() { 149 bool useEllipses() {
148 return parent.simple; 150 return parent.simple;
149 } 151 }
150 152
151 char[] shortenText(GC gc, char[] text, int width) { 153 String shortenText(GC gc, String text, int width) {
152 return useEllipses() 154 return useEllipses()
153 ? shortenText(gc, text, width, ELLIPSIS) 155 ? shortenText(gc, text, width, ELLIPSIS)
154 : shortenText(gc, text, width, ""); //$NON-NLS-1$ 156 : shortenText(gc, text, width, ""); //$NON-NLS-1$
155 } 157 }
156 158
157 char[] shortenText(GC gc, char[] text, int width, char[] ellipses) { 159 String shortenText(GC gc, String text, int width, String ellipses) {
158 if (gc.textExtent(text, FLAGS).x <= width) return text; 160 if (gc.textExtent(text, FLAGS).x <= width) return text;
159 int ellipseWidth = gc.textExtent(ellipses, FLAGS).x; 161 int ellipseWidth = gc.textExtent(ellipses, FLAGS).x;
160 int length = text.length; 162 int length = text.length;
161 int end = length - 1; 163 int end = length - 1;
162 while (end > 0) { 164 while (end > 0) {
774 * @exception DWTException <ul> 776 * @exception DWTException <ul>
775 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> 777 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
776 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 778 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
777 * </ul> 779 * </ul>
778 */ 780 */
779 public char[] getToolTipText () { 781 public String getToolTipText () {
780 checkWidget(); 782 checkWidget();
781 if (toolTipText is null && shortenedText !is null) { 783 if (toolTipText is null && shortenedText !is null) {
782 char[] text = getText(); 784 String text = getText();
783 if (shortenedText!=text) return text; 785 if (shortenedText!=text) return text;
784 } 786 }
785 return toolTipText; 787 return toolTipText;
786 } 788 }
787 /** 789 /**
809 } 811 }
810 } 812 }
811 int preferredHeight(GC gc) { 813 int preferredHeight(GC gc) {
812 Image image = getImage(); 814 Image image = getImage();
813 int h = (image is null) ? 0 : image.getBounds().height; 815 int h = (image is null) ? 0 : image.getBounds().height;
814 char[] text = getText(); 816 String text = getText();
815 if (font is null) { 817 if (font is null) {
816 h = Math.max(h, gc.textExtent(text, FLAGS).y); 818 h = Math.max(h, gc.textExtent(text, FLAGS).y);
817 } else { 819 } else {
818 Font gcFont = gc.getFont(); 820 Font gcFont = gc.getFont();
819 gc.setFont(font); 821 gc.setFont(font);
829 int w = 0; 831 int w = 0;
830 Image image = getImage(); 832 Image image = getImage();
831 if (image !is null && (isSelected || parent.showUnselectedImage)) { 833 if (image !is null && (isSelected || parent.showUnselectedImage)) {
832 w += image.getBounds().width; 834 w += image.getBounds().width;
833 } 835 }
834 char[] text = null; 836 String text = null;
835 if (minimum) { 837 if (minimum) {
836 int minChars = parent.minChars; 838 int minChars = parent.minChars;
837 text = minChars is 0 ? null : getText(); 839 text = minChars is 0 ? null : getText();
838 if (text !is null && text.length > minChars) { 840 if (text !is null && text.length > minChars) {
839 if (useEllipses()) { 841 if (useEllipses()) {
994 } 996 }
995 parent.updateItems(); 997 parent.updateItems();
996 parent.redrawTabs(); 998 parent.redrawTabs();
997 } 999 }
998 } 1000 }
999 public override void setText (char[] string) { 1001 public override void setText (String string) {
1000 checkWidget(); 1002 checkWidget();
1001 if (string is null) DWT.error (DWT.ERROR_NULL_ARGUMENT); 1003 if (string is null) DWT.error (DWT.ERROR_NULL_ARGUMENT);
1002 if (string==getText()) return; 1004 if (string==getText()) return;
1003 super.setText(string); 1005 super.setText(string);
1004 shortenedText = null; 1006 shortenedText = null;
1017 * @exception DWTException <ul> 1019 * @exception DWTException <ul>
1018 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> 1020 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
1019 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 1021 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1020 * </ul> 1022 * </ul>
1021 */ 1023 */
1022 public void setToolTipText (char[] string) { 1024 public void setToolTipText (String string) {
1023 checkWidget(); 1025 checkWidget();
1024 toolTipText = string; 1026 toolTipText = string;
1025 } 1027 }
1026 } 1028 }