changeset 130:3d4579727e0e

Fixes #2 and #3
author Jacob Carlborg <doob@me.com>
date Tue, 10 Feb 2009 21:01:24 +0100
parents ad4e1fe71a5a
children 03fac5984741
files dwt/custom/CCombo.d dwt/custom/PopupList.d dwt/dwthelper/array.d dwt/dwthelper/utils.d dwt/internal/Compatibility.d dwt/internal/cocoa/OS.d dwt/printing/Printer.d dwt/widgets/TabItem.d dwt/widgets/Table.d
diffstat 9 files changed, 72 insertions(+), 51 deletions(-) [+]
line wrap: on
line diff
--- a/dwt/custom/CCombo.d	Sun Jan 18 18:39:46 2009 +0100
+++ b/dwt/custom/CCombo.d	Tue Feb 10 21:01:24 2009 +0100
@@ -134,26 +134,40 @@
     if ((style & DWT.FLAT) !is 0) arrowStyle |= DWT.FLAT;
     arrow = new Button (this, arrowStyle);
 
-    listener = new class() Listener {
+    listener = new class(text, list, popup, arrow) Listener {
+
+        Text text;
+        List list;
+        Shell popup;
+        Button arrow;
+
+        this (Text text, List list, Shell popup, Button arrow)
+        {
+            this.text = text;
+            this.list = list;
+            this.popup = popup;
+            this.arrow = arrow;
+        }
+
         public void handleEvent (Event event) {
             if (popup is event.widget) {
-                popupEvent (event);
+                this.outer.popupEvent (event);
                 return;
             }
             if (text is event.widget) {
-                textEvent (event);
+                this.outer.textEvent (event);
                 return;
             }
             if (list is event.widget) {
-                listEvent (event);
+                this.outer.listEvent (event);
                 return;
             }
             if (arrow is event.widget) {
-                arrowEvent (event);
+                this.outer.arrowEvent (event);
                 return;
             }
             if (this.outer is event.widget) {
-                comboEvent (event);
+                this.outer.comboEvent (event);
                 return;
             }
             if (getShell () is event.widget) {
--- a/dwt/custom/PopupList.d	Sun Jan 18 18:39:46 2009 +0100
+++ b/dwt/custom/PopupList.d	Tue Feb 10 21:01:24 2009 +0100
@@ -32,6 +32,8 @@
 import dwt.widgets.Listener;
 import dwt.widgets.Shell;
 
+import tango.text.Util;
+
 /**
 * A PopupList is a list of selectable items that appears in its own shell positioned above
 * its parent shell.  It is used for selecting items when editing a Table cell (similar to the
--- a/dwt/dwthelper/array.d	Sun Jan 18 18:39:46 2009 +0100
+++ b/dwt/dwthelper/array.d	Tue Feb 10 21:01:24 2009 +0100
@@ -205,10 +205,6 @@
 {
     assert(start >= 0);
 }
-out (result)
-{
-    assert(result >= -1 && result < arr.length);
-}
 body
 {
     size_t index = tango.text.Util.locatePattern(arr, match, start);
@@ -239,10 +235,6 @@
 {
     assert(start >= 0);
 }
-out (result)
-{
-    assert(result >= -1 && result < arr.length);
-}
 body
 {
     size_t index;
--- a/dwt/dwthelper/utils.d	Sun Jan 18 18:39:46 2009 +0100
+++ b/dwt/dwthelper/utils.d	Tue Feb 10 21:01:24 2009 +0100
@@ -26,6 +26,7 @@
 static import tango.text.Util;
 static import tango.text.Text;
 import tango.text.Unicode;
+public import Utf = tango.text.convert.Utf;
 import tango.text.convert.Utf;
 import tango.core.Exception;
 import tango.stdc.stdlib : exit;
--- a/dwt/internal/Compatibility.d	Sun Jan 18 18:39:46 2009 +0100
+++ b/dwt/internal/Compatibility.d	Tue Feb 10 21:01:24 2009 +0100
@@ -296,7 +296,7 @@
     proc.execute;
 }
 
-const ImportData[] SWTMessagesBundleData = [
+const ImportData[] SWTMessagesBundleData = [/*
     getImportData!( "swt.internal.SWTMessages.properties" ),
     getImportData!( "swt.internal.SWTMessages_ar.properties" ),
     getImportData!( "swt.internal.SWTMessages_cs.properties" ),
@@ -322,7 +322,7 @@
     getImportData!( "swt.internal.SWTMessages_zh_HK.properties" ),
     getImportData!( "swt.internal.SWTMessages_zh.properties" ),
     getImportData!( "swt.internal.SWTMessages_zh_TW.properties" )
-];
+*/];
 
 private static ResourceBundle msgs = null;
 
--- a/dwt/internal/cocoa/OS.d	Sun Jan 18 18:39:46 2009 +0100
+++ b/dwt/internal/cocoa/OS.d	Tue Feb 10 21:01:24 2009 +0100
@@ -32,11 +32,14 @@
     NSGrooveBorder = 3
 }
 
+
+
 import dwt.dwthelper.utils;
 
 import dwt.internal.C;
 import dwt.internal.Library;
 
+import tango.core.Memory;
 import unistd = tango.stdc.posix.unistd;
 import stdc = tango.stdc.string;
 
@@ -1361,13 +1364,19 @@
 /** @method flags=jni */
 public static void* NewGlobalRef (Object object)
 {
-    return cast(void*) object;
+    auto o = cast(void*) object;
+    GC.addRoot(o);
+
+    return o;
 }
 /**
  * @method flags=jni
  * @param globalRef cast=(jobject)
  */
-//public static final void DeleteGlobalRef(void* globalRef){}
+public static void DeleteGlobalRef(void* globalRef)
+{
+    GC.removeRoot(globalRef);
+}
 /** @method flags=no_gen */
 public static Object JNIGetObject (void* globalRef)
 {
--- a/dwt/printing/Printer.d	Sun Jan 18 18:39:46 2009 +0100
+++ b/dwt/printing/Printer.d	Tue Feb 10 21:01:24 2009 +0100
@@ -42,6 +42,7 @@
 
 import Carbon = dwt.internal.c.Carbon;
 import dwt.internal.objc.cocoa.Cocoa;
+import objc = dwt.internal.objc.runtime;
 import dwt.printing.PrinterData;
 
 /**
--- a/dwt/widgets/TabItem.d	Sun Jan 18 18:39:46 2009 +0100
+++ b/dwt/widgets/TabItem.d	Tue Feb 10 21:01:24 2009 +0100
@@ -30,6 +30,7 @@
 import dwt.internal.cocoa.NSWindow;
 import dwt.internal.cocoa.OS;
 
+import objc = dwt.internal.objc.runtime;
 import dwt.widgets.Control;
 import dwt.widgets.Item;
 import dwt.widgets.TabFolder;
--- a/dwt/widgets/Table.d	Sun Jan 18 18:39:46 2009 +0100
+++ b/dwt/widgets/Table.d	Tue Feb 10 21:01:24 2009 +0100
@@ -1,4 +1,4 @@
-/*******************************************************************************
+/*******************************************************************************
  * 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
@@ -137,7 +137,7 @@
     NSBrowserCell dataCell;
     int columnCount, itemCount, lastIndexOf, sortDirection;
     bool ignoreSelect;
-    
+
 /**
  * Constructs a new instance of this class given its parent
  * and a style value describing its behavior and appearance.
@@ -249,7 +249,7 @@
         currentItem = null;
         if (isDisposed () || item.isDisposed ()) return false;
         if (redraw) {
-            //          if (!setScrollWidth (item)) item.redraw (OS.kDataBrowserNoItem);
+//          if (!setScrollWidth (item)) item.redraw (OS.kDataBrowserNoItem);
         }
     }
     return true;
@@ -464,10 +464,10 @@
     widget.setDelegate(widget);
     widget.setDoubleAction(OS.sel_sendDoubleSelection);
     if (!hasBorder()) widget.setFocusRingType(OS.NSFocusRingTypeNone);
-    
+
     headerView = cast(NSTableHeaderView)(new SWTTableHeaderView ()).alloc ().init ();
     widget.setHeaderView (null);
-    
+
     NSString str = NSString.stringWith("");
     if ((style & DWT.CHECK) !is 0) {
         checkColumn = cast(NSTableColumn)(new NSTableColumn()).alloc();
@@ -484,7 +484,7 @@
         checkColumn.setResizingMask(OS.NSTableColumnNoResizing);
         checkColumn.setEditable(false);
     }
-    
+
     firstColumn = cast(NSTableColumn)(new NSTableColumn()).alloc();
     firstColumn.initWithIdentifier(firstColumn);
     firstColumn.setMinWidth(0);
@@ -492,7 +492,7 @@
     dataCell = cast(NSBrowserCell)(new SWTBrowserCell ()).alloc ().init ();
     firstColumn.setDataCell (dataCell);
     widget.addTableColumn (firstColumn);
-    
+
     scrollView = scrollWidget;
     view = widget;
 }
@@ -515,6 +515,7 @@
         nsColumn = cast(NSTableColumn)(new NSTableColumn()).alloc();
         nsColumn.initWithIdentifier(nsColumn);
         nsColumn.setMinWidth(0);
+        (cast(NSTableView)view).addTableColumn (nsColumn);
         int checkColumn = (style & DWT.CHECK) !is 0 ? 1 : 0;
         (cast(NSTableView)view).moveColumn (columnCount + checkColumn, index + checkColumn);
         nsColumn.setDataCell (dataCell);
@@ -774,9 +775,9 @@
             }
         }
     }
-    
+
     NSInteger oldIndex = (cast(NSTableView)view).columnWithIdentifier (column.nsColumn);
-    
+
     if (columnCount is 1) {
         //TODO - reset attributes
         firstColumn = column.nsColumn;
@@ -786,7 +787,7 @@
     }
     System.arraycopy (columns, index + 1, columns, index, --columnCount - index);
     columns [columnCount] = null;
-    
+
     NSArray array = (cast(NSTableView)view).tableColumns ();
     NSUInteger arraySize = array.count ();
     for (NSUInteger i = oldIndex; i < arraySize; i++) {
@@ -813,14 +814,14 @@
     if (itemCount is 0) {
         setTableEmpty ();
     } else {
-        //      fixScrollBar ();
+//      fixScrollBar ();
     }
 }
 
 void drawInteriorWithFrame_inView (objc.id id, objc.SEL sel, objc.id cellFrame, objc.id view) {
     NSRect rect = NSRect ();
     OS.memmove (&rect, cellFrame, NSRect.sizeof);
-    
+
     NSTableView tableView = cast(NSTableView)this.view;
     NSBrowserCell cell = new NSBrowserCell (id);
     NSRange rowsRange = tableView.rowsInRect (rect);
@@ -840,14 +841,14 @@
             }
         }
     }
-    
+
     Color background = item.cellBackground !is null ? item.cellBackground [columnIndex] : null;
     if (background is null) background = item.background;
     bool drawBackground = background !is null;
     bool drawForeground = true;
     bool isSelected = tableView.isRowSelected (rowIndex);
     bool drawSelection = isSelected;
-    
+
     NSColor nsSelectionBackground = null;
     NSColor nsSelectionForeground = null;
     if (isSelected) {
@@ -860,7 +861,7 @@
         nsSelectionBackground = cell.highlightColorInView (tableView);
         nsSelectionBackground = nsSelectionBackground.colorUsingColorSpace (NSColorSpace.deviceRGBColorSpace ());
     }
-    
+
     NSRect fullRect = NSRect ();
     fullRect.x = rect.x; fullRect.y = rect.y; fullRect.height = rect.height;
     if (columnCount is 0) {
@@ -874,7 +875,7 @@
         NSSize spacing = tableView.intercellSpacing ();
         fullRect.width = rect.width + spacing.width;
     }
-    
+
     if (hooks (DWT.EraseItem)) {
         NSRect eraseItemRect;
         // TODO how to handle rearranged columns?  The third clause below ensures that
@@ -927,7 +928,7 @@
             drawForeground = (event.detail & DWT.FOREGROUND) !is 0;
             drawSelection = drawSelection && (event.detail & DWT.SELECTED) !is 0;           
         }
-        
+
         if (drawSelection) {
             NSRect selectionRect = NSRect ();
             selectionRect.y = rect.y; selectionRect.height = rect.height;
@@ -948,7 +949,7 @@
             callSuper (tableView.id, OS.sel_highlightSelectionInClipRect_, selectionRect);
         }   
     }
-    
+
     if (drawBackground && !drawSelection) {
         NSGraphicsContext context = NSGraphicsContext.currentContext ();
         context.saveGraphicsState ();
@@ -958,16 +959,16 @@
         NSBezierPath.fillRect (fullRect);
         context.restoreGraphicsState ();
     }
-    
+
     if (drawForeground) {
         cell.setHighlighted (false);
         callSuper (id, sel, rect, view);
     }
-    
+
     if (hooks (DWT.PaintItem)) {
         NSRect contentRect = cell.titleRectForBounds (rect);
         NSSize contentSize = cell.cellSizeForBounds (rect);
-        
+
         GCData data = new GCData ();
         // TODO how to handle rearranged columns?  The third clause below ensures that
         // there are either 0 columns or that column 0 is still the first physical column.
@@ -998,7 +999,7 @@
             gc.setForeground (item.getForeground (columnIndex));
             gc.setBackground (item.getBackground (columnIndex));
         }
-        
+
         Event event = new Event ();
         event.item = item;
         event.gc = gc;
@@ -1398,7 +1399,7 @@
     selection.getIndexes(indexBuffer.ptr, count, null);
     TableItem [] result = new TableItem  [count];
     for (NSUInteger i=0; i<count; i++) {
-        result [i] = _getItem (cast(int)/*64*/indexBuffer [i]);
+        result [i] = _getItem (indexBuffer [i]);
     }
     return result;
 }
