changeset 81:97f1b638de63

Ported dwt.widgets.TableColumn
author Jacob Carlborg <doob@me.com>
date Sun, 28 Dec 2008 17:56:45 +0100
parents b24476d6dedf
children 2d895a357833
files dwt/dwthelper/utils.d dwt/widgets/TableColumn.d
diffstat 2 files changed, 36 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/dwt/dwthelper/utils.d	Wed Dec 24 22:50:11 2008 +0100
+++ b/dwt/dwthelper/utils.d	Sun Dec 28 17:56:45 2008 +0100
@@ -267,8 +267,7 @@
     public static float NEGATIVE_INFINITY = ((-1.0f) / 0.0f);
     public static float NaN = (0.0f / 0.0f);
     public static float MAX_VALUE = 3.4028235e+38f;
-    public static float MIN_VALUE = float.min;
-    //public static float MIN_VALUE = 1.4e-45f;    
+    public static float MIN_VALUE = 1.4e-45f;    
     public static int SIZE = 32;
 
     this( float value ){
--- a/dwt/widgets/TableColumn.d	Wed Dec 24 22:50:11 2008 +0100
+++ b/dwt/widgets/TableColumn.d	Sun Dec 28 17:56:45 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.TableColumn;
 
@@ -35,6 +38,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.Table;
+import dwt.widgets.TypedListener;
+
 /**
  * Instances of this class represent a column in a table widget.
  * <p><dl>
@@ -57,7 +66,7 @@
     NSTableColumn nsColumn;
     String toolTipText, displayText;
 
-    static final int MARGIN = 2;
+    static const int MARGIN = 2;
 
 /**
  * Constructs a new instance of this class given its parent
@@ -217,9 +226,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 table does not reach the
@@ -228,8 +237,8 @@
      * right edge and the table's right edge.  If this case is detected then
      * nothing should be drawn.
      */
-    NSTableView tableView = (NSTableView)parent.view;
-    int columnIndex = (int)/*64*/tableView.columnWithIdentifier (nsColumn);
+    NSTableView tableView = cast(NSTableView)parent.view;
+    NSInteger columnIndex = tableView.columnWithIdentifier (nsColumn);
     NSRect headerRect = parent.headerView.headerRectOfColumn (columnIndex);
     if (headerRect.x !is cellRect.x || headerRect.width !is cellRect.width) return;
 
@@ -237,18 +246,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 */
@@ -268,20 +277,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 ();
@@ -289,7 +298,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);
@@ -299,7 +308,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);
@@ -450,7 +459,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);
@@ -462,7 +471,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;
@@ -577,10 +586,10 @@
     if (index is -1 || index is 0) return;
     style &= ~(DWT.LEFT | DWT.RIGHT | DWT.CENTER);
     style |= alignment & (DWT.LEFT | DWT.RIGHT | DWT.CENTER);
-    NSTableView tableView = ((NSTableView) parent.view);
+    NSTableView tableView = (cast(NSTableView) parent.view);
     NSTableHeaderView headerView = tableView.headerView ();
     if (headerView is null) return;
-    index = (int)/*64*/tableView.columnWithIdentifier (nsColumn);
+    NSInteger = tableView.columnWithIdentifier (nsColumn);
     NSRect rect = headerView.headerRectOfColumn (index);
     headerView.setNeedsDisplayInRect (rect);
     rect = tableView.rectOfColumn (index);
@@ -593,9 +602,9 @@
         error (DWT.ERROR_INVALID_ARGUMENT);
     }
     super.setImage (image);
-    NSTableHeaderView headerView = ((NSTableView) parent.view).headerView ();
+    NSTableHeaderView headerView = (cast(NSTableView) parent.view).headerView ();
     if (headerView is null) return;
-    int /*long*/ index = ((NSTableView)parent.view).columnWithIdentifier (nsColumn);
+    NSInteger index = (cast(NSTableView)parent.view).columnWithIdentifier (nsColumn);
     NSRect rect = headerView.headerRectOfColumn (index);
     headerView.setNeedsDisplayInRect (rect);
 }
@@ -625,7 +634,7 @@
     checkWidget ();
     // TODO how to make only some columns movable?  And handle moveable is false.
     if (moveable) {
-        ((NSTableView)parent.view).setAllowsColumnReordering (true);
+        (cast(NSTableView)parent.view).setAllowsColumnReordering (true);
     }
 //  int [] flags = new int [1];
 //  OS.GetDataBrowserPropertyFlags (parent.handle, id, flags);
@@ -663,12 +672,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 = ((NSTableView) parent.view).headerView ();
+    NSTableHeaderView headerView = (cast(NSTableView) parent.view).headerView ();
     if (headerView is null) return;
-    int /*long*/ index = ((NSTableView)parent.view).columnWithIdentifier (nsColumn);
+    NSInteger index = (cast(NSTableView)parent.view).columnWithIdentifier (nsColumn);
     NSRect rect = headerView.headerRectOfColumn (index);
     headerView.setNeedsDisplayInRect (rect);
 }