changeset 122:45921f44a4b2

Fix: stack access from listener in AddressBook example
author Frank Benoit <benoit@tionex.de>
date Sun, 20 Jan 2008 22:07:27 +0100
parents c8f6e8dc0fcf
children 93492b9cae31
files dwt/widgets/Dialog.d dwt/widgets/EventTable.d dwt/widgets/Shell.d dwtexamples/addressbook/AddressBook.d
diffstat 4 files changed, 19 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/dwt/widgets/Dialog.d	Sun Jan 20 22:07:01 2008 +0100
+++ b/dwt/widgets/Dialog.d	Sun Jan 20 22:07:27 2008 +0100
@@ -1,4 +1,4 @@
-/*******************************************************************************
+/*******************************************************************************
  * Copyright (c) 2000, 2005 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
--- a/dwt/widgets/EventTable.d	Sun Jan 20 22:07:01 2008 +0100
+++ b/dwt/widgets/EventTable.d	Sun Jan 20 22:07:27 2008 +0100
@@ -21,19 +21,6 @@
 import dwt.DWT;
 import dwt.internal.DWTEventListener;
 
-/+
-class EventTable{
-    public void hook (int eventType, Listener listener) {
-    }
-    public void sendEvent (Event event) {}
-    public bool hooks (int eventType) { return false; }
-    public void unhook (int eventType, Listener listener) {}
-    public void unhook (int eventType, DWTEventListener listener) {}
-    public int size () { return 0;}
-}
-+/
-
-
 /**
  * Instances of this class implement a simple
  * look up mechanism that maps an event type
--- a/dwt/widgets/Shell.d	Sun Jan 20 22:07:01 2008 +0100
+++ b/dwt/widgets/Shell.d	Sun Jan 20 22:07:27 2008 +0100
@@ -565,6 +565,7 @@
     checkWidget ();
     closeWidget ();
 }
+
 void closeWidget () {
     Event event = new Event ();
     sendEvent (DWT.Close, event);
--- a/dwtexamples/addressbook/AddressBook.d	Sun Jan 20 22:07:01 2008 +0100
+++ b/dwtexamples/addressbook/AddressBook.d	Sun Jan 20 22:07:27 2008 +0100
@@ -10,19 +10,6 @@
  *******************************************************************************/
 module dwtexamples.addressbook.AddressBook;
 
-
-// /* Imports */
-// import java.io.BufferedReader;
-// import java.io.File;
-// import java.io.FileNotFoundException;
-// import java.io.FileReader;
-// import java.io.FileWriter;
-// import java.io.IOException;
-// import java.util.Arrays;
-// import java.util.Comparator;
-// import java.util.ResourceBundle;
-
-
 import dwt.DWT;
 import dwt.events.MenuAdapter;
 import dwt.events.MenuEvent;
@@ -66,11 +53,12 @@
 
 void main() {
     Display display = new Display();
-    AddressBook application = new AddressBook();
+    auto application = new AddressBook();
     Shell shell = application.open(display);
     while(!shell.isDisposed()){
-        if(!display.readAndDispatch())
+        if(!display.readAndDispatch()){
             display.sleep();
+        }
     }
     display.dispose();
 }
@@ -111,10 +99,13 @@
             resAddressBook.getString("Fax") ];
     }
 }
+
+
 public Shell open(Display display) {
     shell = new Shell(display);
     shell.setLayout(new FillLayout());
-    shell.addShellListener(new class() ShellAdapter {
+
+    shell.addShellListener( new class() ShellAdapter {
         public void shellClosed(ShellEvent e) {
             e.doit = closeAddressBook();
         }
@@ -144,10 +135,12 @@
         TableColumn column = new TableColumn(table, DWT.NONE);
         column.setText(columnNames[i]);
         column.setWidth(150);
-        final int columnIndex = i;
-        column.addSelectionListener(new class() SelectionAdapter {
+        int columnIndex = i;
+        column.addSelectionListener(new class(columnIndex) SelectionAdapter {
+            int c;
+            this( int c ){ this.c = c; }
             public void widgetSelected(SelectionEvent e) {
-                sort(columnIndex);
+                sort(c);
             }
         });
     }
@@ -696,13 +689,14 @@
     for(int i = 0; i < columnNames.length; i++) {
         subitem = new MenuItem (submenu, DWT.NONE);
         subitem.setText(columnNames [i]);
-        final int column = i;
-        subitem.addSelectionListener(new class() SelectionAdapter {
+        int column = i;
+        subitem.addSelectionListener(new class(column) SelectionAdapter {
+            int c;
+            this(int c){ this.c = c; }
             public void widgetSelected(SelectionEvent e) {
-                sort(column);
+                sort(c);
             }
         });
-
     }
 
     return submenu;