diff dwt/custom/TableTreeItem.d @ 41:6337764516f1

Sync dwt/custom with dwt-linux (took copy of complete folder)
author Frank Benoit <benoit@tionex.de>
date Tue, 07 Oct 2008 16:29:55 +0200
parents 1a8b3cb347e0
children
line wrap: on
line diff
--- a/dwt/custom/TableTreeItem.d	Tue Oct 07 14:41:31 2008 +0200
+++ b/dwt/custom/TableTreeItem.d	Tue Oct 07 16:29:55 2008 +0200
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2007 IBM Corporation and others.
+ * Copyright (c) 2000, 2008 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -7,28 +7,43 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ *     Frank Benoit <benoit@tionex.de>
  *******************************************************************************/
-module dwt.custom;
+module dwt.custom.TableTreeItem;
+
 
 
-import dwt.*;
-import dwt.graphics.*;
-import dwt.widgets.*;
+import dwt.DWT;
+import dwt.DWTException;
+import dwt.graphics.Color;
+import dwt.graphics.Font;
+import dwt.graphics.GC;
+import dwt.graphics.Image;
+import dwt.graphics.Rectangle;
+import dwt.widgets.Event;
+import dwt.widgets.Item;
+import dwt.widgets.Table;
+import dwt.widgets.TableItem;
+import dwt.widgets.Widget;
+import dwt.custom.TableTree;
+import dwt.dwthelper.utils;
+
 
 /**
  * A TableTreeItem is a selectable user interface object
  * that represents an item in a hierarchy of items in a
  * TableTree.
- * 
+ *
  * @deprecated As of 3.1 use Tree, TreeItem and TreeColumn
  */
 public class TableTreeItem : Item {
     TableItem tableItem;
     TableTree parent;
     TableTreeItem parentItem;
-    TableTreeItem [] items = TableTree.EMPTY_ITEMS;
-    String[] texts = TableTree.EMPTY_TEXTS;
-    Image[] images = TableTree.EMPTY_IMAGES;
+    TableTreeItem [] items;
+    String[] texts;
+    Image[] images;
     Color background;
     Color foreground;
     Font font;
@@ -44,7 +59,7 @@
  * <p>
  * The style value is either one of the style constants defined in
  * class <code>DWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together 
+ * class, or must be built by <em>bitwise OR</em>'ing together
  * (that is, using the <code>int</code> "|" operator) two or more
  * of those <code>DWT</code> style constants. The class description
  * lists the style constants that are applicable to the class.
@@ -76,7 +91,7 @@
  * <p>
  * The style value is either one of the style constants defined in
  * class <code>DWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together 
+ * class, or must be built by <em>bitwise OR</em>'ing together
  * (that is, using the <code>int</code> "|" operator) two or more
  * of those <code>DWT</code> style constants. The class description
  * lists the style constants that are applicable to the class.
@@ -109,7 +124,7 @@
  * <p>
  * The style value is either one of the style constants defined in
  * class <code>DWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together 
+ * class, or must be built by <em>bitwise OR</em>'ing together
  * (that is, using the <code>int</code> "|" operator) two or more
  * of those <code>DWT</code> style constants. The class description
  * lists the style constants that are applicable to the class.
@@ -141,7 +156,7 @@
  * <p>
  * The style value is either one of the style constants defined in
  * class <code>DWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together 
+ * class, or must be built by <em>bitwise OR</em>'ing together
  * (that is, using the <code>int</code> "|" operator) two or more
  * of those <code>DWT</code> style constants. The class description
  * lists the style constants that are applicable to the class.
@@ -167,11 +182,16 @@
 }
 
 this(TableTree parent, TableTreeItem parentItem, int style, int index) {
+
+    items = TableTree.EMPTY_ITEMS;
+    texts = TableTree.EMPTY_TEXTS;
+    images = TableTree.EMPTY_IMAGES;
+
     super(parent, style);
     this.parent = parent;
     this.parentItem = parentItem;
     if (parentItem is null) {
-        
+
         /* Root items are visible immediately */
         int tableIndex = parent.addItem(this, index);
         tableItem = new TableItem(parent.getTable(), style, tableIndex);
@@ -206,7 +226,7 @@
 void addItem(TableTreeItem item, int index) {
     if (item is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
     if (index < 0 || index > items.length) DWT.error(DWT.ERROR_INVALID_ARGUMENT);
-        
+
     /* Now that item has a sub-node it must indicate that it can be expanded */
     if (items.length is 0 && index is 0) {
         if (tableItem !is null) {
@@ -214,7 +234,7 @@
             tableItem.setImage(0, image);
         }
     }
-    
+
     /* Put the item in the items list */
     TableTreeItem[] newItems = new TableTreeItem[items.length + 1];
     System.arraycopy(items, 0, newItems, 0, index);
@@ -228,14 +248,14 @@
  * Returns the receiver's background color.
  *
  * @return the background color
- * 
+ *
  * @exception DWTException <ul>
  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
  * </ul>
- * 
+ *
  * @since 2.0
- * 
+ *
  */
 public Color getBackground () {
     checkWidget ();
@@ -290,7 +310,7 @@
  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
  * </ul>
- * 
+ *
  * @since 2.1
  */
 public bool getGrayed () {
@@ -336,9 +356,9 @@
  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
  * </ul>
- * 
+ *
  * @since 2.0
- * 
+ *
  */
 public Color getForeground () {
     checkWidget ();
@@ -351,13 +371,13 @@
  * images of the tree, therefore getImage(0) will return null.
  *
  * @return the image at index 0
- * 
+ *
  * @exception DWTException <ul>
  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
  * </ul>
  */
-public Image getImage () {
+public override Image getImage () {
     checkWidget();
     return getImage(0);
 }
@@ -398,7 +418,7 @@
  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
  * </ul>
- * 
+ *
  * @since 3.1
  */
 public TableTreeItem getItem (int index) {
@@ -425,7 +445,7 @@
  * <p>
  * Note: This is not the actual structure used by the receiver
  * to maintain its list of items, so modifying the array will
- * not affect the receiver. 
+ * not affect the receiver.
  * </p>
  *
  * @return the receiver's items
@@ -468,7 +488,7 @@
     //checkWidget();
     return parentItem;
 }
-public String getText () {
+public override String getText () {
     checkWidget();
     return getText(0);
 }
@@ -497,7 +517,7 @@
 
 /**
  * Gets the index of the specified item.
- * 
+ *
  * <p>The widget is searched starting at 0 until an
  * item is found that is equal to the search item.
  * If no item is found, -1 is returned.  Indexing
@@ -508,7 +528,7 @@
  *
  */
 public int indexOf (TableTreeItem item) {
-    //checkWidget();    
+    //checkWidget();
     for (int i = 0; i < items.length; i++) {
         if (items[i] is item) return i;
     }
@@ -529,7 +549,7 @@
         items[i].expandAll(notify);
     }
 }
-int expandedIndexOf (TableTreeItem item) {  
+int expandedIndexOf (TableTreeItem item) {
     int index = 0;
     for (int i = 0; i < items.length; i++) {
         if (items[i] is item) return index;
@@ -549,7 +569,7 @@
     return count;
 }
 
-public void dispose () {
+public override void dispose () {
     if (isDisposed()) return;
     for (int i = items.length - 1; i >= 0; i--) {
         items[i].dispose();
@@ -593,17 +613,17 @@
  * if the argument is null.
  *
  * @param color the new color (or null)
- * 
+ *
  * @exception IllegalArgumentException <ul>
- *    <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li> 
+ *    <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
  * </ul>
  * @exception DWTException <ul>
  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
  * </ul>
- * 
+ *
  * @since 2.0
- * 
+ *
  */
 public void setBackground (Color color) {
     checkWidget ();
@@ -617,7 +637,7 @@
 }
 
 /**
- * Sets the checked state of the checkbox for this item.  This state change 
+ * Sets the checked state of the checkbox for this item.  This state change
  * only applies if the Table was created with the DWT.CHECK style.
  *
  * @param checked the new checked state of the checkbox
@@ -638,16 +658,16 @@
 }
 
 /**
- * Sets the grayed state of the checkbox for this item.  This state change 
+ * Sets the grayed state of the checkbox for this item.  This state change
  * only applies if the Table was created with the DWT.CHECK style.
  *
- * @param grayed the new grayed state of the checkbox; 
+ * @param grayed the new grayed state of the checkbox;
  *
  * @exception DWTException <ul>
  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
  * </ul>
- * 
+ *
  * @since 2.1
  */
 public void setGrayed (bool grayed) {
@@ -693,13 +713,13 @@
  * @param font the new font (or null)
  *
  * @exception IllegalArgumentException <ul>
- *    <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li> 
+ *    <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
  * </ul>
  * @exception DWTException <ul>
  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
  * </ul>
- * 
+ *
  * @since 3.0
  */
 public void setFont (Font font){
@@ -720,17 +740,17 @@
  * @param color the new color (or null)
  *
  * @since 2.0
- * 
+ *
  * @exception IllegalArgumentException <ul>
- *    <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li> 
+ *    <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
  * </ul>
  * @exception DWTException <ul>
  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
  * </ul>
- * 
+ *
  * @since 2.0
- * 
+ *
  */
 public void setForeground (Color color) {
     checkWidget ();
@@ -778,13 +798,13 @@
  * images of the tree, therefore do nothing.
  *
  * @param image the new image or null
- * 
+ *
  * @exception DWTException <ul>
  *      <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li>
  *      <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li>
  *  </ul>
  */
-public void setImage (Image image) {
+public override void setImage (Image image) {
     setImage(0, image);
 }
 
@@ -799,9 +819,6 @@
  * @param index the column number
  * @param text the new text
  *
- * @exception IllegalArgumentException <ul>
- *    <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
  * @exception DWTException <ul>
  *      <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li>
  *      <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li>
@@ -809,7 +826,8 @@
  */
 public void setText(int index, String text) {
     checkWidget();
-    if (text is null) DWT.error (DWT.ERROR_NULL_ARGUMENT);
+    // DWT extension: allow null for zero length string
+    //if (text is null) DWT.error (DWT.ERROR_NULL_ARGUMENT);
     int columnCount = Math.max(parent.getTable().getColumnCount(), 1);
     if (index < 0 || index >= columnCount) return;
     if (texts.length < columnCount) {
@@ -820,8 +838,8 @@
     texts[index] = text;
     if (tableItem !is null) tableItem.setText(index, text);
 }
-public void setText (String String) {
-    setText(0, String);
+public override void setText (String string) {
+    setText(0, string);
 }
 
 void setVisible (bool show) {
@@ -862,7 +880,7 @@
                 tableItem.setImage(0, parent.getPlusImage());
             }
         }
-        
+
     } else {
 
         for (int i = 0, length = items.length; i < length; i++) {