Mercurial > projects > dwt-win
annotate dwt/custom/TableTree.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 | a59d51c12b42 |
rev | line source |
---|---|
155 | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 2007 IBM Corporation and others. | |
3 * All rights reserved. This program and the accompanying materials | |
4 * are made available under the terms of the Eclipse Public License v1.0 | |
5 * which accompanies this distribution, and is available at | |
6 * http://www.eclipse.org/legal/epl-v10.html | |
7 * | |
8 * Contributors: | |
9 * IBM Corporation - initial API and implementation | |
10 * Port to the D programming language: | |
11 * Frank Benoit <benoit@tionex.de> | |
12 *******************************************************************************/ | |
13 module dwt.custom.TableTree; | |
14 | |
15 | |
16 | |
17 import dwt.DWT; | |
18 import dwt.DWTException; | |
19 import dwt.events.SelectionEvent; | |
20 import dwt.events.SelectionListener; | |
21 import dwt.events.TreeListener; | |
22 import dwt.graphics.Color; | |
23 import dwt.graphics.Font; | |
24 import dwt.graphics.GC; | |
25 import dwt.graphics.Image; | |
26 import dwt.graphics.ImageData; | |
27 import dwt.graphics.PaletteData; | |
28 import dwt.graphics.Point; | |
29 import dwt.graphics.RGB; | |
30 import dwt.graphics.Rectangle; | |
31 import dwt.widgets.Composite; | |
32 import dwt.widgets.Event; | |
33 import dwt.widgets.Listener; | |
34 import dwt.widgets.Menu; | |
35 import dwt.widgets.Table; | |
36 import dwt.widgets.TableItem; | |
37 import dwt.widgets.TypedListener; | |
38 import dwt.custom.TableTreeItem; | |
39 | |
40 import dwt.dwthelper.utils; | |
41 | |
42 /** | |
43 * A TableTree is a selectable user interface object | |
44 * that displays a hierarchy of items, and issues | |
45 * notification when an item is selected. | |
46 * A TableTree may be single or multi select. | |
47 * <p> | |
48 * The item children that may be added to instances of this class | |
49 * must be of type <code>TableTreeItem</code>. | |
50 * </p><p> | |
51 * Note that although this class is a subclass of <code>Composite</code>, | |
52 * it does not make sense to add <code>Control</code> children to it, | |
53 * or set a layout on it. | |
54 * </p><p> | |
55 * <dl> | |
56 * <dt><b>Styles:</b> <dd> SINGLE, MULTI, CHECK, FULL_SELECTION | |
57 * <dt><b>Events:</b> <dd> Selection, DefaultSelection, Collapse, Expand | |
58 * </dl> | |
59 * <p> | |
60 * Note: Only one of the styles SINGLE, and MULTI may be specified. | |
61 * </p> | |
62 * | |
63 * @deprecated As of 3.1 use Tree, TreeItem and TreeColumn | |
64 */ | |
65 public class TableTree : Composite { | |
66 | |
67 alias Composite.computeSize computeSize; | |
68 | |
69 Table table; | |
70 TableTreeItem[] items; | |
71 Image plusImage, minusImage, sizeImage; | |
72 | |
73 /* | |
74 * TableTreeItems are not treated as children but rather as items. | |
75 * When the TableTree is disposed, all children are disposed because | |
76 * TableTree inherits this behaviour from Composite. The items | |
77 * must be disposed separately. Because TableTree is not part of | |
78 * the org.eclipse.swt.widgets module, the method releaseWidget can | |
79 * not be overridden (this is how items are disposed of in Table and Tree). | |
80 * Instead, the items are disposed of in response to the dispose event on the | |
81 * TableTree. The "inDispose" flag is used to distinguish between disposing | |
82 * one TableTreeItem (e.g. when removing an entry from the TableTree) and | |
83 * disposing the entire TableTree. | |
84 */ | |
85 bool inDispose = false; | |
86 | |
87 static final TableTreeItem[] EMPTY_ITEMS; | |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
155
diff
changeset
|
88 static final String[] EMPTY_TEXTS; |
155 | 89 static final Image[] EMPTY_IMAGES; |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
155
diff
changeset
|
90 static final String ITEMID = "TableTreeItemID"; //$NON-NLS-1$ |
155 | 91 |
92 /** | |
93 * Constructs a new instance of this class given its parent | |
94 * and a style value describing its behavior and appearance. | |
95 * <p> | |
96 * The style value is either one of the style constants defined in | |
97 * class <code>DWT</code> which is applicable to instances of this | |
98 * class, or must be built by <em>bitwise OR</em>'ing together | |
99 * (that is, using the <code>int</code> "|" operator) two or more | |
100 * of those <code>DWT</code> style constants. The class description | |
101 * lists the style constants that are applicable to the class. | |
102 * Style bits are also inherited from superclasses. | |
103 * </p> | |
104 * | |
105 * @param parent a widget which will be the parent of the new instance (cannot be null) | |
106 * @param style the style of widget to construct | |
107 * | |
108 * @exception IllegalArgumentException <ul> | |
109 * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> | |
110 * </ul> | |
111 * @exception DWTException <ul> | |
112 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> | |
113 * </ul> | |
114 * | |
115 * @see DWT#SINGLE | |
116 * @see DWT#MULTI | |
117 * @see DWT#CHECK | |
118 * @see DWT#FULL_SELECTION | |
119 * @see #getStyle | |
120 */ | |
121 public this(Composite parent, int style) { | |
122 super(parent, checkStyle (style)); | |
123 items = EMPTY_ITEMS; | |
124 table = new Table(this, style); | |
125 Listener tableListener = new class() Listener { | |
126 public void handleEvent(Event e) { | |
127 switch (e.type) { | |
128 case DWT.MouseDown: onMouseDown(e); break; | |
129 case DWT.Selection: onSelection(e); break; | |
130 case DWT.DefaultSelection: onSelection(e); break; | |
131 case DWT.KeyDown: onKeyDown(e); break; | |
132 default: | |
133 } | |
134 } | |
135 }; | |
136 int[] tableEvents = [DWT.MouseDown, | |
137 DWT.Selection, | |
138 DWT.DefaultSelection, | |
139 DWT.KeyDown]; | |
140 for (int i = 0; i < tableEvents.length; i++) { | |
141 table.addListener(tableEvents[i], tableListener); | |
142 } | |
143 | |
144 Listener listener = new class() Listener { | |
145 public void handleEvent(Event e) { | |
146 switch (e.type) { | |
147 case DWT.Dispose: onDispose(e); break; | |
148 case DWT.Resize: onResize(e); break; | |
149 case DWT.FocusIn: onFocusIn(e); break; | |
150 default: | |
151 } | |
152 } | |
153 }; | |
154 int[] events = [DWT.Dispose, | |
155 DWT.Resize, | |
156 DWT.FocusIn]; | |
157 for (int i = 0; i < events.length; i++) { | |
158 addListener(events[i], listener); | |
159 } | |
160 } | |
161 | |
162 int addItem(TableTreeItem item, int index) { | |
163 if (index < 0 || index > items.length) DWT.error(DWT.ERROR_INVALID_ARGUMENT); | |
164 TableTreeItem[] newItems = new TableTreeItem[items.length + 1]; | |
165 System.arraycopy(items, 0, newItems, 0, index); | |
166 newItems[index] = item; | |
167 System.arraycopy(items, index, newItems, index + 1, items.length - index); | |
168 items = newItems; | |
169 | |
170 /* Return the index in the table where this table should be inserted */ | |
171 if (index is items.length - 1 ) | |
172 return table.getItemCount(); | |
173 else | |
174 return table.indexOf(items[index+1].tableItem); | |
175 } | |
176 | |
177 /** | |
178 * Adds the listener to the collection of listeners who will | |
179 * be notified when the user changes the receiver's selection, by sending | |
180 * it one of the messages defined in the <code>SelectionListener</code> | |
181 * interface. | |
182 * <p> | |
183 * When <code>widgetSelected</code> is called, the item field of the event object is valid. | |
184 * If the receiver has <code>DWT.CHECK</code> style set and the check selection changes, | |
185 * the event object detail field contains the value <code>DWT.CHECK</code>. | |
186 * <code>widgetDefaultSelected</code> is typically called when an item is double-clicked. | |
187 * The item field of the event object is valid for default selection, but the detail field is not used. | |
188 * </p> | |
189 * | |
190 * @param listener the listener which should be notified when the user changes the receiver's selection | |
191 * | |
192 * @exception IllegalArgumentException <ul> | |
193 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> | |
194 * </ul> | |
195 * @exception DWTException <ul> | |
196 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
197 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
198 * </ul> | |
199 * | |
200 * @see SelectionListener | |
201 * @see #removeSelectionListener | |
202 * @see SelectionEvent | |
203 */ | |
204 public void addSelectionListener(SelectionListener listener) { | |
205 checkWidget(); | |
206 if (listener is null) DWT.error (DWT.ERROR_NULL_ARGUMENT); | |
207 TypedListener typedListener = new TypedListener (listener); | |
208 addListener (DWT.Selection,typedListener); | |
209 addListener (DWT.DefaultSelection,typedListener); | |
210 } | |
211 | |
212 /** | |
213 * Adds the listener to the collection of listeners who will | |
214 * be notified when an item in the receiver is expanded or collapsed | |
215 * by sending it one of the messages defined in the <code>TreeListener</code> | |
216 * interface. | |
217 * | |
218 * @param listener the listener which should be notified | |
219 * | |
220 * @exception IllegalArgumentException <ul> | |
221 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> | |
222 * </ul> | |
223 * @exception DWTException <ul> | |
224 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
225 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
226 * </ul> | |
227 * | |
228 * @see TreeListener | |
229 * @see #removeTreeListener | |
230 */ | |
231 public void addTreeListener(TreeListener listener) { | |
232 checkWidget(); | |
233 if (listener is null) DWT.error (DWT.ERROR_NULL_ARGUMENT); | |
234 TypedListener typedListener = new TypedListener (listener); | |
235 addListener (DWT.Expand, typedListener); | |
236 addListener (DWT.Collapse, typedListener); | |
237 } | |
238 private static int checkStyle (int style) { | |
239 int mask = DWT.LEFT_TO_RIGHT | DWT.RIGHT_TO_LEFT; | |
240 style = style & mask; | |
241 return style; | |
242 } | |
243 public override Point computeSize (int wHint, int hHint, bool changed) { | |
244 checkWidget(); | |
245 return table.computeSize (wHint, hHint, changed); | |
246 } | |
247 public override Rectangle computeTrim (int x, int y, int width, int height) { | |
248 checkWidget(); | |
249 return table.computeTrim(x, y, width, height); | |
250 } | |
251 | |
252 /** | |
253 * Deselects all items. | |
254 * <p> | |
255 * If an item is selected, it is deselected. | |
256 * If an item is not selected, it remains unselected. | |
257 * | |
258 * @exception DWTException <ul> | |
259 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread | |
260 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed | |
261 * </ul> | |
262 */ | |
263 public void deselectAll () { | |
264 checkWidget(); | |
265 table.deselectAll(); | |
266 } | |
267 | |
268 /* Expand upward from the specified leaf item. */ | |
269 void expandItem (TableTreeItem item) { | |
270 if (item is null) return; | |
271 expandItem(item.parentItem); | |
272 if (!item.getVisible()) item.setVisible(true); | |
273 if ( !item.expanded && item.items.length > 0) { | |
274 item.setExpanded(true); | |
275 Event event = new Event(); | |
276 event.item = item; | |
277 notifyListeners(DWT.Expand, event); | |
278 } | |
279 } | |
280 public override Color getBackground () { | |
281 // This method must be overridden otherwise, in a TableTree in which the first | |
282 // item has no sub items, a grey (Widget background colour) square will appear in | |
283 // the first column of the first item. | |
284 // It is not possible in the constructor to set the background of the TableTree | |
285 // to be the same as the background of the Table because this interferes with | |
286 // the TableTree adapting to changes in the System color settings. | |
287 return table.getBackground(); | |
288 } | |
289 public override Rectangle getClientArea () { | |
290 return table.getClientArea(); | |
291 } | |
292 public override Color getForeground () { | |
293 return table.getForeground(); | |
294 } | |
295 public override Font getFont () { | |
296 return table.getFont(); | |
297 } | |
298 /** | |
299 * Gets the number of items. | |
300 * <p> | |
301 * @return the number of items in the widget | |
302 */ | |
303 public int getItemCount () { | |
304 //checkWidget(); | |
305 return items.length; | |
306 } | |
307 | |
308 /** | |
309 * Gets the height of one item. | |
310 * <p> | |
311 * This operation will fail if the height of | |
312 * one item could not be queried from the OS. | |
313 * | |
314 * @return the height of one item in the widget | |
315 * | |
316 * @exception DWTException <ul> | |
317 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread | |
318 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed | |
319 * </ul> | |
320 */ | |
321 public int getItemHeight () { | |
322 checkWidget(); | |
323 return table.getItemHeight(); | |
324 } | |
325 | |
326 /** | |
327 * Gets the items. | |
328 * <p> | |
329 * @return the items in the widget | |
330 */ | |
331 public TableTreeItem [] getItems () { | |
332 //checkWidget(); | |
333 TableTreeItem[] newItems = new TableTreeItem[items.length]; | |
334 System.arraycopy(items, 0, newItems, 0, items.length); | |
335 return newItems; | |
336 } | |
337 | |
338 /** | |
339 * Gets the selected items. | |
340 * <p> | |
341 * This operation will fail if the selected | |
342 * items cannot be queried from the OS. | |
343 * | |
344 * @return the selected items in the widget | |
345 * | |
346 * @exception DWTException <ul> | |
347 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li> | |
348 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li> | |
349 * </ul> | |
350 */ | |
351 public TableTreeItem [] getSelection () { | |
352 checkWidget(); | |
353 TableItem[] selection = table.getSelection(); | |
354 TableTreeItem [] result = new TableTreeItem[selection.length]; | |
355 for (int i = 0; i < selection.length; i++){ | |
356 result[i] = cast(TableTreeItem) selection[i].getData(ITEMID); | |
357 } | |
358 return result; | |
359 } | |
360 | |
361 /** | |
362 * Gets the number of selected items. | |
363 * <p> | |
364 * This operation will fail if the number of selected | |
365 * items cannot be queried from the OS. | |
366 * | |
367 * @return the number of selected items in the widget | |
368 * | |
369 * @exception DWTException <ul> | |
370 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li> | |
371 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li> | |
372 * </ul> | |
373 */ | |
374 public int getSelectionCount () { | |
375 checkWidget(); | |
376 return table.getSelectionCount(); | |
377 } | |
378 | |
379 public override int getStyle () { | |
380 checkWidget(); | |
381 return table.getStyle(); | |
382 } | |
383 | |
384 /** | |
385 * Returns the underlying Table control. | |
386 * | |
387 * @return the underlying Table control | |
388 */ | |
389 public Table getTable () { | |
390 //checkWidget(); | |
391 return table; | |
392 } | |
393 | |
394 void createImages () { | |
395 | |
396 int itemHeight = sizeImage.getBounds().height; | |
397 // Calculate border around image. | |
398 // At least 9 pixels are needed to draw the image | |
399 // Leave at least a 6 pixel border. | |
400 int indent = Math.min(6, (itemHeight - 9) / 2); | |
401 indent = Math.max(0, indent); | |
402 int size = Math.max (10, itemHeight - 2 * indent); | |
403 size = ((size + 1) / 2) * 2; // size must be an even number | |
404 int midpoint = indent + size / 2; | |
405 | |
406 Color foreground = getForeground(); | |
407 Color plusMinus = getDisplay().getSystemColor(DWT.COLOR_WIDGET_NORMAL_SHADOW); | |
408 Color background = getBackground(); | |
409 | |
410 /* Plus image */ | |
411 PaletteData palette = new PaletteData( [ foreground.getRGB(), background.getRGB(), plusMinus.getRGB()]); | |
412 ImageData imageData = new ImageData(itemHeight, itemHeight, 4, palette); | |
413 imageData.transparentPixel = 1; | |
414 plusImage = new Image(getDisplay(), imageData); | |
415 GC gc = new GC(plusImage); | |
416 gc.setBackground(background); | |
417 gc.fillRectangle(0, 0, itemHeight, itemHeight); | |
418 gc.setForeground(plusMinus); | |
419 gc.drawRectangle(indent, indent, size, size); | |
420 gc.setForeground(foreground); | |
421 gc.drawLine(midpoint, indent + 2, midpoint, indent + size - 2); | |
422 gc.drawLine(indent + 2, midpoint, indent + size - 2, midpoint); | |
423 gc.dispose(); | |
424 | |
425 /* Minus image */ | |
426 palette = new PaletteData([foreground.getRGB(), background.getRGB(), plusMinus.getRGB()]); | |
427 imageData = new ImageData(itemHeight, itemHeight, 4, palette); | |
428 imageData.transparentPixel = 1; | |
429 minusImage = new Image(getDisplay(), imageData); | |
430 gc = new GC(minusImage); | |
431 gc.setBackground(background); | |
432 gc.fillRectangle(0, 0, itemHeight, itemHeight); | |
433 gc.setForeground(plusMinus); | |
434 gc.drawRectangle(indent, indent, size, size); | |
435 gc.setForeground(foreground); | |
436 gc.drawLine(indent + 2, midpoint, indent + size - 2, midpoint); | |
437 gc.dispose(); | |
438 } | |
439 | |
440 Image getPlusImage() { | |
441 if (plusImage is null) createImages(); | |
442 return plusImage; | |
443 } | |
444 | |
445 Image getMinusImage() { | |
446 if (minusImage is null) createImages(); | |
447 return minusImage; | |
448 } | |
449 | |
450 /** | |
451 * Gets the index of an item. | |
452 * | |
453 * <p>The widget is searched starting at 0 until an | |
454 * item is found that is equal to the search item. | |
455 * If no item is found, -1 is returned. Indexing | |
456 * is zero based. This index is relative to the parent only. | |
457 * | |
458 * @param item the search item | |
459 * @return the index of the item or -1 | |
460 */ | |
461 public int indexOf (TableTreeItem item) { | |
462 //checkWidget(); | |
463 for (int i = 0; i < items.length; i++) { | |
464 if (item is items[i]) return i; | |
465 } | |
466 return -1; | |
467 } | |
468 | |
469 void onDispose(Event e) { | |
470 /* | |
471 * Usually when an item is disposed, destroyItem will change the size of the items array | |
472 * and dispose of the underlying table items. | |
473 * Since the whole table tree is being disposed, this is not necessary. For speed | |
474 * the inDispose flag is used to skip over this part of the item dispose. | |
475 */ | |
476 inDispose = true; | |
477 for (int i = 0; i < items.length; i++) { | |
478 items[i].dispose(); | |
479 } | |
480 inDispose = false; | |
481 if (plusImage !is null) plusImage.dispose(); | |
482 if (minusImage !is null) minusImage.dispose(); | |
483 if (sizeImage !is null) sizeImage.dispose(); | |
484 plusImage = minusImage = sizeImage = null; | |
485 } | |
486 | |
487 void onResize(Event e) { | |
488 Point size = getSize(); | |
489 table.setBounds(0, 0, size.x, size.y); | |
490 } | |
491 | |
492 void onSelection(Event e) { | |
493 Event event = new Event(); | |
494 TableItem tableItem = cast(TableItem)e.item; | |
495 TableTreeItem item = getItem(tableItem); | |
496 event.item = item; | |
497 | |
498 if (e.type is DWT.Selection && e.detail is DWT.CHECK && item !is null) { | |
499 event.detail = DWT.CHECK; | |
500 item.checked = tableItem.getChecked(); | |
501 } | |
502 notifyListeners(e.type, event); | |
503 } | |
504 /** | |
505 * Returns the item at the given, zero-relative index in the | |
506 * receiver. Throws an exception if the index is out of range. | |
507 * | |
508 * @param index the index of the item to return | |
509 * @return the item at the given index | |
510 * | |
511 * @exception IllegalArgumentException <ul> | |
512 * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li> | |
513 * </ul> | |
514 * @exception DWTException <ul> | |
515 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
516 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
517 * </ul> | |
518 * | |
519 * @since 3.1 | |
520 */ | |
521 public TableTreeItem getItem (int index) { | |
522 checkWidget(); | |
523 int count = items.length; | |
524 if (!(0 <= index && index < count)) DWT.error (DWT.ERROR_INVALID_RANGE); | |
525 return items [index]; | |
526 } | |
527 | |
528 /** | |
529 * Returns the item at the given point in the receiver | |
530 * or null if no such item exists. The point is in the | |
531 * coordinate system of the receiver. | |
532 * | |
533 * @param point the point used to locate the item | |
534 * @return the item at the given point | |
535 * | |
536 * @exception IllegalArgumentException <ul> | |
537 * <li>ERROR_NULL_ARGUMENT - if the point is null</li> | |
538 * </ul> | |
539 * @exception DWTException <ul> | |
540 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
541 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
542 * </ul> | |
543 */ | |
544 public TableTreeItem getItem(Point point) { | |
545 checkWidget(); | |
546 TableItem item = table.getItem(point); | |
547 if (item is null) return null; | |
548 return getItem(item); | |
549 | |
550 } | |
551 TableTreeItem getItem(TableItem tableItem) { | |
552 if (tableItem is null) return null; | |
553 for (int i = 0; i < items.length; i++) { | |
554 TableTreeItem item = items[i].getItem(tableItem); | |
555 if (item !is null) return item; | |
556 } | |
557 return null; | |
558 } | |
559 void onFocusIn (Event e) { | |
560 table.setFocus(); | |
561 } | |
562 | |
563 void onKeyDown (Event e) { | |
564 TableTreeItem[] selection = getSelection(); | |
565 if (selection.length is 0) return; | |
566 TableTreeItem item = selection[0]; | |
567 int type = 0; | |
568 if (e.keyCode is DWT.ARROW_RIGHT || e.keyCode is DWT.ARROW_LEFT) { | |
569 int trailKey = (getStyle() & DWT.MIRRORED) !is 0 ? DWT.ARROW_LEFT : DWT.ARROW_RIGHT; | |
570 if (e.keyCode is trailKey) { | |
571 if (item.getItemCount() is 0) return; | |
572 if (item.getExpanded()) { | |
573 TableTreeItem newSelection = item.getItems()[0]; | |
574 table.setSelection([newSelection.tableItem]); | |
575 showItem(newSelection); | |
576 type = DWT.Selection; | |
577 } else { | |
578 item.setExpanded(true); | |
579 type = DWT.Expand; | |
580 } | |
581 } else { | |
582 if (item.getExpanded()) { | |
583 item.setExpanded(false); | |
584 type = DWT.Collapse; | |
585 } else { | |
586 TableTreeItem parent = item.getParentItem(); | |
587 if (parent !is null) { | |
588 int index = parent.indexOf(item); | |
589 if (index !is 0) return; | |
590 table.setSelection([parent.tableItem]); | |
591 type = DWT.Selection; | |
592 } | |
593 } | |
594 } | |
595 } | |
596 if (e.character is '*') { | |
597 item.expandAll(true); | |
598 } | |
599 if (e.character is '-') { | |
600 if (item.getExpanded()) { | |
601 item.setExpanded(false); | |
602 type = DWT.Collapse; | |
603 } | |
604 } | |
605 if (e.character is '+') { | |
606 if (item.getItemCount() > 0 && !item.getExpanded()) { | |
607 item.setExpanded(true); | |
608 type = DWT.Expand; | |
609 } | |
610 } | |
611 if (type is 0) return; | |
612 Event event = new Event(); | |
613 event.item = item; | |
614 notifyListeners(type, event); | |
615 } | |
616 void onMouseDown(Event event) { | |
617 /* If user clicked on the [+] or [-], expand or collapse the tree. */ | |
618 TableItem[] items = table.getItems(); | |
619 for (int i = 0; i < items.length; i++) { | |
620 Rectangle rect = items[i].getImageBounds(0); | |
621 if (rect.contains(event.x, event.y)) { | |
622 TableTreeItem item = cast(TableTreeItem) items[i].getData(ITEMID); | |
623 event = new Event(); | |
624 event.item = item; | |
625 item.setExpanded(!item.getExpanded()); | |
626 if (item.getExpanded()) { | |
627 notifyListeners(DWT.Expand, event); | |
628 } else { | |
629 notifyListeners(DWT.Collapse, event); | |
630 } | |
631 return; | |
632 } | |
633 } | |
634 } | |
635 | |
636 /** | |
637 * Removes all items. | |
638 * <p> | |
639 * This operation will fail when an item | |
640 * could not be removed in the OS. | |
641 * | |
642 * @exception DWTException <ul> | |
643 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread | |
644 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed | |
645 * </ul> | |
646 */ | |
647 public void removeAll () { | |
648 checkWidget(); | |
649 setRedraw(false); | |
650 for (int i = items.length - 1; i >= 0; i--) { | |
651 items[i].dispose(); | |
652 } | |
653 items = EMPTY_ITEMS; | |
654 setRedraw(true); | |
655 } | |
656 | |
657 void removeItem(TableTreeItem item) { | |
658 int index = 0; | |
659 while (index < items.length && items[index] !is item) index++; | |
660 if (index is items.length) return; | |
661 TableTreeItem[] newItems = new TableTreeItem[items.length - 1]; | |
662 System.arraycopy(items, 0, newItems, 0, index); | |
663 System.arraycopy(items, index + 1, newItems, index, items.length - index - 1); | |
664 items = newItems; | |
665 } | |
666 | |
667 /** | |
668 * Removes the listener from the collection of listeners who will | |
669 * be notified when the user changes the receiver's selection. | |
670 * | |
671 * @param listener the listener which should no longer be notified | |
672 * | |
673 * @exception IllegalArgumentException <ul> | |
674 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> | |
675 * </ul> | |
676 * @exception DWTException <ul> | |
677 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
678 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
679 * </ul> | |
680 * | |
681 * @see SelectionListener | |
682 * @see #addSelectionListener | |
683 */ | |
684 public void removeSelectionListener (SelectionListener listener) { | |
685 checkWidget(); | |
686 if (listener is null) DWT.error (DWT.ERROR_NULL_ARGUMENT); | |
687 removeListener(DWT.Selection, listener); | |
688 removeListener(DWT.DefaultSelection, listener); | |
689 } | |
690 | |
691 /** | |
692 * Removes the listener from the collection of listeners who will | |
693 * be notified when items in the receiver are expanded or collapsed. | |
694 * | |
695 * @param listener the listener which should no longer be notified | |
696 * | |
697 * @exception IllegalArgumentException <ul> | |
698 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> | |
699 * </ul> | |
700 * @exception DWTException <ul> | |
701 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
702 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
703 * </ul> | |
704 * | |
705 * @see TreeListener | |
706 * @see #addTreeListener | |
707 */ | |
708 public void removeTreeListener (TreeListener listener) { | |
709 checkWidget(); | |
710 if (listener is null) DWT.error (DWT.ERROR_NULL_ARGUMENT); | |
711 removeListener(DWT.Expand, listener); | |
712 removeListener(DWT.Collapse, listener); | |
713 } | |
714 | |
715 /** | |
716 * Selects all of the items in the receiver. | |
717 * <p> | |
718 * If the receiver is single-select, do nothing. | |
719 * | |
720 * @exception DWTException <ul> | |
721 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread | |
722 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed | |
723 * </ul> | |
724 */ | |
725 public void selectAll () { | |
726 checkWidget(); | |
727 table.selectAll(); | |
728 } | |
729 public override void setBackground (Color color) { | |
730 super.setBackground(color); | |
731 table.setBackground(color); | |
732 if (sizeImage !is null) { | |
733 GC gc = new GC (sizeImage); | |
734 gc.setBackground(getBackground()); | |
735 Rectangle size = sizeImage.getBounds(); | |
736 gc.fillRectangle(size); | |
737 gc.dispose(); | |
738 } | |
739 } | |
740 public override void setEnabled (bool enabled) { | |
741 super.setEnabled(enabled); | |
742 table.setEnabled(enabled); | |
743 } | |
744 public override void setFont (Font font) { | |
745 super.setFont(font); | |
746 table.setFont(font); | |
747 } | |
748 public override void setForeground (Color color) { | |
749 super.setForeground(color); | |
750 table.setForeground(color); | |
751 } | |
752 public override void setMenu (Menu menu) { | |
753 super.setMenu(menu); | |
754 table.setMenu(menu); | |
755 } | |
756 | |
757 /** | |
758 * Sets the receiver's selection to be the given array of items. | |
759 * The current selection is cleared before the new items are selected. | |
760 * <p> | |
761 * Items that are not in the receiver are ignored. | |
762 * If the receiver is single-select and multiple items are specified, | |
763 * then all items are ignored. | |
764 * | |
765 * @param items the array of items | |
766 * | |
767 * @exception IllegalArgumentException <ul> | |
768 * <li>ERROR_NULL_ARGUMENT - if the array of items is null</li> | |
769 * <li>ERROR_INVALID_ARGUMENT - if one of the item has been disposed</li> | |
770 * </ul> | |
771 * @exception DWTException <ul> | |
772 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
773 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
774 * </ul> | |
775 * | |
776 * @see TableTree#deselectAll() | |
777 */ | |
778 public void setSelection (TableTreeItem[] items) { | |
779 checkWidget (); | |
780 if (items is null) DWT.error (DWT.ERROR_NULL_ARGUMENT); | |
781 int length = items.length; | |
782 if (length is 0 || ((table.getStyle() & DWT.SINGLE) !is 0 && length > 1)) { | |
783 deselectAll(); | |
784 return; | |
785 } | |
786 TableItem[] tableItems = new TableItem[length]; | |
787 for (int i = 0; i < length; i++) { | |
788 if (items[i] is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); | |
789 if (!items[i].getVisible()) expandItem (items[i]); | |
790 tableItems[i] = items[i].tableItem; | |
791 } | |
792 table.setSelection(tableItems); | |
793 } | |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
155
diff
changeset
|
794 public override void setToolTipText (String string) { |
155 | 795 super.setToolTipText(string); |
796 table.setToolTipText(string); | |
797 } | |
798 | |
799 /** | |
800 * Shows the item. If the item is already showing in the receiver, | |
801 * this method simply returns. Otherwise, the items are scrolled | |
802 * and expanded until the item is visible. | |
803 * | |
804 * @param item the item to be shown | |
805 * | |
806 * @exception IllegalArgumentException <ul> | |
807 * <li>ERROR_NULL_ARGUMENT - if the item is null</li> | |
808 * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li> | |
809 * </ul> | |
810 * @exception DWTException <ul> | |
811 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
812 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
813 * </ul> | |
814 * | |
815 * @see TableTree#showSelection() | |
816 */ | |
817 public void showItem (TableTreeItem item) { | |
818 checkWidget(); | |
819 if (item is null) DWT.error (DWT.ERROR_NULL_ARGUMENT); | |
820 if (!item.getVisible()) expandItem (item); | |
821 TableItem tableItem = item.tableItem; | |
822 table.showItem(tableItem); | |
823 } | |
824 | |
825 /** | |
826 * Shows the selection. | |
827 * <p> | |
828 * If there is no selection or the selection | |
829 * is already visible, this method does nothing. | |
830 * If the selection is scrolled out of view, | |
831 * the top index of the widget is changed such | |
832 * that selection becomes visible. | |
833 * | |
834 * @exception DWTException <ul> | |
835 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread | |
836 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed | |
837 * </ul> | |
838 */ | |
839 public void showSelection () { | |
840 checkWidget(); | |
841 table.showSelection(); | |
842 } | |
843 } |