diff dwt/widgets/TableItem.d @ 45:d8635bb48c7c

Merge with SWT 3.5
author Jacob Carlborg <doob@me.com>
date Mon, 01 Dec 2008 17:07:00 +0100
parents e831403a80a9
children 2d895a357833
line wrap: on
line diff
--- a/dwt/widgets/TableItem.d	Tue Oct 21 15:20:04 2008 +0200
+++ b/dwt/widgets/TableItem.d	Mon Dec 01 17:07:00 2008 +0100
@@ -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
@@ -21,9 +21,12 @@
 import dwt.graphics.Image;
 import dwt.graphics.Rectangle;
 import dwt.internal.cocoa.NSAttributedString;
+import dwt.internal.cocoa.NSBrowserCell;
 import dwt.internal.cocoa.NSColor;
 import dwt.internal.cocoa.NSMutableDictionary;
+import dwt.internal.cocoa.NSMutableParagraphStyle;
 import dwt.internal.cocoa.NSRect;
+import dwt.internal.cocoa.NSSize;
 import dwt.internal.cocoa.NSString;
 import dwt.internal.cocoa.NSTableView;
 import dwt.internal.cocoa.OS;
@@ -40,6 +43,9 @@
  * <p>
  * IMPORTANT: This class is <em>not</em> intended to be subclassed.
  * </p>