@@ -1469,7 +1470,7 @@
     NSUInteger [] indices = new NSUInteger [count];
     selection.getIndexes(indices.ptr, count, null);
     int [] result = new int [count];
-    for (int i = 0; i < indices.length; i++) {
+    for (size_t i = 0; i < indices.length; i++) {
         result [i] = cast(int)/*64*/indices [i];
     }
     return result;
@@ -1635,7 +1636,7 @@
 }
 
 objc.id numberOfRowsInTableView(objc.id  id, objc.SEL sel, objc.id aTableView) {
-    return cast(objc.id )itemCount;
+    return cast(objc.id) itemCount;
 }
 
 void register () {
@@ -1710,7 +1711,7 @@
     if (itemCount is 0) {
         setTableEmpty ();
     } else {
-        //      fixScrollBar ();
+//      fixScrollBar ();
     }
 }
 
@@ -2130,7 +2131,7 @@
     if (itemHeight is -1) {
         //TODO - reset item height, ensure other API's such as setFont don't do this
     } else {
-        //      OS.SetDataBrowserTableViewRowHeight (handle, cast(short) itemHeight);
+//      OS.SetDataBrowserTableViewRowHeight (handle, cast(short) itemHeight);
     }
 }
 
@@ -2174,7 +2175,7 @@
 bool setScrollWidth (TableItem items[], bool callMeasureItem) {
     if (columnCount !is 0) return false;
     if (currentItem !is null) {
-        //      if (currentItem !is item) fixScrollWidth = true;
+//      if (currentItem !is item) fixScrollWidth = true;
         return false;
     }
     if (/*ignoreRedraw ||*/ drawCount !is 0) return false;
@@ -2225,7 +2226,7 @@
 }
 
 void setSelection (int index, bool notify) {
-    //  checkWidget ();
+//  checkWidget ();
     if (0 <= index && index < itemCount) {
         select (index);
         showIndex (index);
@@ -2587,10 +2588,10 @@
     cocoa.id columnId = userInfo.valueForKey (NSString.stringWith ("NSTableColumn")); //$NON-NLS-1$
     TableColumn column = getColumn (columnId);
     if (column is null) return; /* either CHECK column or firstColumn in 0-column Table */
-    
+
     column.sendEvent (DWT.Resize);
     if (isDisposed ()) return;
-    
+
     NSTableView tableView = cast(NSTableView)view;
     int index = cast(int)/*64*/tableView.columnWithIdentifier (columnId);
     if (index is -1) return; /* column was disposed in Resize callback */
@@ -2680,14 +2681,14 @@
     cell.setFont (item.getFont (columnIndex).handle);
     cell.setImage (image !is null ? image.handle : null);
     cell.setLeaf (true);
-    
+
     if (hooks (DWT.MeasureItem)) {
         NSTableView tableView = cast(NSTableView)this.view;
         NSInteger nsColumnIndex = tableView.columnWithIdentifier (new cocoa.id (aTableColumn));
         NSRect rect = tableView.frameOfCellAtColumn (nsColumnIndex, cast(NSInteger) rowIndex);
         NSRect contentRect = cell.titleRectForBounds (rect);
         NSSize contentSize = cell.cellSizeForBounds (rect);
-        
+
         GCData data = new GCData ();
         data.paintRectStruct = tableView.frame ();
         data.paintRect = &data.paintRectStruct;