Mercurial > projects > dwt-mac
changeset 82:2d895a357833
Ported dwt.widgets.TableItem
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Sun, 28 Dec 2008 18:14:40 +0100 |
parents | 97f1b638de63 |
children | 681769fb5a7a |
files | dwt/widgets/TableItem.d |
diffstat | 1 files changed, 49 insertions(+), 38 deletions(-) [+] |
line wrap: on
line diff
--- a/dwt/widgets/TableItem.d Sun Dec 28 17:56:45 2008 +0100 +++ b/dwt/widgets/TableItem.d Sun Dec 28 18:14:40 2008 +0100 @@ -7,6 +7,9 @@ * * Contributors: * IBM Corporation - initial API and implementation + * + * Port to the D programming language: + * Jacob Carlborg <doob@me.com> *******************************************************************************/ module dwt.widgets.TableItem; @@ -31,6 +34,13 @@ import dwt.internal.cocoa.NSTableView; import dwt.internal.cocoa.OS; +import dwt.internal.objc.cocoa.Cocoa; +import objc = dwt.internal.objc.runtime; +import dwt.widgets.Event; +import dwt.widgets.Item; +import dwt.widgets.Table; +import dwt.widgets.TableColumn; + /** * Instances of this class represent a selectable user interface object * that represents an item in a table. @@ -147,27 +157,27 @@ cell.setTitle (NSString.stringWith (getText (columnIndex))); Image image = getImage (columnIndex); cell.setImage (image !is null ? image.handle : null); - NSRect rect = new NSRect (); + NSRect rect = NSRect (); rect.width = rect.height = Float.MAX_VALUE; NSSize size = cell.cellSizeForBounds (rect); - int width = (int)Math.ceil (size.width); + int width = cast(int)Math.ceil (size.width); if (callMeasureItem && parent.hooks (DWT.MeasureItem)) { - NSTableView tableView = (NSTableView)parent.view; - int nsColumnIndex = 0; + NSTableView tableView = cast(NSTableView)parent.view; + NSInteger 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 (); + int rowHeight = cast(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.x = cast(int)contentRect.x; + event.y = cast(int)contentRect.y; event.width = width; event.height = rowHeight; parent.sendEvent (DWT.MeasureItem, event); @@ -218,7 +228,7 @@ if (font !is null) { dict.setObject (font.handle, OS.NSFontAttributeName); } - NSMutableParagraphStyle paragraphStyle = (NSMutableParagraphStyle)new NSMutableParagraphStyle ().alloc ().init (); + NSMutableParagraphStyle paragraphStyle = cast(NSMutableParagraphStyle)(new NSMutableParagraphStyle ()).alloc ().init (); paragraphStyle.autorelease (); paragraphStyle.setLineBreakMode (OS.NSLineBreakByClipping); dict.setObject (paragraphStyle, OS.NSParagraphStyleAttributeName); @@ -233,10 +243,10 @@ } String text = getText (index); - int length = text.length (); - char[] chars = new char [length]; - text.getChars(0, length, chars, 0); - NSString str = NSString.stringWithCharacters (chars, length); + size_t length_ = text.length (); + char[] chars = new char [length_]; + text.getChars(0, length_, chars, 0); + NSString str = NSString.stringWithCharacters (chars.toString16().ptr, length_); NSAttributedString attribStr = (cast(NSAttributedString) (new NSAttributedString ()).alloc ()).initWithString (str, dict); attribStr.autorelease (); return attribStr; @@ -305,7 +315,7 @@ if (!parent.checkData (this, true)) error (DWT.ERROR_WIDGET_DISPOSED); NSTableView tableView = cast(NSTableView) parent.view; NSRect rect = tableView.rectOfRow (parent.indexOf (this)); - return new Rectangle((int) rect.x, (int) rect.y, (int) rect.width, (int) rect.height); + return new Rectangle(cast(int) rect.x, cast(int) rect.y, cast(int) rect.width, cast(int) rect.height); } /** @@ -325,14 +335,15 @@ if (!parent.checkData (this, true)) error (DWT.ERROR_WIDGET_DISPOSED); if (!(0 <= index && index < Math.max (1, parent.columnCount))) return new Rectangle (0, 0, 0, 0); + NSTableView tableView = cast(NSTableView) parent.view; 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); + index = cast(int)/*64*/tableView.columnWithIdentifier (column.nsColumn); } NSRect rect = tableView.frameOfCellAtColumn (index, parent.indexOf (this)); - return new Rectangle ((int) rect.x, (int) rect.y, (int) rect.width, (int) rect.height); + return new Rectangle (cast(int) rect.x, cast(int) rect.y, cast(int) rect.width, cast(int) rect.height); } /** @@ -502,18 +513,18 @@ if (!parent.checkData (this, true)) error (DWT.ERROR_WIDGET_DISPOSED); if (!(0 <= index && index < Math.max (1, parent.columnCount))) return new Rectangle (0, 0, 0, 0); - NSTableView tableView = (NSTableView) parent.view; + NSTableView tableView = cast(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); + index = cast(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); + return new Rectangle(cast(int) rect.x, cast(int) rect.y, cast(int) rect.width, cast(int) rect.height); } /** @@ -606,22 +617,22 @@ if (!parent.checkData (this, true)) error (DWT.ERROR_WIDGET_DISPOSED); if (!(0 <= index && index < Math.max (1, parent.columnCount))) return new Rectangle (0, 0, 0, 0); - NSTableView tableView = (NSTableView) parent.view; + NSTableView tableView = cast(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); + index = cast(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; + rect.origin.x += imageWidth; + rect.size.width -= imageWidth; } - return new Rectangle((int) rect.x, (int) rect.y, (int) rect.width, (int) rect.height); + return new Rectangle(cast(int) rect.x, cast(int) rect.y, cast(int) rect.width, cast(int) rect.height); } void redraw () { @@ -717,8 +728,8 @@ if (oldColor !is null && oldColor.equals (color)) return; cached = true; - NSTableView tableView = (NSTableView) parent.view; - NSRect rect = null; + NSTableView tableView = cast(NSTableView) parent.view; + NSRect rect; if (parent.hooks (DWT.MeasureItem) || parent.hooks (DWT.EraseItem) || parent.hooks (DWT.PaintItem)) { rect = tableView.rectOfRow (parent.indexOf (this)); } else { @@ -726,7 +737,7 @@ index = (parent.style & DWT.CHECK) !is 0 ? 1 : 0; } else { TableColumn column = parent.getColumn (index); - index = (int)/*64*/tableView.columnWithIdentifier (column.nsColumn); + index = cast(int)/*64*/tableView.columnWithIdentifier (column.nsColumn); } rect = tableView.frameOfCellAtColumn (index, parent.indexOf (this)); } @@ -823,8 +834,8 @@ if (oldFont !is null && oldFont.equals (font)) return; cached = true; - NSTableView tableView = (NSTableView) parent.view; - NSRect rect = null; + NSTableView tableView = cast(NSTableView) parent.view; + NSRect rect; if (parent.hooks (DWT.MeasureItem) || parent.hooks (DWT.EraseItem) || parent.hooks (DWT.PaintItem)) { rect = tableView.rectOfRow (parent.indexOf (this)); } else { @@ -832,7 +843,7 @@ index = (parent.style & DWT.CHECK) !is 0 ? 1 : 0; } else { TableColumn column = parent.getColumn (index); - index = (int)/*64*/tableView.columnWithIdentifier (column.nsColumn); + index = cast(int)/*64*/tableView.columnWithIdentifier (column.nsColumn); } rect = tableView.frameOfCellAtColumn (index, parent.indexOf (this)); } @@ -906,8 +917,8 @@ if (oldColor !is null && oldColor.equals (color)) return; cached = true; - NSTableView tableView = (NSTableView) parent.view; - NSRect rect = null; + NSTableView tableView = cast(NSTableView) parent.view; + NSRect rect; if (parent.hooks (DWT.MeasureItem) || parent.hooks (DWT.EraseItem) || parent.hooks (DWT.PaintItem)) { rect = tableView.rectOfRow (parent.indexOf (this)); } else { @@ -915,7 +926,7 @@ index = (parent.style & DWT.CHECK) !is 0 ? 1 : 0; } else { TableColumn column = parent.getColumn (index); - index = (int)/*64*/tableView.columnWithIdentifier (column.nsColumn); + index = cast(int)/*64*/tableView.columnWithIdentifier (column.nsColumn); } rect = tableView.frameOfCellAtColumn (index, parent.indexOf (this)); } @@ -1008,8 +1019,8 @@ // cached = true; // if (index is 0) parent.setScrollWidth (this); - NSTableView tableView = (NSTableView) parent.view; - NSRect rect = null; + NSTableView tableView = cast(NSTableView) parent.view; + NSRect rect; if (parent.hooks (DWT.MeasureItem) || parent.hooks (DWT.EraseItem) || parent.hooks (DWT.PaintItem)) { rect = tableView.rectOfRow (parent.indexOf (this)); } else { @@ -1017,7 +1028,7 @@ index = (parent.style & DWT.CHECK) !is 0 ? 1 : 0; } else { TableColumn column = parent.getColumn (index); - index = (int)/*64*/tableView.columnWithIdentifier (column.nsColumn); + index = cast(int)/*64*/tableView.columnWithIdentifier (column.nsColumn); } rect = tableView.frameOfCellAtColumn (index, parent.indexOf (this)); } @@ -1102,8 +1113,8 @@ cached = true; if (index is 0) parent.setScrollWidth (this, true); - NSTableView tableView = (NSTableView) parent.view; - NSRect rect = null; + NSTableView tableView = cast(NSTableView) parent.view; + NSRect rect; if (parent.hooks (DWT.MeasureItem) || parent.hooks (DWT.EraseItem) || parent.hooks (DWT.PaintItem)) { rect = tableView.rectOfRow (parent.indexOf (this)); } else { @@ -1111,7 +1122,7 @@ index = (parent.style & DWT.CHECK) !is 0 ? 1 : 0; } else { TableColumn column = parent.getColumn (index); - index = (int)/*64*/tableView.columnWithIdentifier (column.nsColumn); + index = cast(int)/*64*/tableView.columnWithIdentifier (column.nsColumn); } rect = tableView.frameOfCellAtColumn (index, parent.indexOf (this)); }