+ *
+ * @see <a href="http://www.eclipse.org/swt/snippets/#table">Table, TableItem, TableColumn snippets</a>
+ * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
  */
 public class TableItem : Item {
     Table parent;
@@ -50,7 +56,7 @@
     Color[] cellForeground, cellBackground;
     Font font;
     Font[] cellFont;
-    int width = -1;
+    int customWidth = -1;
     
 /**
  * Constructs a new instance of this class given its parent
@@ -133,31 +139,50 @@
     return control;
 }
 
-int calculateWidth (int index, GC gc) {
-    if (index is 0 && width !is -1) return width;
-    int width = 0;
-    Image image = getImage (index);
-    String text = getText (index);
-    gc.setFont (getFont (index));
-//  if (image !is null) width += image.getBounds ().width + parent.getGap ();
-    if (text !is null && text.length () > 0) width += gc.stringExtent (text).x;
-//  if (parent.hooks (DWT.MeasureItem)) {
-//      Event event = new Event ();
-//      event.item = this;
-//      event.index = index;
-//      event.gc = gc;
-//      short [] height = new short [1];
-//      OS.GetDataBrowserTableViewRowHeight (parent.handle, height);
-//      event.width = width;
-//      event.height = height[0];
-//      parent.sendEvent (DWT.MeasureItem, event);
-//      if (parent.itemHeight < event.height) {
-//          parent.itemHeight = event.height;
-//          OS.SetDataBrowserTableViewRowHeight (parent.handle, cast(short) event.height);
-//      }
-//      width = event.width;
-//  }
-    if (index is 0) this.width = width;
+int calculateWidth (int columnIndex, GC gc, bool callMeasureItem) {
+    if (!callMeasureItem && customWidth !is -1) return customWidth;
+
+    NSBrowserCell cell = parent.dataCell;
+    cell.setFont (getFont (columnIndex).handle);
+    cell.setTitle (NSString.stringWith (getText (columnIndex)));
+    Image image = getImage (columnIndex);
+    cell.setImage (image !is null ? image.handle : null);
+    NSRect rect = new NSRect ();
+    rect.width = rect.height = Float.MAX_VALUE;
+    NSSize size = cell.cellSizeForBounds (rect);
+    int width = (int)Math.ceil (size.width);
+
+    if (callMeasureItem && parent.hooks (DWT.MeasureItem)) {
+        NSTableView tableView = (NSTableView)parent.view;
+        int nsColumnIndex = 0;
+        if (parent.columnCount > 0) {
+            nsColumnIndex = tableView.columnWithIdentifier (parent.columns[columnIndex].nsColumn);
+        }
+        int rowIndex = parent.indexOf (this);
+        rect = tableView.frameOfCellAtColumn (nsColumnIndex, rowIndex);
+        NSRect contentRect = cell.titleRectForBounds (rect);
+        int rowHeight = (int)tableView.rowHeight ();
+        Event event = new Event ();
+        event.item = this;
+        event.index = columnIndex;
+        event.gc = gc;
+        event.x = (int)contentRect.x;
+        event.y = (int)contentRect.y;
+        event.width = width;
+        event.height = rowHeight;
+        parent.sendEvent (DWT.MeasureItem, event);
+        if (rowHeight < event.height) {
+            tableView.setRowHeight (event.height);
+        }
+        if (parent.columnCount is 0) {
+            int change = event.width - (customWidth !is -1 ? customWidth : width);
+            if (customWidth !is -1 || event.width !is width) {
+                customWidth = event.width;  
+            }
+            if (change !is 0) parent.setScrollWidth (this, false);
+        }
+        width = event.width;
+    }
     return width;
 }
 
@@ -175,37 +200,45 @@
     cellForeground = cellBackground = null;
     font = null;
     cellFont = null;
-    width = -1;
+    customWidth = -1;
 }
 
-NSAttributedString createString(int index) {
-    NSMutableDictionary dict = NSMutableDictionary.dictionaryWithCapacity(4);
+NSAttributedString createString (int index) {
+    NSMutableDictionary dict = NSMutableDictionary.dictionaryWithCapacity (4);
     Color foreground = cellForeground !is null ? cellForeground [index] : null;
     if (foreground is null) foreground = this.foreground;
     if (foreground is null) foreground = parent.foreground;
     if (foreground !is null) {
-        NSColor color = NSColor.colorWithDeviceRed(foreground.handle[0], foreground.handle[1], foreground.handle[2], 1);
-        dict.setObject(color, OS.NSForegroundColorAttributeName());
+        NSColor color = NSColor.colorWithDeviceRed (foreground.handle [0], foreground.handle [1], foreground.handle [2], 1);
+        dict.setObject(color, OS.NSForegroundColorAttributeName);
     }
     Font font = cellFont !is null ? cellFont [index] : null;
     if (font is null) font = this.font;
-//  if (font is null) font = parent.font;
+    if (font is null) font = parent.font;
     if (font !is null) {
-        dict.setObject(font.handle, OS.NSFontAttributeName());
+        dict.setObject (font.handle, OS.NSFontAttributeName);
     }
-    Color background = cellBackground !is null ? cellBackground [index] : null;
-    if (background is null) background = this.background;
-    if (background !is null) {
-        NSColor color = NSColor.colorWithDeviceRed(background.handle[0], background.handle[1], background.handle[2], 1);
-        dict.setObject(color, OS.NSBackgroundColorAttributeName());
+    NSMutableParagraphStyle paragraphStyle = (NSMutableParagraphStyle)new NSMutableParagraphStyle ().alloc ().init ();
+    paragraphStyle.autorelease ();
+    paragraphStyle.setLineBreakMode (OS.NSLineBreakByClipping);
+    dict.setObject (paragraphStyle, OS.NSParagraphStyleAttributeName);
+    if (parent.columnCount > 0) {
+        TableColumn column = parent.getColumn (index);
+        int style = column.getStyle ();
+        if ((style & DWT.CENTER) !is 0) {
+            paragraphStyle.setAlignment (OS.NSCenterTextAlignment);
+        } else if ((style & DWT.RIGHT) !is 0) {
+            paragraphStyle.setAlignment (OS.NSRightTextAlignment);
+        }
     }
+
     String text = getText (index);
-    int length = text.length();
-    char[] chars = new char[length];
+    int length = text.length ();
+    char[] chars = new char [length];
     text.getChars(0, length, chars, 0);
-    NSString str = NSString.stringWithCharacters(chars, length);
-    NSAttributedString attribStr = (cast(NSAttributedString)new NSAttributedString().alloc()).initWithString_attributes_(str, dict);
-    attribStr.autorelease();
+    NSString str = NSString.stringWithCharacters (chars, length);
+    NSAttributedString attribStr = (cast(NSAttributedString) (new NSAttributedString ()).alloc ()).initWithString (str, dict);
+    attribStr.autorelease ();
     return attribStr;
 }
 
@@ -272,9 +305,7 @@
     if (!parent.checkData (this, true)) error (DWT.ERROR_WIDGET_DISPOSED);
     NSTableView tableView = cast(NSTableView) parent.view;
     NSRect rect = tableView.rectOfRow (parent.indexOf (this));
-    rect = tableView.convertRect_toView_ (rect, parent.scrollView);
-    Rectangle result = new Rectangle(cast(int) rect.x, cast(int) rect.y, cast(int) rect.width, cast(int) rect.height);
-    return result;
+    return new Rectangle((int) rect.x, (int) rect.y, (int) rect.width, (int) rect.height);
 }
 
 /**
@@ -292,12 +323,16 @@
 public Rectangle getBounds (int index) {
     checkWidget ();
     if (!parent.checkData (this, true)) error (DWT.ERROR_WIDGET_DISPOSED);
-    NSTableView tableView = cast(NSTableView) parent.view;
-    if ((parent.style & DWT.CHECK) !is 0) index ++;
+    if (!(0 <= index && index < Math.max (1, parent.columnCount))) return new Rectangle (0, 0, 0, 0);
+
+    if (parent.columnCount is 0) {
+        index = (parent.style & DWT.CHECK) !is 0 ? 1 : 0;
+    } else {
+        TableColumn column = parent.getColumn (index);
+        index = (int)/*64*/tableView.columnWithIdentifier (column.nsColumn);
+    }
     NSRect rect = tableView.frameOfCellAtColumn (index, parent.indexOf (this));
