Mercurial > projects > dwt-mac
changeset 88:6c56264306a6
Ported dwt.widgets.TreeColumn
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Tue, 30 Dec 2008 16:44:02 +0100 |
parents | 4e8317766ba0 |
children | 8e3c85e1733d |
files | dwt/widgets/TreeColumn.d |
diffstat | 1 files changed, 32 insertions(+), 26 deletions(-) [+] |
line wrap: on
line diff
--- a/dwt/widgets/TreeColumn.d Tue Dec 30 16:22:25 2008 +0100 +++ b/dwt/widgets/TreeColumn.d Tue Dec 30 16:44:02 2008 +0100 @@ -35,6 +35,12 @@ import dwt.internal.cocoa.NSView; import dwt.internal.cocoa.OS; +import dwt.internal.objc.cocoa.Cocoa; +import objc = dwt.internal.objc.runtime; +import dwt.widgets.Item; +import dwt.widgets.Tree; +import dwt.widgets.TypedListener; + /** * Instances of this class represent a column in a tree widget. * <p><dl> @@ -59,7 +65,7 @@ Tree parent; String toolTipText, displayText; - static final int MARGIN = 2; + static const int MARGIN = 2; /** * Constructs a new instance of this class given its parent @@ -219,9 +225,9 @@ releaseHandle (); } -void drawInteriorWithFrame_inView (int /*long*/ id, int /*long*/ sel, int /*long*/ cellFrame, int /*long*/ view) { - NSRect cellRect = new NSRect (); - OS.memmove (cellRect, cellFrame, NSRect.sizeof); +void drawInteriorWithFrame_inView (objc.id id, objc.SEL sel, objc.id cellFrame, objc.id view) { + NSRect cellRect = NSRect (); + OS.memmove (&cellRect, cellFrame, NSRect.sizeof); /* * Feature in Cocoa. When the last column in a tree does not reach the @@ -230,8 +236,8 @@ * right edge and the tree's right edge. If this case is detected then * nothing should be drawn. */ - NSOutlineView outlineView = (NSOutlineView)parent.view; - int columnIndex = (int)/*64*/outlineView.columnWithIdentifier (nsColumn); + NSOutlineView outlineView = cast(NSOutlineView)parent.view; + NSInteger columnIndex = outlineView.columnWithIdentifier (nsColumn); NSRect headerRect = parent.headerView.headerRectOfColumn (columnIndex); if (headerRect.x !is cellRect.x || headerRect.width !is cellRect.width) return; @@ -239,18 +245,18 @@ context.saveGraphicsState (); int contentWidth = 0; - NSSize stringSize = null, imageSize = null; + NSSize stringSize, imageSize; NSAttributedString attrString = null; NSTableHeaderCell headerCell = nsColumn.headerCell (); if (displayText !is null) { NSMutableDictionary dict = NSMutableDictionary.dictionaryWithCapacity(4); dict.setObject (headerCell.font (), 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); NSString string = NSString.stringWith (displayText); - attrString = ((NSAttributedString)new NSAttributedString ().alloc ()).initWithString (string, dict); + attrString = (cast(NSAttributedString)(new NSAttributedString ()).alloc ()).initWithString (string, dict); stringSize = attrString.size (); contentWidth += Math.ceil (stringSize.width); if (image !is null) contentWidth += MARGIN; /* space between image and text */ @@ -270,20 +276,20 @@ int drawX = 0; if ((style & DWT.CENTER) !is 0) { - drawX = (int)(cellRect.x + Math.max (MARGIN, ((cellRect.width - contentWidth) / 2))); + drawX = cast(int)(cellRect.x + Math.max (MARGIN, ((cellRect.width - contentWidth) / 2))); } else if ((style & DWT.RIGHT) !is 0) { - drawX = (int)(cellRect.x + Math.max (MARGIN, cellRect.width - contentWidth - MARGIN)); + drawX = cast(int)(cellRect.x + Math.max (MARGIN, cellRect.width - contentWidth - MARGIN)); } else { - drawX = (int)cellRect.x + MARGIN; + drawX = cast(int)cellRect.x + MARGIN; } if (image !is null) { - NSRect destRect = new NSRect (); + NSRect destRect = NSRect (); destRect.x = drawX; destRect.y = cellRect.y; destRect.width = Math.min (imageSize.width, cellRect.width - 2 * MARGIN); destRect.height = Math.min (imageSize.height, cellRect.height); - bool isFlipped = new NSView (view).isFlipped(); + bool isFlipped = (new NSView (view)).isFlipped(); if (isFlipped) { context.saveGraphicsState (); NSAffineTransform transform = NSAffineTransform.transform (); @@ -291,7 +297,7 @@ transform.translateXBy (0, -(destRect.height + 2 * destRect.y)); transform.concat (); } - NSRect sourceRect = new NSRect (); + NSRect sourceRect = NSRect (); sourceRect.width = destRect.width; sourceRect.height = destRect.height; image.handle.drawInRect (destRect, sourceRect, OS.NSCompositeSourceOver, 1f); @@ -301,7 +307,7 @@ if (displayText !is null && displayText.length () > 0) { if (image !is null) drawX += MARGIN; /* space between image and text */ - NSRect destRect = new NSRect (); + NSRect destRect = NSRect (); destRect.x = drawX; destRect.y = cellRect.y; destRect.width = Math.min (stringSize.width, cellRect.x + cellRect.width - MARGIN - drawX); @@ -452,7 +458,7 @@ NSTableHeaderCell headerCell = nsColumn.headerCell (); dict.setObject (headerCell.font (), OS.NSFontAttributeName); NSString string = NSString.stringWith (displayText); - NSAttributedString attrString = ((NSAttributedString)new NSAttributedString ().alloc ()).initWithString (string, dict); + NSAttributedString attrString = (cast(NSAttributedString)(new NSAttributedString ()).alloc ()).initWithString (string, dict); NSSize stringSize = attrString.size (); attrString.release (); width += Math.ceil (stringSize.width); @@ -464,7 +470,7 @@ } if (parent.sortColumn is this && parent.sortDirection !is DWT.NONE) { NSTableHeaderCell headerCell = nsColumn.headerCell (); - NSRect rect = new NSRect (); + NSRect rect = NSRect (); rect.width = rect.height = Float.MAX_VALUE; NSSize cellSize = headerCell.cellSizeForBounds (rect); rect.height = cellSize.height; @@ -579,10 +585,10 @@ if (index is -1 || index is 0) return; style &= ~(DWT.LEFT | DWT.RIGHT | DWT.CENTER); style |= alignment & (DWT.LEFT | DWT.RIGHT | DWT.CENTER); - NSOutlineView outlineView = ((NSOutlineView) parent.view); + NSOutlineView outlineView = (cast(NSOutlineView) parent.view); NSTableHeaderView headerView = outlineView.headerView (); if (headerView is null) return; - index = (int)/*64*/outlineView.columnWithIdentifier (nsColumn); + NSInteger = outlineView.columnWithIdentifier (nsColumn); NSRect rect = headerView.headerRectOfColumn (index); headerView.setNeedsDisplayInRect (rect); rect = outlineView.rectOfColumn (index); @@ -595,9 +601,9 @@ error (DWT.ERROR_INVALID_ARGUMENT); } super.setImage (image); - NSTableHeaderView headerView = ((NSOutlineView) parent.view).headerView (); + NSTableHeaderView headerView = (cast(NSOutlineView) parent.view).headerView (); if (headerView is null) return; - int /*long*/ index = ((NSOutlineView)parent.view).columnWithIdentifier (nsColumn); + NSInteger index = (cast(NSOutlineView)parent.view).columnWithIdentifier (nsColumn); NSRect rect = headerView.headerRectOfColumn (index); headerView.setNeedsDisplayInRect (rect); } @@ -627,7 +633,7 @@ checkWidget (); // TODO how to make only some columns movable? And handle moveable is false. if (moveable) { - ((NSOutlineView)parent.view).setAllowsColumnReordering (true); + (cast(NSOutlineView)parent.view).setAllowsColumnReordering (true); } // int [] flags = new int [1]; // OS.GetDataBrowserPropertyFlags (parent.handle, id, flags); @@ -663,12 +669,12 @@ char [] buffer = new char [text.length ()]; text.getChars (0, buffer.length, buffer, 0); int length = fixMnemonic (buffer); - displayText = new String (buffer, 0, length); + displayText = new_String (buffer, 0, length); NSString title = NSString.stringWith (displayText); nsColumn.headerCell ().setTitle (title); - NSTableHeaderView headerView = ((NSOutlineView) parent.view).headerView (); + NSTableHeaderView headerView = (cast(NSOutlineView) parent.view).headerView (); if (headerView is null) return; - int /*long*/ index = ((NSOutlineView)parent.view).columnWithIdentifier (nsColumn); + NSInteger index = (cast(NSOutlineView)parent.view).columnWithIdentifier (nsColumn); NSRect rect = headerView.headerRectOfColumn (index); headerView.setNeedsDisplayInRect (rect); }