On Tue, 8 Feb 2005, Thomas Fitzsimmons wrote:

> On Wed, 2005-02-02 at 11:58 -0700, Craig Black wrote:
> > Hello,
> > The following patch makes CheckboxMenuItem notify ItemListeners on 
> > selection/deselection.
> > See attached test, comments?
> >
>
> The test still doesn't work perfectly.  The checkbox action should be
> detected in the menu labeled "Menu" but it's reported in a menu labeled
> "Checkbox".  Also, the selected/deselected state is always reported as
> selected.
>
> Tom
>
>

Sorry about that, I've attached a modified patch that fixes both problems.

Craig


2005-02-10  Craig Black  <[EMAIL PROTECTED]>

  * gnu/java/awt/peer/gtk/GtkCheckboxMenuItem.java
  (postMenuActionEvent): Implement to notify ItemListeners.
  * java/awt/CheckboxMenuItem.java
  (dispatchEventImpl): Update state on ItemEvent.
  * java/awt/MenuItem.java
  (processActionEvent): Retarget event source.
Index: gnu/java/awt/peer/gtk/GtkCheckboxMenuItemPeer.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/gnu/java/awt/peer/gtk/GtkCheckboxMenuItemPeer.java,v
retrieving revision 1.5
diff -u -r1.5 GtkCheckboxMenuItemPeer.java
--- gnu/java/awt/peer/gtk/GtkCheckboxMenuItemPeer.java  9 Jul 2003 10:25:34 
-0000       1.5
+++ gnu/java/awt/peer/gtk/GtkCheckboxMenuItemPeer.java  10 Feb 2005 20:09:33 
-0000
@@ -38,6 +38,8 @@
 
 package gnu.java.awt.peer.gtk;
 
+import java.awt.ItemSelectable;
+import java.awt.event.ItemEvent;
 import java.awt.CheckboxMenuItem;
 import java.awt.peer.CheckboxMenuItemPeer;
 import java.awt.peer.MenuItemPeer;
@@ -54,4 +56,15 @@
   }
 
   native public void setState (boolean t);
+
+  protected void postMenuActionEvent ()
+  {
+    CheckboxMenuItem item = (CheckboxMenuItem)awtWidget;
+    q().postEvent (new ItemEvent ((ItemSelectable)awtWidget,
+      ItemEvent.ITEM_STATE_CHANGED,
+      item.getActionCommand(),
+      item.getState() ? ItemEvent.DESELECTED : ItemEvent.SELECTED));
+
+    super.postMenuActionEvent();
+  }
 }
Index: java/awt/CheckboxMenuItem.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/awt/CheckboxMenuItem.java,v
retrieving revision 1.17
diff -u -r1.17 CheckboxMenuItem.java
--- java/awt/CheckboxMenuItem.java      30 Dec 2004 19:02:06 -0000      1.17
+++ java/awt/CheckboxMenuItem.java      10 Feb 2005 20:09:33 -0000
@@ -274,6 +274,14 @@
 void
 dispatchEventImpl(AWTEvent e)
 {
+  if (e instanceof ItemEvent)
+    {
+      synchronized (this)
+        {
+          state = (((ItemEvent) e).getStateChange() == ItemEvent.SELECTED);
+        }
+    }
+
   if (e.id <= ItemEvent.ITEM_LAST 
       && e.id >= ItemEvent.ITEM_FIRST
       && (item_listeners != null 
Index: java/awt/MenuItem.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/awt/MenuItem.java,v
retrieving revision 1.20
diff -u -r1.20 MenuItem.java
--- java/awt/MenuItem.java      30 Dec 2004 19:02:06 -0000      1.20
+++ java/awt/MenuItem.java      10 Feb 2005 20:09:33 -0000
@@ -563,7 +563,10 @@
 processActionEvent(ActionEvent event)
 {
   if (action_listeners != null)
-    action_listeners.actionPerformed(event);
+    {
+      event.setSource(this);
+      action_listeners.actionPerformed(event);
+    }
 }
 
 /*************************************************************************/
_______________________________________________
Classpath-patches mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/classpath-patches

Reply via email to