-    rect = tableView.convertRect_toView_ (rect, parent.scrollView);
-    Rectangle result = new Rectangle(cast(int) rect.x, cast(int) rect.y, cast(int) rect.width, cast(int) rect.height);
-    return result;
+    return new Rectangle ((int) rect.x, (int) rect.y, (int) rect.width, (int) rect.height);
 }
 
 /**
@@ -421,7 +456,7 @@
 }
 
 public Image getImage () {
-    checkWidget();
+    checkWidget ();
     if (!parent.checkData (this, true)) error (DWT.ERROR_WIDGET_DISPOSED);
     return super.getImage ();
 }
@@ -439,7 +474,7 @@
  * </ul>
  */
 public Image getImage (int index) {
-    checkWidget();
+    checkWidget ();
     if (!parent.checkData (this, true)) error (DWT.ERROR_WIDGET_DISPOSED);
     if (index is 0) return getImage ();
     if (images !is null) {
@@ -463,30 +498,22 @@
  * </ul>
  */
 public Rectangle getImageBounds (int index) {
-    checkWidget();
+    checkWidget ();
     if (!parent.checkData (this, true)) error (DWT.ERROR_WIDGET_DISPOSED);
-//  parent.checkItems (true);
-//  if (index !is 0 && !(0 <= index && index < parent.columnCount)) return new Rectangle (0, 0, 0, 0);
-//  Rect rect = new Rect();
-//  int itemIndex = parent.indexOf (this);
-//  int id = itemIndex + 1;
-//  int columnId = parent.columnCount is 0 ? parent.column_id : parent.columns [index].id;
-//  if (OS.GetDataBrowserItemPartBounds (parent.handle, id, columnId, OS.kDataBrowserPropertyContentPart, rect) !is OS.noErr) {
-//      return new Rectangle (0, 0, 0, 0);
-//  }
-//  int x = rect.left, y = rect.top;
-//  int width = 0;
-//  if (index is 0 && image !is null) {
-//      Rectangle bounds = image.getBounds ();
-//      width += bounds.width;
-//  }
-//  if (index !is 0 && images !is null && images[index] !is null) {
-//      Rectangle bounds = images [index].getBounds ();
-//      width += bounds.width;
-//  }
-//  int height = rect.bottom - rect.top + 1;
-//  return new Rectangle (x, y, width, height);
-    return null;
+    if (!(0 <= index && index < Math.max (1, parent.columnCount))) return new Rectangle (0, 0, 0, 0);
+
+    NSTableView tableView = (NSTableView) parent.view;
+    Image image = index is 0 ? this.image : (images !is null) ? images [index] : null;
+    if (parent.columnCount is 0) {
+        index = (parent.style & DWT.CHECK) !is 0 ? 1 : 0;
+    } else {
+        TableColumn column = parent.getColumn (index);
+        index = (int)/*64*/tableView.columnWithIdentifier (column.nsColumn);
+    }
+    NSRect rect = tableView.frameOfCellAtColumn (index, parent.indexOf (this));
+    //TODO is this right?
+    rect.width = image !is null ? image.getBounds().width : 0; 
+    return new Rectangle((int) rect.x, (int) rect.y, (int) rect.width, (int) rect.height);
 }
 
 /**
@@ -500,7 +527,7 @@
  * </ul>
  */
 public int getImageIndent () {
-    checkWidget();
+    checkWidget ();
     if (!parent.checkData (this, true)) error (DWT.ERROR_WIDGET_DISPOSED);
     return 0;
 }
@@ -577,50 +604,30 @@
 public Rectangle getTextBounds (int index) {
     checkWidget ();
     if (!parent.checkData (this, true)) error (DWT.ERROR_WIDGET_DISPOSED);
-//  parent.checkItems (true);
-//  if (index !is 0 && !(0 <= index && index < parent.columnCount)) return new Rectangle (0, 0, 0, 0);
-//  Rect rect = new Rect();
-//  int itemIndex = parent.indexOf (this);
-//  int id = itemIndex + 1;
-//  int columnId = parent.columnCount is 0 ? parent.column_id : parent.columns [index].id;
-//  if (OS.GetDataBrowserItemPartBounds (parent.handle, id, columnId, OS.kDataBrowserPropertyEnclosingPart, rect) !is OS.noErr) {
-//      return new Rectangle (0, 0, 0, 0);
-//  }
-//  int imageWidth = 0;
-//  int margin = parent.getInsetWidth () / 2;
-//  Image image = getImage (index);
-//  if (image !is null) {
-//      Rectangle bounds = image.getBounds ();
-//      imageWidth = bounds.width + parent.getGap ();
-//  }
-//  int x, y, width, height;
-//  if (OS.VERSION >= 0x1040) {
-//      if (parent.getLinesVisible ()) {
-//          rect.left += Table.GRID_WIDTH;
-//          rect.top += Table.GRID_WIDTH;
-//      }
-//      x = rect.left + imageWidth + margin;
-//      y = rect.top;
-//      width = Math.max (0, rect.right - rect.left - imageWidth - margin * 2);
-//      height = rect.bottom - rect.top;
-//  } else {
-//      Rect rect2 = new Rect();
-//      if (OS.GetDataBrowserItemPartBounds (parent.handle, id, columnId, OS.kDataBrowserPropertyContentPart, rect2) !is OS.noErr) {
-//          return new Rectangle (0, 0, 0, 0);
-//      }
-//      x = rect2.left + imageWidth + margin;
-//      y = rect2.top;
-//      width = Math.max (0, rect.right - rect2.left + 1 - imageWidth - margin * 2);
-//      height = rect2.bottom - rect2.top + 1;
-//  }
-//  return new Rectangle (x, y, width, height);
-    return null;
+    if (!(0 <= index && index < Math.max (1, parent.columnCount))) return new Rectangle (0, 0, 0, 0);
+
+    NSTableView tableView = (NSTableView) parent.view;
+    Image image = index is 0 ? this.image : (images !is null) ? images [index] : null;
+    if (parent.columnCount is 0) {
+        index = (parent.style & DWT.CHECK) !is 0 ? 1 : 0;
+    } else {
+        TableColumn column = parent.getColumn (index);
+        index = (int)/*64*/tableView.columnWithIdentifier (column.nsColumn);
+    }
+    NSRect rect = tableView.frameOfCellAtColumn (index, parent.indexOf (this));
+    //TODO is this right?
+    if (image !is null) {
+        int imageWidth = image.getBounds().width;
+        rect.x += imageWidth;
+        rect.width -= imageWidth;
+    }
+    return new Rectangle((int) rect.x, (int) rect.y, (int) rect.width, (int) rect.height);
 }
 
 void redraw () {
 //  0[aTableView setNeedsDisplayInRect:[aTableView rectOfRow:row]];
-    (cast(NSTableView)parent.view).reloadData();
-    (cast(NSTableView)parent.view).tile();
+    (cast(NSTableView) parent.view).reloadData ();
+    (cast(NSTableView) parent.view).tile ();
 }
 
 void releaseHandle () {
@@ -670,9 +677,9 @@
     background = color;
     if (oldColor !is null && oldColor.equals (color)) return;
     cached = true;
-    NSTableView view = cast(NSTableView)parent.view;
-    NSRect rect = view.rectOfRow(parent.indexOf(this));
-    view.setNeedsDisplayInRect(rect);
+    NSTableView view = cast(NSTableView) parent.view;
+    NSRect rect = view.rectOfRow (parent.indexOf (this));
+    view.setNeedsDisplayInRect (rect);
 }
 
 /**
@@ -709,9 +716,21 @@
     cellBackground [index] = color;
     if (oldColor !is null && oldColor.equals (color)) return;
     cached = true;
-    NSTableView view = cast(NSTableView)parent.view;
-    NSRect rect = view.frameOfCellAtColumn(index + ((parent.style & DWT.CHECK) !is 0 ? 1 : 0), parent.indexOf(this));
-    view.setNeedsDisplayInRect(rect);
+
+    NSTableView tableView = (NSTableView) parent.view;
+    NSRect rect = null;
+    if (parent.hooks (DWT.MeasureItem) || parent.hooks (DWT.EraseItem) || parent.hooks (DWT.PaintItem)) {
+        rect = tableView.rectOfRow (parent.indexOf (this));
+    } else {
+        if (parent.columnCount is 0) {
+            index = (parent.style & DWT.CHECK) !is 0 ? 1 : 0;
+        } else {
+            TableColumn column = parent.getColumn (index);
+            index = (int)/*64*/tableView.columnWithIdentifier (column.nsColumn);
+        }
+        rect = tableView.frameOfCellAtColumn (index, parent.indexOf (this));
+    }
+    tableView.setNeedsDisplayInRect (rect);
 }
 
 /**
@@ -731,9 +750,9 @@
     if (this.checked is checked) return;
     this.checked = checked;
     cached = true;
-    NSTableView view = cast(NSTableView)parent.view;
-    NSRect rect = view.rectOfRow(parent.indexOf(this));
-    view.setNeedsDisplayInRect(rect);
+    NSTableView view = cast(NSTableView) parent.view;
+    NSRect rect = view.rectOfRow (parent.indexOf (this));
+    view.setNeedsDisplayInRect (rect);
 }
 
 /**
@@ -763,9 +782,9 @@
     this.font = font;
     if (oldFont !is null && oldFont.equals (font)) return;
     cached = true;
-    NSTableView view = cast(NSTableView)parent.view;
-    NSRect rect = view.rectOfRow(parent.indexOf(this));
-    view.setNeedsDisplayInRect(rect);
+    NSTableView view = cast(NSTableView) parent.view;
+    NSRect rect = view.rectOfRow (parent.indexOf (this));
+    view.setNeedsDisplayInRect (rect);
 }
 
 /**
@@ -803,9 +822,21 @@
     cellFont [index] = font;
     if (oldFont !is null && oldFont.equals (font)) return;
     cached = true;
-    NSTableView view = cast(NSTableView)parent.view;
-    NSRect rect = view.frameOfCellAtColumn(index + ((parent.style & DWT.CHECK) !is 0 ? 1 : 0), parent.indexOf(this));
-    view.setNeedsDisplayInRect(rect);
+
+    NSTableView tableView = (NSTableView) parent.view;
+    NSRect rect = null;
+    if (parent.hooks (DWT.MeasureItem) || parent.hooks (DWT.EraseItem) || parent.hooks (DWT.PaintItem)) {
+        rect = tableView.rectOfRow (parent.indexOf (this));
+    } else {
+        if (parent.columnCount is 0) {
+            index = (parent.style & DWT.CHECK) !is 0 ? 1 : 0;
+        } else {
+            TableColumn column = parent.getColumn (index);
+            index = (int)/*64*/tableView.columnWithIdentifier (column.nsColumn);
+        }
+        rect = tableView.frameOfCellAtColumn (index, parent.indexOf (this));
+    }
+    tableView.setNeedsDisplayInRect (rect);
 }
 
 /**
@@ -835,9 +866,9 @@
     foreground = color;
     if (oldColor !is null && oldColor.equals (color)) return;
     cached = true;
-    NSTableView view = cast(NSTableView)parent.view;
-    NSRect rect = view.rectOfRow(parent.indexOf(this));
-    view.setNeedsDisplayInRect(rect);
+    NSTableView view = cast(NSTableView) parent.view;
+    NSRect rect = view.rectOfRow (parent.indexOf (this));
+    view.setNeedsDisplayInRect (rect);
 }
 
 /**
@@ -858,7 +889,7 @@
  * 
  * @since 3.0
  */
