Mercurial > projects > dwt-win
comparison dwt/custom/CTabItem.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 | a5afe31f5cdd |
children | 36f5cb12e1a2 |
comparison
equal
deleted
inserted
replaced
211:ff59aeb96cac | 212:ab60f3309436 |
---|---|
26 import dwt.widgets.Control; | 26 import dwt.widgets.Control; |
27 import dwt.widgets.Display; | 27 import dwt.widgets.Display; |
28 import dwt.widgets.Item; | 28 import dwt.widgets.Item; |
29 import dwt.widgets.Widget; | 29 import dwt.widgets.Widget; |
30 import dwt.custom.CTabFolder; | 30 import dwt.custom.CTabFolder; |
31 import dwt.dwthelper.utils; | |
31 | 32 |
32 /** | 33 /** |
33 * Instances of this class represent a selectable user interface object | 34 * Instances of this class represent a selectable user interface object |
34 * that represent a page in a notebook widget. | 35 * that represent a page in a notebook widget. |
35 * | 36 * |
46 public class CTabItem : Item { | 47 public class CTabItem : Item { |
47 CTabFolder parent; | 48 CTabFolder parent; |
48 int x,y,width,height = 0; | 49 int x,y,width,height = 0; |
49 Control control; // the tab page | 50 Control control; // the tab page |
50 | 51 |
51 char[] toolTipText; | 52 String toolTipText; |
52 char[] shortenedText; | 53 String shortenedText; |
53 int shortenedTextWidth; | 54 int shortenedTextWidth; |
54 | 55 |
55 // Appearance | 56 // Appearance |
56 Font font; | 57 Font font; |
57 Image disabledImage; | 58 Image disabledImage; |
66 static final int BOTTOM_MARGIN = 2; | 67 static final int BOTTOM_MARGIN = 2; |
67 static final int LEFT_MARGIN = 4; | 68 static final int LEFT_MARGIN = 4; |
68 static final int RIGHT_MARGIN = 4; | 69 static final int RIGHT_MARGIN = 4; |
69 static final int INTERNAL_SPACING = 4; | 70 static final int INTERNAL_SPACING = 4; |
70 static final int FLAGS = DWT.DRAW_TRANSPARENT | DWT.DRAW_MNEMONIC; | 71 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" | 72 static final String ELLIPSIS = "..."; //$NON-NLS-1$ // could use the ellipsis glyph on some platforms "\u2026" |
72 | 73 |
73 /** | 74 /** |
74 * Constructs a new instance of this class given its parent | 75 * Constructs a new instance of this class given its parent |
75 * (which must be a <code>CTabFolder</code>) and a style value | 76 * (which must be a <code>CTabFolder</code>) and a style value |
76 * describing its behavior and appearance. The item is added | 77 * describing its behavior and appearance. The item is added |
146 */ | 147 */ |
147 bool useEllipses() { | 148 bool useEllipses() { |
148 return parent.simple; | 149 return parent.simple; |
149 } | 150 } |
150 | 151 |
151 char[] shortenText(GC gc, char[] text, int width) { | 152 String shortenText(GC gc, String text, int width) { |
152 return useEllipses() | 153 return useEllipses() |
153 ? shortenText(gc, text, width, ELLIPSIS) | 154 ? shortenText(gc, text, width, ELLIPSIS) |
154 : shortenText(gc, text, width, ""); //$NON-NLS-1$ | 155 : shortenText(gc, text, width, ""); //$NON-NLS-1$ |
155 } | 156 } |
156 | 157 |
157 char[] shortenText(GC gc, char[] text, int width, char[] ellipses) { | 158 String shortenText(GC gc, String text, int width, String ellipses) { |
158 if (gc.textExtent(text, FLAGS).x <= width) return text; | 159 if (gc.textExtent(text, FLAGS).x <= width) return text; |
159 int ellipseWidth = gc.textExtent(ellipses, FLAGS).x; | 160 int ellipseWidth = gc.textExtent(ellipses, FLAGS).x; |
160 int length = text.length; | 161 int length = text.length; |
161 int end = length - 1; | 162 int end = length - 1; |
162 while (end > 0) { | 163 while (end > 0) { |
774 * @exception DWTException <ul> | 775 * @exception DWTException <ul> |
775 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | 776 * <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> | 777 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
777 * </ul> | 778 * </ul> |
778 */ | 779 */ |
779 public char[] getToolTipText () { | 780 public String getToolTipText () { |
780 checkWidget(); | 781 checkWidget(); |
781 if (toolTipText is null && shortenedText !is null) { | 782 if (toolTipText is null && shortenedText !is null) { |
782 char[] text = getText(); | 783 String text = getText(); |
783 if (shortenedText!=text) return text; | 784 if (shortenedText!=text) return text; |
784 } | 785 } |
785 return toolTipText; | 786 return toolTipText; |
786 } | 787 } |
787 /** | 788 /** |
809 } | 810 } |
810 } | 811 } |
811 int preferredHeight(GC gc) { | 812 int preferredHeight(GC gc) { |
812 Image image = getImage(); | 813 Image image = getImage(); |
813 int h = (image is null) ? 0 : image.getBounds().height; | 814 int h = (image is null) ? 0 : image.getBounds().height; |
814 char[] text = getText(); | 815 String text = getText(); |
815 if (font is null) { | 816 if (font is null) { |
816 h = Math.max(h, gc.textExtent(text, FLAGS).y); | 817 h = Math.max(h, gc.textExtent(text, FLAGS).y); |
817 } else { | 818 } else { |
818 Font gcFont = gc.getFont(); | 819 Font gcFont = gc.getFont(); |
819 gc.setFont(font); | 820 gc.setFont(font); |
829 int w = 0; | 830 int w = 0; |
830 Image image = getImage(); | 831 Image image = getImage(); |
831 if (image !is null && (isSelected || parent.showUnselectedImage)) { | 832 if (image !is null && (isSelected || parent.showUnselectedImage)) { |
832 w += image.getBounds().width; | 833 w += image.getBounds().width; |
833 } | 834 } |
834 char[] text = null; | 835 String text = null; |
835 if (minimum) { | 836 if (minimum) { |
836 int minChars = parent.minChars; | 837 int minChars = parent.minChars; |
837 text = minChars is 0 ? null : getText(); | 838 text = minChars is 0 ? null : getText(); |
838 if (text !is null && text.length > minChars) { | 839 if (text !is null && text.length > minChars) { |
839 if (useEllipses()) { | 840 if (useEllipses()) { |
994 } | 995 } |
995 parent.updateItems(); | 996 parent.updateItems(); |
996 parent.redrawTabs(); | 997 parent.redrawTabs(); |
997 } | 998 } |
998 } | 999 } |
999 public override void setText (char[] string) { | 1000 public override void setText (String string) { |
1000 checkWidget(); | 1001 checkWidget(); |
1001 if (string is null) DWT.error (DWT.ERROR_NULL_ARGUMENT); | 1002 if (string is null) DWT.error (DWT.ERROR_NULL_ARGUMENT); |
1002 if (string==getText()) return; | 1003 if (string==getText()) return; |
1003 super.setText(string); | 1004 super.setText(string); |
1004 shortenedText = null; | 1005 shortenedText = null; |
1017 * @exception DWTException <ul> | 1018 * @exception DWTException <ul> |
1018 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | 1019 * <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> | 1020 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
1020 * </ul> | 1021 * </ul> |
1021 */ | 1022 */ |
1022 public void setToolTipText (char[] string) { | 1023 public void setToolTipText (String string) { |
1023 checkWidget(); | 1024 checkWidget(); |
1024 toolTipText = string; | 1025 toolTipText = string; |
1025 } | 1026 } |
1026 } | 1027 } |