comparison 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
comparison
equal deleted inserted replaced
44:ca5e494f2bbf 45:d8635bb48c7c
1 /******************************************************************************* 1 /*******************************************************************************
2 * Copyright (c) 2000, 2007 IBM Corporation and others. 2 * Copyright (c) 2000, 2008 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials 3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0 4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at 5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html 6 * http://www.eclipse.org/legal/epl-v10.html
7 * 7 *
19 import dwt.graphics.Font; 19 import dwt.graphics.Font;
20 import dwt.graphics.GC; 20 import dwt.graphics.GC;
21 import dwt.graphics.Image; 21 import dwt.graphics.Image;
22 import dwt.graphics.Rectangle; 22 import dwt.graphics.Rectangle;
23 import dwt.internal.cocoa.NSAttributedString; 23 import dwt.internal.cocoa.NSAttributedString;
24 import dwt.internal.cocoa.NSBrowserCell;
24 import dwt.internal.cocoa.NSColor; 25 import dwt.internal.cocoa.NSColor;
25 import dwt.internal.cocoa.NSMutableDictionary; 26 import dwt.internal.cocoa.NSMutableDictionary;
27 import dwt.internal.cocoa.NSMutableParagraphStyle;
26 import dwt.internal.cocoa.NSRect; 28 import dwt.internal.cocoa.NSRect;
29 import dwt.internal.cocoa.NSSize;
27 import dwt.internal.cocoa.NSString; 30 import dwt.internal.cocoa.NSString;
28 import dwt.internal.cocoa.NSTableView; 31 import dwt.internal.cocoa.NSTableView;
29 import dwt.internal.cocoa.OS; 32 import dwt.internal.cocoa.OS;
30 33
31 /** 34 /**
38 * <dd>(none)</dd> 41 * <dd>(none)</dd>
39 * </dl> 42 * </dl>
40 * <p> 43 * <p>
41 * IMPORTANT: This class is <em>not</em> intended to be subclassed. 44 * IMPORTANT: This class is <em>not</em> intended to be subclassed.
42 * </p> 45 * </p>
46 *
47 * @see <a href="http://www.eclipse.org/swt/snippets/#table">Table, TableItem, TableColumn snippets</a>
48 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
43 */ 49 */
44 public class TableItem : Item { 50 public class TableItem : Item {
45 Table parent; 51 Table parent;
46 String [] strings; 52 String [] strings;
47 Image [] images; 53 Image [] images;
48 bool checked, grayed, cached; 54 bool checked, grayed, cached;
49 Color foreground, background; 55 Color foreground, background;
50 Color[] cellForeground, cellBackground; 56 Color[] cellForeground, cellBackground;
51 Font font; 57 Font font;
52 Font[] cellFont; 58 Font[] cellFont;
53 int width = -1; 59 int customWidth = -1;
54 60
55 /** 61 /**
56 * Constructs a new instance of this class given its parent 62 * Constructs a new instance of this class given its parent
57 * (which must be a <code>Table</code>) and a style value 63 * (which must be a <code>Table</code>) and a style value
58 * describing its behavior and appearance. The item is added 64 * describing its behavior and appearance. The item is added
131 static Table checkNull (Table control) { 137 static Table checkNull (Table control) {
132 if (control is null) DWT.error (DWT.ERROR_NULL_ARGUMENT); 138 if (control is null) DWT.error (DWT.ERROR_NULL_ARGUMENT);
133 return control; 139 return control;
134 } 140 }
135 141
136 int calculateWidth (int index, GC gc) { 142 int calculateWidth (int columnIndex, GC gc, bool callMeasureItem) {
137 if (index is 0 && width !is -1) return width; 143 if (!callMeasureItem && customWidth !is -1) return customWidth;
138 int width = 0; 144
139 Image image = getImage (index); 145 NSBrowserCell cell = parent.dataCell;
140 String text = getText (index); 146 cell.setFont (getFont (columnIndex).handle);
141 gc.setFont (getFont (index)); 147 cell.setTitle (NSString.stringWith (getText (columnIndex)));
142 // if (image !is null) width += image.getBounds ().width + parent.getGap (); 148 Image image = getImage (columnIndex);
143 if (text !is null && text.length () > 0) width += gc.stringExtent (text).x; 149 cell.setImage (image !is null ? image.handle : null);
144 // if (parent.hooks (DWT.MeasureItem)) { 150 NSRect rect = new NSRect ();
145 // Event event = new Event (); 151 rect.width = rect.height = Float.MAX_VALUE;
146 // event.item = this; 152 NSSize size = cell.cellSizeForBounds (rect);
147 // event.index = index; 153 int width = (int)Math.ceil (size.width);
148 // event.gc = gc; 154
149 // short [] height = new short [1]; 155 if (callMeasureItem && parent.hooks (DWT.MeasureItem)) {
150 // OS.GetDataBrowserTableViewRowHeight (parent.handle, height); 156 NSTableView tableView = (NSTableView)parent.view;
151 // event.width = width; 157 int nsColumnIndex = 0;
152 // event.height = height[0]; 158 if (parent.columnCount > 0) {
153 // parent.sendEvent (DWT.MeasureItem, event); 159 nsColumnIndex = tableView.columnWithIdentifier (parent.columns[columnIndex].nsColumn);
154 // if (parent.itemHeight < event.height) { 160 }
155 // parent.itemHeight = event.height; 161 int rowIndex = parent.indexOf (this);
156 // OS.SetDataBrowserTableViewRowHeight (parent.handle, cast(short) event.height); 162 rect = tableView.frameOfCellAtColumn (nsColumnIndex, rowIndex);
157 // } 163 NSRect contentRect = cell.titleRectForBounds (rect);
158 // width = event.width; 164 int rowHeight = (int)tableView.rowHeight ();
159 // } 165 Event event = new Event ();
160 if (index is 0) this.width = width; 166 event.item = this;
167 event.index = columnIndex;
168 event.gc = gc;
169 event.x = (int)contentRect.x;
170 event.y = (int)contentRect.y;
171 event.width = width;
172 event.height = rowHeight;
173 parent.sendEvent (DWT.MeasureItem, event);
174 if (rowHeight < event.height) {
175 tableView.setRowHeight (event.height);
176 }
177 if (parent.columnCount is 0) {
178 int change = event.width - (customWidth !is -1 ? customWidth : width);
179 if (customWidth !is -1 || event.width !is width) {
180 customWidth = event.width;
181 }
182 if (change !is 0) parent.setScrollWidth (this, false);
183 }
184 width = event.width;
185 }
161 return width; 186 return width;
162 } 187 }
163 188
164 protected void checkSubclass () { 189 protected void checkSubclass () {
165 if (!isValidSubclass ()) error (DWT.ERROR_INVALID_SUBCLASS); 190 if (!isValidSubclass ()) error (DWT.ERROR_INVALID_SUBCLASS);
173 checked = grayed = cached = false; 198 checked = grayed = cached = false;
174 foreground = background = null; 199 foreground = background = null;
175 cellForeground = cellBackground = null; 200 cellForeground = cellBackground = null;
176 font = null; 201 font = null;
177 cellFont = null; 202 cellFont = null;
178 width = -1; 203 customWidth = -1;
179 } 204 }
180 205
181 NSAttributedString createString(int index) { 206 NSAttributedString createString (int index) {
182 NSMutableDictionary dict = NSMutableDictionary.dictionaryWithCapacity(4); 207 NSMutableDictionary dict = NSMutableDictionary.dictionaryWithCapacity (4);
183 Color foreground = cellForeground !is null ? cellForeground [index] : null; 208 Color foreground = cellForeground !is null ? cellForeground [index] : null;
184 if (foreground is null) foreground = this.foreground; 209 if (foreground is null) foreground = this.foreground;
185 if (foreground is null) foreground = parent.foreground; 210 if (foreground is null) foreground = parent.foreground;
186 if (foreground !is null) { 211 if (foreground !is null) {
187 NSColor color = NSColor.colorWithDeviceRed(foreground.handle[0], foreground.handle[1], foreground.handle[2], 1); 212 NSColor color = NSColor.colorWithDeviceRed (foreground.handle [0], foreground.handle [1], foreground.handle [2], 1);
188 dict.setObject(color, OS.NSForegroundColorAttributeName()); 213 dict.setObject(color, OS.NSForegroundColorAttributeName);
189 } 214 }
190 Font font = cellFont !is null ? cellFont [index] : null; 215 Font font = cellFont !is null ? cellFont [index] : null;
191 if (font is null) font = this.font; 216 if (font is null) font = this.font;
192 // if (font is null) font = parent.font; 217 if (font is null) font = parent.font;
193 if (font !is null) { 218 if (font !is null) {
194 dict.setObject(font.handle, OS.NSFontAttributeName()); 219 dict.setObject (font.handle, OS.NSFontAttributeName);
195 } 220 }
196 Color background = cellBackground !is null ? cellBackground [index] : null; 221 NSMutableParagraphStyle paragraphStyle = (NSMutableParagraphStyle)new NSMutableParagraphStyle ().alloc ().init ();
197 if (background is null) background = this.background; 222 paragraphStyle.autorelease ();
198 if (background !is null) { 223 paragraphStyle.setLineBreakMode (OS.NSLineBreakByClipping);
199 NSColor color = NSColor.colorWithDeviceRed(background.handle[0], background.handle[1], background.handle[2], 1); 224 dict.setObject (paragraphStyle, OS.NSParagraphStyleAttributeName);
200 dict.setObject(color, OS.NSBackgroundColorAttributeName()); 225 if (parent.columnCount > 0) {
201 } 226 TableColumn column = parent.getColumn (index);
227 int style = column.getStyle ();
228 if ((style & DWT.CENTER) !is 0) {
229 paragraphStyle.setAlignment (OS.NSCenterTextAlignment);
230 } else if ((style & DWT.RIGHT) !is 0) {
231 paragraphStyle.setAlignment (OS.NSRightTextAlignment);
232 }
233 }
234
202 String text = getText (index); 235 String text = getText (index);
203 int length = text.length(); 236 int length = text.length ();
204 char[] chars = new char[length]; 237 char[] chars = new char [length];
205 text.getChars(0, length, chars, 0); 238 text.getChars(0, length, chars, 0);
206 NSString str = NSString.stringWithCharacters(chars, length); 239 NSString str = NSString.stringWithCharacters (chars, length);
207 NSAttributedString attribStr = (cast(NSAttributedString)new NSAttributedString().alloc()).initWithString_attributes_(str, dict); 240 NSAttributedString attribStr = (cast(NSAttributedString) (new NSAttributedString ()).alloc ()).initWithString (str, dict);
208 attribStr.autorelease(); 241 attribStr.autorelease ();
209 return attribStr; 242 return attribStr;
210 } 243 }
211 244
212 void destroyWidget () { 245 void destroyWidget () {
213 parent.destroyItem (this); 246 parent.destroyItem (this);
270 public Rectangle getBounds () { 303 public Rectangle getBounds () {
271 checkWidget (); 304 checkWidget ();
272 if (!parent.checkData (this, true)) error (DWT.ERROR_WIDGET_DISPOSED); 305 if (!parent.checkData (this, true)) error (DWT.ERROR_WIDGET_DISPOSED);
273 NSTableView tableView = cast(NSTableView) parent.view; 306 NSTableView tableView = cast(NSTableView) parent.view;
274 NSRect rect = tableView.rectOfRow (parent.indexOf (this)); 307 NSRect rect = tableView.rectOfRow (parent.indexOf (this));
275 rect = tableView.convertRect_toView_ (rect, parent.scrollView); 308 return new Rectangle((int) rect.x, (int) rect.y, (int) rect.width, (int) rect.height);
276 Rectangle result = new Rectangle(cast(int) rect.x, cast(int) rect.y, cast(int) rect.width, cast(int) rect.height);
277 return result;
278 } 309 }
279 310
280 /** 311 /**
281 * Returns a rectangle describing the receiver's size and location 312 * Returns a rectangle describing the receiver's size and location
282 * relative to its parent at a column in the table. 313 * relative to its parent at a column in the table.
290 * </ul> 321 * </ul>
291 */ 322 */
292 public Rectangle getBounds (int index) { 323 public Rectangle getBounds (int index) {
293 checkWidget (); 324 checkWidget ();
294 if (!parent.checkData (this, true)) error (DWT.ERROR_WIDGET_DISPOSED); 325 if (!parent.checkData (this, true)) error (DWT.ERROR_WIDGET_DISPOSED);
295 NSTableView tableView = cast(NSTableView) parent.view; 326 if (!(0 <= index && index < Math.max (1, parent.columnCount))) return new Rectangle (0, 0, 0, 0);
296 if ((parent.style & DWT.CHECK) !is 0) index ++; 327
328 if (parent.columnCount is 0) {
329 index = (parent.style & DWT.CHECK) !is 0 ? 1 : 0;
330 } else {
331 TableColumn column = parent.getColumn (index);
332 index = (int)/*64*/tableView.columnWithIdentifier (column.nsColumn);
333 }
297 NSRect rect = tableView.frameOfCellAtColumn (index, parent.indexOf (this)); 334 NSRect rect = tableView.frameOfCellAtColumn (index, parent.indexOf (this));
298 rect = tableView.convertRect_toView_ (rect, parent.scrollView); 335 return new Rectangle ((int) rect.x, (int) rect.y, (int) rect.width, (int) rect.height);
299 Rectangle result = new Rectangle(cast(int) rect.x, cast(int) rect.y, cast(int) rect.width, cast(int) rect.height);
300 return result;
301 } 336 }
302 337
303 /** 338 /**
304 * Returns <code>true</code> if the receiver is checked, 339 * Returns <code>true</code> if the receiver is checked,
305 * and false otherwise. When the parent does not have 340 * and false otherwise. When the parent does not have
419 if ((parent.style & DWT.CHECK) is 0) return false; 454 if ((parent.style & DWT.CHECK) is 0) return false;
420 return grayed; 455 return grayed;
421 } 456 }
422 457
423 public Image getImage () { 458 public Image getImage () {
424 checkWidget(); 459 checkWidget ();
425 if (!parent.checkData (this, true)) error (DWT.ERROR_WIDGET_DISPOSED); 460 if (!parent.checkData (this, true)) error (DWT.ERROR_WIDGET_DISPOSED);
426 return super.getImage (); 461 return super.getImage ();
427 } 462 }
428 463
429 /** 464 /**
437 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> 472 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
438 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 473 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
439 * </ul> 474 * </ul>
440 */ 475 */
441 public Image getImage (int index) { 476 public Image getImage (int index) {
442 checkWidget(); 477 checkWidget ();
443 if (!parent.checkData (this, true)) error (DWT.ERROR_WIDGET_DISPOSED); 478 if (!parent.checkData (this, true)) error (DWT.ERROR_WIDGET_DISPOSED);
444 if (index is 0) return getImage (); 479 if (index is 0) return getImage ();
445 if (images !is null) { 480 if (images !is null) {
446 if (0 <= index && index < images.length) return images [index]; 481 if (0 <= index && index < images.length) return images [index];
447 } 482 }
461 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> 496 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
462 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 497 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
463 * </ul> 498 * </ul>
464 */ 499 */
465 public Rectangle getImageBounds (int index) { 500 public Rectangle getImageBounds (int index) {
466 checkWidget(); 501 checkWidget ();
467 if (!parent.checkData (this, true)) error (DWT.ERROR_WIDGET_DISPOSED); 502 if (!parent.checkData (this, true)) error (DWT.ERROR_WIDGET_DISPOSED);
468 // parent.checkItems (true); 503 if (!(0 <= index && index < Math.max (1, parent.columnCount))) return new Rectangle (0, 0, 0, 0);
469 // if (index !is 0 && !(0 <= index && index < parent.columnCount)) return new Rectangle (0, 0, 0, 0); 504
470 // Rect rect = new Rect(); 505 NSTableView tableView = (NSTableView) parent.view;
471 // int itemIndex = parent.indexOf (this); 506 Image image = index is 0 ? this.image : (images !is null) ? images [index] : null;
472 // int id = itemIndex + 1; 507 if (parent.columnCount is 0) {
473 // int columnId = parent.columnCount is 0 ? parent.column_id : parent.columns [index].id; 508 index = (parent.style & DWT.CHECK) !is 0 ? 1 : 0;
474 // if (OS.GetDataBrowserItemPartBounds (parent.handle, id, columnId, OS.kDataBrowserPropertyContentPart, rect) !is OS.noErr) { 509 } else {
475 // return new Rectangle (0, 0, 0, 0); 510 TableColumn column = parent.getColumn (index);
476 // } 511 index = (int)/*64*/tableView.columnWithIdentifier (column.nsColumn);
477 // int x = rect.left, y = rect.top; 512 }
478 // int width = 0; 513 NSRect rect = tableView.frameOfCellAtColumn (index, parent.indexOf (this));
479 // if (index is 0 && image !is null) { 514 //TODO is this right?
480 // Rectangle bounds = image.getBounds (); 515 rect.width = image !is null ? image.getBounds().width : 0;
481 // width += bounds.width; 516 return new Rectangle((int) rect.x, (int) rect.y, (int) rect.width, (int) rect.height);
482 // }
483 // if (index !is 0 && images !is null && images[index] !is null) {
484 // Rectangle bounds = images [index].getBounds ();
485 // width += bounds.width;
486 // }
487 // int height = rect.bottom - rect.top + 1;
488 // return new Rectangle (x, y, width, height);
489 return null;
490 } 517 }
491 518
492 /** 519 /**
493 * Gets the image indent. 520 * Gets the image indent.
494 * 521 *
498 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> 525 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
499 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 526 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
500 * </ul> 527 * </ul>
501 */ 528 */
502 public int getImageIndent () { 529 public int getImageIndent () {
503 checkWidget(); 530 checkWidget ();
504 if (!parent.checkData (this, true)) error (DWT.ERROR_WIDGET_DISPOSED); 531 if (!parent.checkData (this, true)) error (DWT.ERROR_WIDGET_DISPOSED);
505 return 0; 532 return 0;
506 } 533 }
507 534
508 String getNameText () { 535 String getNameText () {
575 * @since 3.3 602 * @since 3.3
576 */ 603 */
577 public Rectangle getTextBounds (int index) { 604 public Rectangle getTextBounds (int index) {
578 checkWidget (); 605 checkWidget ();
579 if (!parent.checkData (this, true)) error (DWT.ERROR_WIDGET_DISPOSED); 606 if (!parent.checkData (this, true)) error (DWT.ERROR_WIDGET_DISPOSED);
580 // parent.checkItems (true); 607 if (!(0 <= index && index < Math.max (1, parent.columnCount))) return new Rectangle (0, 0, 0, 0);
581 // if (index !is 0 && !(0 <= index && index < parent.columnCount)) return new Rectangle (0, 0, 0, 0); 608
582 // Rect rect = new Rect(); 609 NSTableView tableView = (NSTableView) parent.view;
583 // int itemIndex = parent.indexOf (this); 610 Image image = index is 0 ? this.image : (images !is null) ? images [index] : null;
584 // int id = itemIndex + 1; 611 if (parent.columnCount is 0) {
585 // int columnId = parent.columnCount is 0 ? parent.column_id : parent.columns [index].id; 612 index = (parent.style & DWT.CHECK) !is 0 ? 1 : 0;
586 // if (OS.GetDataBrowserItemPartBounds (parent.handle, id, columnId, OS.kDataBrowserPropertyEnclosingPart, rect) !is OS.noErr) { 613 } else {
587 // return new Rectangle (0, 0, 0, 0); 614 TableColumn column = parent.getColumn (index);
588 // } 615 index = (int)/*64*/tableView.columnWithIdentifier (column.nsColumn);
589 // int imageWidth = 0; 616 }
590 // int margin = parent.getInsetWidth () / 2; 617 NSRect rect = tableView.frameOfCellAtColumn (index, parent.indexOf (this));
591 // Image image = getImage (index); 618 //TODO is this right?
592 // if (image !is null) { 619 if (image !is null) {
593 // Rectangle bounds = image.getBounds (); 620 int imageWidth = image.getBounds().width;
594 // imageWidth = bounds.width + parent.getGap (); 621 rect.x += imageWidth;
595 // } 622 rect.width -= imageWidth;
596 // int x, y, width, height; 623 }
597 // if (OS.VERSION >= 0x1040) { 624 return new Rectangle((int) rect.x, (int) rect.y, (int) rect.width, (int) rect.height);
598 // if (parent.getLinesVisible ()) {
599 // rect.left += Table.GRID_WIDTH;
600 // rect.top += Table.GRID_WIDTH;
601 // }
602 // x = rect.left + imageWidth + margin;
603 // y = rect.top;
604 // width = Math.max (0, rect.right - rect.left - imageWidth - margin * 2);
605 // height = rect.bottom - rect.top;
606 // } else {
607 // Rect rect2 = new Rect();
608 // if (OS.GetDataBrowserItemPartBounds (parent.handle, id, columnId, OS.kDataBrowserPropertyContentPart, rect2) !is OS.noErr) {
609 // return new Rectangle (0, 0, 0, 0);
610 // }
611 // x = rect2.left + imageWidth + margin;
612 // y = rect2.top;
613 // width = Math.max (0, rect.right - rect2.left + 1 - imageWidth - margin * 2);
614 // height = rect2.bottom - rect2.top + 1;
615 // }
616 // return new Rectangle (x, y, width, height);
617 return null;
618 } 625 }
619 626
620 void redraw () { 627 void redraw () {
621 // 0[aTableView setNeedsDisplayInRect:[aTableView rectOfRow:row]]; 628 // 0[aTableView setNeedsDisplayInRect:[aTableView rectOfRow:row]];
622 (cast(NSTableView)parent.view).reloadData(); 629 (cast(NSTableView) parent.view).reloadData ();
623 (cast(NSTableView)parent.view).tile(); 630 (cast(NSTableView) parent.view).tile ();
624 } 631 }
625 632
626 void releaseHandle () { 633 void releaseHandle () {
627 super.releaseHandle (); 634 super.releaseHandle ();
628 parent = null; 635 parent = null;
668 Color oldColor = background; 675 Color oldColor = background;
669 if (oldColor is color) return; 676 if (oldColor is color) return;
670 background = color; 677 background = color;
671 if (oldColor !is null && oldColor.equals (color)) return; 678 if (oldColor !is null && oldColor.equals (color)) return;
672 cached = true; 679 cached = true;
673 NSTableView view = cast(NSTableView)parent.view; 680 NSTableView view = cast(NSTableView) parent.view;
674 NSRect rect = view.rectOfRow(parent.indexOf(this)); 681 NSRect rect = view.rectOfRow (parent.indexOf (this));
675 view.setNeedsDisplayInRect(rect); 682 view.setNeedsDisplayInRect (rect);
676 } 683 }
677 684
678 /** 685 /**
679 * Sets the background color at the given column index in the receiver 686 * Sets the background color at the given column index in the receiver
680 * to the color specified by the argument, or to the default system color for the item 687 * to the color specified by the argument, or to the default system color for the item
707 Color oldColor = cellBackground [index]; 714 Color oldColor = cellBackground [index];
708 if (oldColor is color) return; 715 if (oldColor is color) return;
709 cellBackground [index] = color; 716 cellBackground [index] = color;
710 if (oldColor !is null && oldColor.equals (color)) return; 717 if (oldColor !is null && oldColor.equals (color)) return;
711 cached = true; 718 cached = true;
712 NSTableView view = cast(NSTableView)parent.view; 719
713 NSRect rect = view.frameOfCellAtColumn(index + ((parent.style & DWT.CHECK) !is 0 ? 1 : 0), parent.indexOf(this)); 720 NSTableView tableView = (NSTableView) parent.view;
714 view.setNeedsDisplayInRect(rect); 721 NSRect rect = null;
722 if (parent.hooks (DWT.MeasureItem) || parent.hooks (DWT.EraseItem) || parent.hooks (DWT.PaintItem)) {
723 rect = tableView.rectOfRow (parent.indexOf (this));
724 } else {
725 if (parent.columnCount is 0) {
726 index = (parent.style & DWT.CHECK) !is 0 ? 1 : 0;
727 } else {
728 TableColumn column = parent.getColumn (index);
729 index = (int)/*64*/tableView.columnWithIdentifier (column.nsColumn);
730 }
731 rect = tableView.frameOfCellAtColumn (index, parent.indexOf (this));
732 }
733 tableView.setNeedsDisplayInRect (rect);
715 } 734 }
716 735
717 /** 736 /**
718 * Sets the checked state of the checkbox for this item. This state change 737 * Sets the checked state of the checkbox for this item. This state change
719 * only applies if the Table was created with the DWT.CHECK style. 738 * only applies if the Table was created with the DWT.CHECK style.
729 checkWidget (); 748 checkWidget ();
730 if ((parent.style & DWT.CHECK) is 0) return; 749 if ((parent.style & DWT.CHECK) is 0) return;
731 if (this.checked is checked) return; 750 if (this.checked is checked) return;
732 this.checked = checked; 751 this.checked = checked;
733 cached = true; 752 cached = true;
734 NSTableView view = cast(NSTableView)parent.view; 753 NSTableView view = cast(NSTableView) parent.view;
735 NSRect rect = view.rectOfRow(parent.indexOf(this)); 754 NSRect rect = view.rectOfRow (parent.indexOf (this));
736 view.setNeedsDisplayInRect(rect); 755 view.setNeedsDisplayInRect (rect);
737 } 756 }
738 757
739 /** 758 /**
740 * Sets the font that the receiver will use to paint textual information 759 * Sets the font that the receiver will use to paint textual information
741 * for this item to the font specified by the argument, or to the default font 760 * for this item to the font specified by the argument, or to the default font
761 Font oldFont = this.font; 780 Font oldFont = this.font;
762 if (oldFont is font) return; 781 if (oldFont is font) return;
763 this.font = font; 782 this.font = font;
764 if (oldFont !is null && oldFont.equals (font)) return; 783 if (oldFont !is null && oldFont.equals (font)) return;
765 cached = true; 784 cached = true;
766 NSTableView view = cast(NSTableView)parent.view; 785 NSTableView view = cast(NSTableView) parent.view;
767 NSRect rect = view.rectOfRow(parent.indexOf(this)); 786 NSRect rect = view.rectOfRow (parent.indexOf (this));
768 view.setNeedsDisplayInRect(rect); 787 view.setNeedsDisplayInRect (rect);
769 } 788 }
770 789
771 /** 790 /**
772 * Sets the font that the receiver will use to paint textual information 791 * Sets the font that the receiver will use to paint textual information
773 * for the specified cell in this item to the font specified by the 792 * for the specified cell in this item to the font specified by the
801 Font oldFont = cellFont [index]; 820 Font oldFont = cellFont [index];
802 if (oldFont is font) return; 821 if (oldFont is font) return;
803 cellFont [index] = font; 822 cellFont [index] = font;
804 if (oldFont !is null && oldFont.equals (font)) return; 823 if (oldFont !is null && oldFont.equals (font)) return;
805 cached = true; 824 cached = true;
806 NSTableView view = cast(NSTableView)parent.view; 825
807 NSRect rect = view.frameOfCellAtColumn(index + ((parent.style & DWT.CHECK) !is 0 ? 1 : 0), parent.indexOf(this)); 826 NSTableView tableView = (NSTableView) parent.view;
808 view.setNeedsDisplayInRect(rect); 827 NSRect rect = null;
828 if (parent.hooks (DWT.MeasureItem) || parent.hooks (DWT.EraseItem) || parent.hooks (DWT.PaintItem)) {
829 rect = tableView.rectOfRow (parent.indexOf (this));
830 } else {
831 if (parent.columnCount is 0) {
832 index = (parent.style & DWT.CHECK) !is 0 ? 1 : 0;
833 } else {
834 TableColumn column = parent.getColumn (index);
835 index = (int)/*64*/tableView.columnWithIdentifier (column.nsColumn);
836 }
837 rect = tableView.frameOfCellAtColumn (index, parent.indexOf (this));
838 }
839 tableView.setNeedsDisplayInRect (rect);
809 } 840 }
810 841
811 /** 842 /**
812 * Sets the receiver's foreground color to the color specified 843 * Sets the receiver's foreground color to the color specified
813 * by the argument, or to the default system color for the item 844 * by the argument, or to the default system color for the item
833 Color oldColor = foreground; 864 Color oldColor = foreground;
834 if (oldColor is color) return; 865 if (oldColor is color) return;
835 foreground = color; 866 foreground = color;
836 if (oldColor !is null && oldColor.equals (color)) return; 867 if (oldColor !is null && oldColor.equals (color)) return;
837 cached = true; 868 cached = true;
838 NSTableView view = cast(NSTableView)parent.view; 869 NSTableView view = cast(NSTableView) parent.view;
839 NSRect rect = view.rectOfRow(parent.indexOf(this)); 870 NSRect rect = view.rectOfRow (parent.indexOf (this));
840 view.setNeedsDisplayInRect(rect); 871 view.setNeedsDisplayInRect (rect);
841 } 872 }
842 873
843 /** 874 /**
844 * Sets the foreground color at the given column index in the receiver 875 * Sets the foreground color at the given column index in the receiver
845 * to the color specified by the argument, or to the default system color for the item 876 * to the color specified by the argument, or to the default system color for the item
856 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 887 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
857 * </ul> 888 * </ul>
858 * 889 *
859 * @since 3.0 890 * @since 3.0
860 */ 891 */
861 public void setForeground (int index, Color color){ 892 public void setForeground (int index, Color color) {
862 checkWidget (); 893 checkWidget ();
863 if (color !is null && color.isDisposed ()) { 894 if (color !is null && color.isDisposed ()) {
864 DWT.error (DWT.ERROR_INVALID_ARGUMENT); 895 DWT.error (DWT.ERROR_INVALID_ARGUMENT);
865 } 896 }
866 int count = Math.max (1, parent.columnCount); 897 int count = Math.max (1, parent.columnCount);
872 Color oldColor = cellForeground [index]; 903 Color oldColor = cellForeground [index];
873 if (oldColor is color) return; 904 if (oldColor is color) return;
874 cellForeground [index] = color; 905 cellForeground [index] = color;
875 if (oldColor !is null && oldColor.equals (color)) return; 906 if (oldColor !is null && oldColor.equals (color)) return;
876 cached = true; 907 cached = true;
877 NSTableView view = cast(NSTableView)parent.view; 908
878 NSRect rect = view.frameOfCellAtColumn(index + ((parent.style & DWT.CHECK) !is 0 ? 1 : 0), parent.indexOf(this)); 909 NSTableView tableView = (NSTableView) parent.view;
879 view.setNeedsDisplayInRect(rect); 910 NSRect rect = null;
911 if (parent.hooks (DWT.MeasureItem) || parent.hooks (DWT.EraseItem) || parent.hooks (DWT.PaintItem)) {
912 rect = tableView.rectOfRow (parent.indexOf (this));
913 } else {
914 if (parent.columnCount is 0) {
915 index = (parent.style & DWT.CHECK) !is 0 ? 1 : 0;
916 } else {
917 TableColumn column = parent.getColumn (index);
918 index = (int)/*64*/tableView.columnWithIdentifier (column.nsColumn);
919 }
920 rect = tableView.frameOfCellAtColumn (index, parent.indexOf (this));
921 }
922 tableView.setNeedsDisplayInRect (rect);
880 } 923 }
881 924
882 /** 925 /**
883 * Sets the grayed state of the checkbox for this item. This state change 926 * Sets the grayed state of the checkbox for this item. This state change
884 * only applies if the Table was created with the DWT.CHECK style. 927 * only applies if the Table was created with the DWT.CHECK style.
894 checkWidget (); 937 checkWidget ();
895 if ((parent.style & DWT.CHECK) is 0) return; 938 if ((parent.style & DWT.CHECK) is 0) return;
896 if (this.grayed is grayed) return; 939 if (this.grayed is grayed) return;
897 this.grayed = grayed; 940 this.grayed = grayed;
898 cached = true; 941 cached = true;
899 NSTableView view = cast(NSTableView)parent.view; 942 NSTableView view = cast(NSTableView) parent.view;
900 NSRect rect = view.rectOfRow(parent.indexOf(this)); 943 NSRect rect = view.rectOfRow (parent.indexOf (this));
901 view.setNeedsDisplayInRect(rect); 944 view.setNeedsDisplayInRect (rect);
902 } 945 }
903 946
904 /** 947 /**
905 * Sets the image for multiple columns in the table. 948 * Sets the image for multiple columns in the table.
906 * 949 *
914 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> 957 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
915 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 958 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
916 * </ul> 959 * </ul>
917 */ 960 */
918 public void setImage (Image [] images) { 961 public void setImage (Image [] images) {
919 checkWidget(); 962 checkWidget ();
920 if (images is null) error (DWT.ERROR_NULL_ARGUMENT); 963 if (images is null) error (DWT.ERROR_NULL_ARGUMENT);
921 for (int i=0; i<images.length; i++) { 964 for (int i=0; i<images.length; i++) {
922 setImage (i, images [i]); 965 setImage (i, images [i]);
923 } 966 }
924 } 967 }
936 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> 979 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
937 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 980 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
938 * </ul> 981 * </ul>
939 */ 982 */
940 public void setImage (int index, Image image) { 983 public void setImage (int index, Image image) {
941 checkWidget(); 984 checkWidget ();
942 if (image !is null && image.isDisposed ()) { 985 if (image !is null && image.isDisposed ()) {
943 error(DWT.ERROR_INVALID_ARGUMENT); 986 error(DWT.ERROR_INVALID_ARGUMENT);
944 } 987 }
945 int itemIndex = parent.indexOf (this); 988 int itemIndex = parent.indexOf (this);
946 if (itemIndex is -1) return; 989 if (itemIndex is -1) return;
949 // } 992 // }
950 if (index is 0) { 993 if (index is 0) {
951 if (image !is null && image.type is DWT.ICON) { 994 if (image !is null && image.type is DWT.ICON) {
952 if (image.equals (this.image)) return; 995 if (image.equals (this.image)) return;
953 } 996 }
954 width = -1; 997 customWidth = -1;
955 super.setImage (image); 998 super.setImage (image);
956 } 999 }
957 int count = Math.max (1, parent.columnCount); 1000 int count = Math.max (1, parent.columnCount);
958 if (0 <= index && index < count) { 1001 if (0 <= index && index < count) {
959 if (images is null) images = new Image [count]; 1002 if (images is null) images = new Image [count];
962 } 1005 }
963 images [index] = image; 1006 images [index] = image;
964 } 1007 }
965 // cached = true; 1008 // cached = true;
966 // if (index is 0) parent.setScrollWidth (this); 1009 // if (index is 0) parent.setScrollWidth (this);
967 NSTableView view = cast(NSTableView)parent.view; 1010
968 NSRect rect = view.frameOfCellAtColumn(index + ((parent.style & DWT.CHECK) !is 0 ? 1 : 0), parent.indexOf(this)); 1011 NSTableView tableView = (NSTableView) parent.view;
969 view.setNeedsDisplayInRect(rect); 1012 NSRect rect = null;
1013 if (parent.hooks (DWT.MeasureItem) || parent.hooks (DWT.EraseItem) || parent.hooks (DWT.PaintItem)) {
1014 rect = tableView.rectOfRow (parent.indexOf (this));
1015 } else {
1016 if (parent.columnCount is 0) {
1017 index = (parent.style & DWT.CHECK) !is 0 ? 1 : 0;
1018 } else {
1019 TableColumn column = parent.getColumn (index);
1020 index = (int)/*64*/tableView.columnWithIdentifier (column.nsColumn);
1021 }
1022 rect = tableView.frameOfCellAtColumn (index, parent.indexOf (this));
1023 }
1024 tableView.setNeedsDisplayInRect (rect);
970 } 1025 }
971 1026
972 public void setImage (Image image) { 1027 public void setImage (Image image) {
973 checkWidget (); 1028 checkWidget ();
974 setImage (0, image); 1029 setImage (0, image);
986 * </ul> 1041 * </ul>
987 * 1042 *
988 * @deprecated this functionality is not supported on most platforms 1043 * @deprecated this functionality is not supported on most platforms
989 */ 1044 */
990 public void setImageIndent (int indent) { 1045 public void setImageIndent (int indent) {
991 checkWidget(); 1046 checkWidget ();
992 if (indent < 0) return; 1047 if (indent < 0) return;
993 cached = true; 1048 cached = true;
994 /* Image indent is not supported on the Macintosh */ 1049 /* Image indent is not supported on the Macintosh */
995 } 1050 }
996 1051
1006 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> 1061 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
1007 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 1062 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1008 * </ul> 1063 * </ul>
1009 */ 1064 */
1010 public void setText (String [] strings) { 1065 public void setText (String [] strings) {
1011 checkWidget(); 1066 checkWidget ();
1012 if (strings is null) error (DWT.ERROR_NULL_ARGUMENT); 1067 if (strings is null) error (DWT.ERROR_NULL_ARGUMENT);
1013 for (int i=0; i<strings.length; i++) { 1068 for (int i=0; i<strings.length; i++) {
1014 String string = strings [i]; 1069 String string = strings [i];
1015 if (string !is null) setText (i, string); 1070 if (string !is null) setText (i, string);
1016 } 1071 }
1029 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> 1084 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
1030 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 1085 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1031 * </ul> 1086 * </ul>
1032 */ 1087 */
1033 public void setText (int index, String string) { 1088 public void setText (int index, String string) {
1034 checkWidget(); 1089 checkWidget ();
1035 if (string is null) error (DWT.ERROR_NULL_ARGUMENT); 1090 if (string is null) error (DWT.ERROR_NULL_ARGUMENT);
1036 if (index is 0) { 1091 if (index is 0) {
1037 if (string.equals (text)) return; 1092 if (string.equals (text)) return;
1038 width = -1; 1093 customWidth = -1;
1039 super.setText (string); 1094 super.setText (string);
1040 } 1095 }
1041 int count = Math.max (1, parent.columnCount); 1096 int count = Math.max (1, parent.columnCount);
1042 if (0 <= index && index < count) { 1097 if (0 <= index && index < count) {
1043 if (strings is null) strings = new String [count]; 1098 if (strings is null) strings = new String [count];
1044 if (string.equals (strings [index])) return; 1099 if (string.equals (strings [index])) return;
1045 strings [index] = string; 1100 strings [index] = string;
1046 } 1101 }
1047 cached = true; 1102 cached = true;
1048 if (index is 0) parent.setScrollWidth (this); 1103 if (index is 0) parent.setScrollWidth (this, true);
1049 NSTableView view = cast(NSTableView)parent.view; 1104
1050 NSRect rect = view.frameOfCellAtColumn(index + ((parent.style & DWT.CHECK) !is 0 ? 1 : 0), parent.indexOf(this)); 1105 NSTableView tableView = (NSTableView) parent.view;
1051 view.setNeedsDisplayInRect(rect); 1106 NSRect rect = null;
1107 if (parent.hooks (DWT.MeasureItem) || parent.hooks (DWT.EraseItem) || parent.hooks (DWT.PaintItem)) {
1108 rect = tableView.rectOfRow (parent.indexOf (this));
1109 } else {
1110 if (parent.columnCount is 0) {
1111 index = (parent.style & DWT.CHECK) !is 0 ? 1 : 0;
1112 } else {
1113 TableColumn column = parent.getColumn (index);
1114 index = (int)/*64*/tableView.columnWithIdentifier (column.nsColumn);
1115 }
1116 rect = tableView.frameOfCellAtColumn (index, parent.indexOf (this));
1117 }
1118 tableView.setNeedsDisplayInRect (rect);
1052 } 1119 }
1053 1120
1054 public void setText (String string) { 1121 public void setText (String string) {
1055 checkWidget(); 1122 checkWidget ();
1056 setText (0, string); 1123 setText (0, string);
1057 } 1124 }
1058 1125
1059 } 1126 }