This fixes regressions caused by the previous patch. The reason for the
previous mauve failures was due to an oversight on my part of not
properly taking care of the case when you don't have a peer to update
the selected index. 

The mauve test is very flawed in this respect; since it only tests one
(and the less significant) of the two code-paths.

This also fixes some other problems that were remaining. It also makes a
minor change to the design I'd spoken about earlier on the mailing list,
(please read.) The change is that the peer calls back the setProperty
method (in this case select()) regardless if the owner component
(Choice) needs to have its state updated or not. The JRE appears to
do this as well. This makes the code a lot simpler since you don't
need to fiddle around with the component state to force a callback
from the peer. 

The drawback here is that we fail on "case 3" which I outlined in my
email. Thus, the reason the JRE works the way it does gets away with
this must be because they use some other event to trigger the callback
from the peer and not the ItemEvent, so user-created events can't do it.

However this drawback is such a minor detail I'm not sure it's worth
changing. In any case it need not be a top priority for now, until we
get all the peers doing events right.

At least this one seems to be fine now.

/Sven

2006-08-02  Sven de Marothy  <[EMAIL PROTECTED]>

        * gnu/java/awt/peer/gtk/GtkChoicePeer.java
        (remove): Force event on removing item 0 when it's selected.
        (handleEvent): Always call Choice.selected().
        * java/awt/Choice.java:
        (remove): Simplify and correct.

Index: gnu/java/awt/peer/gtk/GtkChoicePeer.java
===================================================================
RCS file: /sources/classpath/classpath/gnu/java/awt/peer/gtk/GtkChoicePeer.java,v
retrieving revision 1.26
diff -U3 -r1.26 GtkChoicePeer.java
--- gnu/java/awt/peer/gtk/GtkChoicePeer.java	30 Jul 2006 09:01:33 -0000	1.26
+++ gnu/java/awt/peer/gtk/GtkChoicePeer.java	3 Aug 2006 03:58:07 -0000
@@ -92,7 +92,10 @@
 
   public void remove( int index )
   {
-    selected = -1; // we do not want to trigger a select event here.
+    // Ensure the triggering of an event when removing item zero if zero is the
+    // selected item, even though the selected index doesn't change.
+    if( index == 0 && selected == 0 )
+      selected = -1; 
     nativeRemove( index );
   }
 
@@ -134,8 +137,7 @@
     if( event instanceof ItemEvent )
       if( ((ItemEvent)event).getItemSelectable() == awtComponent &&
 	  ((ItemEvent)event).getStateChange() == ItemEvent.SELECTED )
-	if( ((Choice)awtComponent).getSelectedIndex() != selected )
-	  ((Choice)awtComponent).select( selected );
+	((Choice)awtComponent).select( selected );
   }
 }
 
Index: java/awt/Choice.java
===================================================================
RCS file: /sources/classpath/classpath/java/awt/Choice.java,v
retrieving revision 1.29
diff -U3 -r1.29 Choice.java
--- java/awt/Choice.java	1 Aug 2006 16:50:13 -0000	1.29
+++ java/awt/Choice.java	3 Aug 2006 03:58:08 -0000
@@ -329,20 +329,14 @@
       selectedIndex = -1;
     else 
       {
-	if( index == selectedIndex )
-	  {
-	    if( peer != null )
-	      ((ChoicePeer)peer).select( 0 ); // force an event here
-            selectedIndex = 0;
-	  }
-	else if( selectedIndex > index )
-          {
-            if ( peer != null)
-              ((ChoicePeer)peer).select(selectedIndex - 1);
-	    select( selectedIndex - 1 );
-          }
-      }
+	if( selectedIndex > index ) 
+	  selectedIndex--;
+	else if( selectedIndex == index )
+	  selectedIndex = 0;
 
+	if( peer != null )
+	  ((ChoicePeer)peer).select( selectedIndex );
+      }
   }
 
   /**

Reply via email to