-public void setForeground (int index, Color color){
+public void setForeground (int index, Color color) {
     checkWidget ();
     if (color !is null && color.isDisposed ()) {
         DWT.error (DWT.ERROR_INVALID_ARGUMENT);
@@ -874,9 +905,21 @@
     cellForeground [index] = color;
     if (oldColor !is null && oldColor.equals (color)) return;
     cached = true;
-    NSTableView view = cast(NSTableView)parent.view;
-    NSRect rect = view.frameOfCellAtColumn(index + ((parent.style & DWT.CHECK) !is 0 ? 1 : 0), parent.indexOf(this));
-    view.setNeedsDisplayInRect(rect);
+
+    NSTableView tableView = (NSTableView) parent.view;
+    NSRect rect = null;
+    if (parent.hooks (DWT.MeasureItem) || parent.hooks (DWT.EraseItem) || parent.hooks (DWT.PaintItem)) {
+        rect = tableView.rectOfRow (parent.indexOf (this));
+    } else {
+        if (parent.columnCount is 0) {
+            index = (parent.style & DWT.CHECK) !is 0 ? 1 : 0;
+        } else {
+            TableColumn column = parent.getColumn (index);
+            index = (int)/*64*/tableView.columnWithIdentifier (column.nsColumn);
+        }
+        rect = tableView.frameOfCellAtColumn (index, parent.indexOf (this));
+    }
+    tableView.setNeedsDisplayInRect (rect);
 }
 
 /**
@@ -896,9 +939,9 @@
     if (this.grayed is grayed) return;
     this.grayed = grayed;
     cached = true;
-    NSTableView view = cast(NSTableView)parent.view;
-    NSRect rect = view.rectOfRow(parent.indexOf(this));
-    view.setNeedsDisplayInRect(rect);
+    NSTableView view = cast(NSTableView) parent.view;
+    NSRect rect = view.rectOfRow (parent.indexOf (this));
+    view.setNeedsDisplayInRect (rect);
 }
 
 /**
@@ -916,7 +959,7 @@
  * </ul>
  */
 public void setImage (Image [] images) {
-    checkWidget();
+    checkWidget ();
     if (images is null) error (DWT.ERROR_NULL_ARGUMENT);
     for (int i=0; i<images.length; i++) {
         setImage (i, images [i]);
@@ -938,7 +981,7 @@
  * </ul>
  */
 public void setImage (int index, Image image) {
-    checkWidget();
+    checkWidget ();
     if (image !is null && image.isDisposed ()) {
         error(DWT.ERROR_INVALID_ARGUMENT);
     }
@@ -951,7 +994,7 @@
         if (image !is null && image.type is DWT.ICON) {
             if (image.equals (this.image)) return;
         }
-        width = -1;
+        customWidth = -1;
         super.setImage (image);
     }
     int count = Math.max (1, parent.columnCount);
@@ -964,9 +1007,21 @@
     }
 //  cached = true;
 //  if (index is 0) parent.setScrollWidth (this);
-    NSTableView view = cast(NSTableView)parent.view;
-    NSRect rect = view.frameOfCellAtColumn(index + ((parent.style & DWT.CHECK) !is 0 ? 1 : 0), parent.indexOf(this));
-    view.setNeedsDisplayInRect(rect);
+    
+    NSTableView tableView = (NSTableView) parent.view;
+    NSRect rect = null;
+    if (parent.hooks (DWT.MeasureItem) || parent.hooks (DWT.EraseItem) || parent.hooks (DWT.PaintItem)) {
+        rect = tableView.rectOfRow (parent.indexOf (this));
+    } else {
+        if (parent.columnCount is 0) {
+            index = (parent.style & DWT.CHECK) !is 0 ? 1 : 0;
+        } else {
+            TableColumn column = parent.getColumn (index);
+            index = (int)/*64*/tableView.columnWithIdentifier (column.nsColumn);
+        }
+        rect = tableView.frameOfCellAtColumn (index, parent.indexOf (this));
+    }
+    tableView.setNeedsDisplayInRect (rect);
 }
 
 public void setImage (Image image) {
@@ -988,7 +1043,7 @@
  * @deprecated this functionality is not supported on most platforms
  */
 public void setImageIndent (int indent) {
-    checkWidget();
+    checkWidget ();
     if (indent < 0) return;
     cached = true;
     /* Image indent is not supported on the Macintosh */
@@ -1008,7 +1063,7 @@
  * </ul>
  */
 public void setText (String [] strings) {
-    checkWidget();
+    checkWidget ();
     if (strings is null) error (DWT.ERROR_NULL_ARGUMENT);
     for (int i=0; i<strings.length; i++) {
         String string = strings [i];
@@ -1031,11 +1086,11 @@
  * </ul>
  */
 public void setText (int index, String string) {
-    checkWidget();
+    checkWidget ();
     if (string is null) error (DWT.ERROR_NULL_ARGUMENT);
     if (index is 0) {
         if (string.equals (text)) return;
-        width = -1;
+        customWidth = -1;
         super.setText (string);
     }
     int count = Math.max (1, parent.columnCount);
@@ -1045,14 +1100,26 @@
         strings [index] = string;
     }
     cached = true;
-    if (index is 0) parent.setScrollWidth (this);
-    NSTableView view = cast(NSTableView)parent.view;
-    NSRect rect = view.frameOfCellAtColumn(index + ((parent.style & DWT.CHECK) !is 0 ? 1 : 0), parent.indexOf(this));
-    view.setNeedsDisplayInRect(rect);
+    if (index is 0) parent.setScrollWidth (this, true);
+
+    NSTableView tableView = (NSTableView) parent.view;
+    NSRect rect = null;
+    if (parent.hooks (DWT.MeasureItem) || parent.hooks (DWT.EraseItem) || parent.hooks (DWT.PaintItem)) {
+        rect = tableView.rectOfRow (parent.indexOf (this));
+    } else {
+        if (parent.columnCount is 0) {
+            index = (parent.style & DWT.CHECK) !is 0 ? 1 : 0;
+        } else {
+            TableColumn column = parent.getColumn (index);
+            index = (int)/*64*/tableView.columnWithIdentifier (column.nsColumn);
+        }
+        rect = tableView.frameOfCellAtColumn (index, parent.indexOf (this));
+    }
+    tableView.setNeedsDisplayInRect (rect);
 }
 
 public void setText (String string) {
-    checkWidget();
+    checkWidget ();
     setText (0, string);
 }