comparison org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet162.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 9f4c18c268b2
children
comparison
equal deleted inserted replaced
119:d00e8db0a568 120:536e43f63c81
38 import org.eclipse.swt.widgets.TableItem; 38 import org.eclipse.swt.widgets.TableItem;
39 39
40 import java.lang.all; 40 import java.lang.all;
41 41
42 42
43 void main(String[] args){ 43 const STATE = "CheckedIndices";
44 Snippet162.main(args);
45 }
46 44
47 public class Snippet162 { 45 void main () {
46 Display display = new Display ();
47 Image checkedImage = getCheckedImage (display);
48 Image uncheckedImage = getUncheckedImage (display);
49 Shell shell = new Shell (display);
50 shell.setLayout (new FillLayout ());
51 Table table = new Table (shell, SWT.BORDER);
52 TableColumn column1 = new TableColumn (table, SWT.NONE);
53 TableColumn column2 = new TableColumn (table, SWT.NONE);
54 TableColumn column3 = new TableColumn (table, SWT.NONE);
55 TableItem item1 = new TableItem (table, SWT.NONE);
56 item1.setText ( ["first item", "a", "b"]);
57 item1.setImage (1, uncheckedImage);
58 item1.setImage (2, uncheckedImage);
59 item1.setData (STATE, null);
60 TableItem item2 = new TableItem (table, SWT.NONE);
61 item2.setText ( ["second item", "c", "d"]);
62 item2.setImage (1, uncheckedImage);
63 item2.setImage (2, checkedImage);
64 item2.setData (STATE, new ArrayWrapperInt([2]));
65 TableItem item3 = new TableItem (table, SWT.NONE);
66 item3.setText ( ["third", "e", "f"]);
67 item3.setImage (1, checkedImage);
68 item3.setImage (2, checkedImage);
69 item3.setData (STATE, new ArrayWrapperInt( [1, 2]));
70 column1.pack ();
71 column2.pack ();
72 column3.pack ();
48 73
49 const static String STATE = "CheckedIndices"; 74 Accessible accessible = table.getAccessible ();
75 accessible.addAccessibleListener( new class AccessibleAdapter {
76 public void getName (AccessibleEvent e) {
77 super.getName (e);
78 if (e.childID >= 0 && e.childID < table.getItemCount ()) {
79 TableItem item = table.getItem (e.childID);
80 Point pt = display.getCursorLocation ();
81 pt = display.map (null, table, pt);
82 for (int i = 0; i < table.getColumnCount (); i++) {
83 if (item.getBounds (i).contains (pt)) {
84 int [] data = (cast(ArrayWrapperInt)item.getData (STATE)).array;
85 bool checked = false;
86 if (data !is null) {
87 for (int j = 0; j < data.length; j++) {
88 if (data [j] == i) {
89 checked = true;
90 break;
91 }
92 }
93 }
94 e.result = item.getText (i) ~ " " ~ (checked ? "checked" : "unchecked");
95 break;
96 }
97 }
98 }
99 }
100 });
50 101
51 public static void main (String [] args) { 102 accessible.addAccessibleControlListener (new class AccessibleControlAdapter {
52 Display display = new Display (); 103 public void getState (AccessibleControlEvent e) {
53 Image checkedImage = getCheckedImage (display); 104 super.getState (e);
54 Image uncheckedImage = getUncheckedImage (display); 105 if (e.childID >= 0 && e.childID < table.getItemCount ()) {
55 Shell shell = new Shell (display); 106 TableItem item = table.getItem (e.childID);
56 shell.setLayout (new FillLayout ()); 107 int [] data =(cast(ArrayWrapperInt)item.getData (STATE)).array;
57 Table table = new Table (shell, SWT.BORDER); 108 if (data !is null) {
58 TableColumn column1 = new TableColumn (table, SWT.NONE);
59 TableColumn column2 = new TableColumn (table, SWT.NONE);
60 TableColumn column3 = new TableColumn (table, SWT.NONE);
61 TableItem item1 = new TableItem (table, SWT.NONE);
62 item1.setText ( ["first item", "a", "b"]);
63 item1.setImage (1, uncheckedImage);
64 item1.setImage (2, uncheckedImage);
65 item1.setData (STATE, null);
66 TableItem item2 = new TableItem (table, SWT.NONE);
67 item2.setText ( ["second item", "c", "d"]);
68 item2.setImage (1, uncheckedImage);
69 item2.setImage (2, checkedImage);
70 item2.setData (STATE, new ArrayWrapperInt([2]));
71 TableItem item3 = new TableItem (table, SWT.NONE);
72 item3.setText ( ["third", "e", "f"]);
73 item3.setImage (1, checkedImage);
74 item3.setImage (2, checkedImage);
75 item3.setData (STATE, new ArrayWrapperInt( [1, 2]));
76 column1.pack ();
77 column2.pack ();
78 column3.pack ();
79
80 Accessible accessible = table.getAccessible ();
81 accessible.addAccessibleListener( new class() AccessibleAdapter {
82 public void getName (AccessibleEvent e) {
83 super.getName (e);
84 if (e.childID >= 0 && e.childID < table.getItemCount ()) {
85 TableItem item = table.getItem (e.childID);
86 Point pt = display.getCursorLocation (); 109 Point pt = display.getCursorLocation ();
87 pt = display.map (null, table, pt); 110 pt = display.map (null, table, pt);
88 for (int i = 0; i < table.getColumnCount (); i++) { 111 for (int i = 0; i < data.length; i++) {
89 if (item.getBounds (i).contains (pt)) { 112 if (item.getBounds (data [i]).contains (pt)) {
90 int [] data = (cast(ArrayWrapperInt)item.getData (STATE)).array; 113 e.detail |= ACC.STATE_CHECKED;
91 bool checked = false;
92 if (data !is null) {
93 for (int j = 0; j < data.length; j++) {
94 if (data [j] == i) {
95 checked = true;
96 break;
97 }
98 }
99 }
100 e.result = item.getText (i) ~ " " ~ (checked ? "checked" : "unchecked");
101 break; 114 break;
102 } 115 }
103 } 116 }
104 } 117 }
105 } 118 }
106 }); 119 }
120 });
121 shell.open ();
122 while (!shell.isDisposed ()) {
123 if (!display.readAndDispatch ()) display.sleep ();
124 }
125 checkedImage.dispose ();
126 uncheckedImage.dispose ();
127 display.dispose ();
128 }
107 129
108 accessible.addAccessibleControlListener (new class() AccessibleControlAdapter { 130 Image getCheckedImage (Display display) {
109 public void getState (AccessibleControlEvent e) { 131 Image image = new Image (display, 16, 16);
110 super.getState (e); 132 GC gc = new GC (image);
111 if (e.childID >= 0 && e.childID < table.getItemCount ()) { 133 gc.setBackground (display.getSystemColor (SWT.COLOR_YELLOW));
112 TableItem item = table.getItem (e.childID); 134 gc.fillOval (0, 0, 16, 16);
113 int [] data =(cast(ArrayWrapperInt)item.getData (STATE)).array; 135 gc.setForeground (display.getSystemColor (SWT.COLOR_DARK_GREEN));
114 if (data !is null) { 136 gc.drawLine (0, 0, 16, 16);
115 Point pt = display.getCursorLocation (); 137 gc.drawLine (16, 0, 0, 16);
116 pt = display.map (null, table, pt); 138 gc.dispose ();
117 for (int i = 0; i < data.length; i++) { 139 return image;
118 if (item.getBounds (data [i]).contains (pt)) { 140 }
119 e.detail |= ACC.STATE_CHECKED;
120 break;
121 }
122 }
123 }
124 }
125 }
126 });
127 shell.open ();
128 while (!shell.isDisposed ()) {
129 if (!display.readAndDispatch ()) display.sleep ();
130 }
131 checkedImage.dispose ();
132 uncheckedImage.dispose ();
133 display.dispose ();
134 }
135 141
136 static Image getCheckedImage (Display display) { 142 Image getUncheckedImage (Display display) {
137 Image image = new Image (display, 16, 16); 143 Image image = new Image (display, 16, 16);
138 GC gc = new GC (image); 144 GC gc = new GC (image);
139 gc.setBackground (display.getSystemColor (SWT.COLOR_YELLOW)); 145 gc.setBackground (display.getSystemColor (SWT.COLOR_YELLOW));
140 gc.fillOval (0, 0, 16, 16); 146 gc.fillOval (0, 0, 16, 16);
141 gc.setForeground (display.getSystemColor (SWT.COLOR_DARK_GREEN)); 147 gc.dispose ();
142 gc.drawLine (0, 0, 16, 16); 148 return image;
143 gc.drawLine (16, 0, 0, 16);
144 gc.dispose ();
145 return image;
146 }
147
148 static Image getUncheckedImage (Display display) {
149 Image image = new Image (display, 16, 16);
150 GC gc = new GC (image);
151 gc.setBackground (display.getSystemColor (SWT.COLOR_YELLOW));
152 gc.fillOval (0, 0, 16, 16);
153 gc.dispose ();
154 return image;
155 }
156 } 149 }