From de1def922d61f2c8775ff796242c973408a67856 Mon Sep 17 00:00:00 2001 From: fitzsim Date: Fri, 22 Sep 2006 13:04:22 +0000 Subject: [PATCH] 2006-08-02 Sven de Marothy * 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. 2006-07-30 Sven de Marothy * java/awt/Choice.java: (accessibleAction): Call select() directly. (add, insert, remove): Reimplement. (dispatchEventImpl): Always call super. (processItemEvent): Does not set the index. * include/gnu_java_awt_peer_gtk_GtkChoicePeer.h * native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkChoicePeer.c (append): removed. (nativeAdd): Name changed to add. (selection_changed_cb): Simplify callback. * gnu/java/awt/peer/gtk/GtkChoicePeer.java (selected): New field. (add): Replaced with native impl. (handleEvent): New method. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@117142 138bc75d-0d04-0410-961f-82ee72b054a4 --- libjava/classpath/ChangeLog | 25 + .../gnu/java/awt/peer/gtk/GtkChoicePeer.java | 99 +-- .../include/gnu_java_awt_peer_gtk_GtkChoicePeer.h | 3 +- libjava/classpath/java/awt/Choice.java | 720 +++++++++------------ .../gtk-peer/gnu_java_awt_peer_gtk_GtkChoicePeer.c | 70 +- 5 files changed, 406 insertions(+), 511 deletions(-) diff --git a/libjava/classpath/ChangeLog b/libjava/classpath/ChangeLog index 8aca3f9..13eda59 100644 --- a/libjava/classpath/ChangeLog +++ b/libjava/classpath/ChangeLog @@ -1,3 +1,28 @@ +2006-08-02 Sven de Marothy + + * 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. + +2006-07-30 Sven de Marothy + + * java/awt/Choice.java: + (accessibleAction): Call select() directly. + (add, insert, remove): Reimplement. + (dispatchEventImpl): Always call super. + (processItemEvent): Does not set the index. + * include/gnu_java_awt_peer_gtk_GtkChoicePeer.h + * native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkChoicePeer.c + (append): removed. + (nativeAdd): Name changed to add. + (selection_changed_cb): Simplify callback. + * gnu/java/awt/peer/gtk/GtkChoicePeer.java + (selected): New field. + (add): Replaced with native impl. + (handleEvent): New method. + 2006-07-06 Paul Eggert Port to hosts whose 'sort' and 'tail' implementations diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/GtkChoicePeer.java b/libjava/classpath/gnu/java/awt/peer/gtk/GtkChoicePeer.java index ed7dc74..f00461f 100644 --- a/libjava/classpath/gnu/java/awt/peer/gtk/GtkChoicePeer.java +++ b/libjava/classpath/gnu/java/awt/peer/gtk/GtkChoicePeer.java @@ -39,12 +39,15 @@ exception statement from your version. */ package gnu.java.awt.peer.gtk; import java.awt.Choice; +import java.awt.AWTEvent; import java.awt.event.ItemEvent; import java.awt.peer.ChoicePeer; public class GtkChoicePeer extends GtkComponentPeer implements ChoicePeer { + private int selected; + public GtkChoicePeer (Choice c) { super (c); @@ -52,31 +55,33 @@ public class GtkChoicePeer extends GtkComponentPeer int count = c.getItemCount (); if (count > 0) { - String items[] = new String[count]; for (int i = 0; i < count; i++) - items[i] = c.getItem (i); - - append (items); - } + add( c.getItem(i), i ); - int selected = c.getSelectedIndex(); - if (selected >= 0) - select(selected); + selected = c.getSelectedIndex(); + if( selected >= 0 ) + select( selected ); + } + else + selected = -1; } native void create (); - native void append (String items[]); native int nativeGetSelected (); - native void nativeAdd (String item, int index); - native void nativeRemove (int index); - native void nativeRemoveAll (); native void connectSignals (); native void selectNative (int position); + native void selectNativeUnlocked (int position); + public native void add (String item, int index); + + native void nativeRemove(int index); + + native void nativeRemoveAll(); + public void select (int position) { if (Thread.currentThread() == GtkToolkit.mainThread) @@ -85,42 +90,18 @@ public class GtkChoicePeer extends GtkComponentPeer selectNative (position); } - public void add (String item, int index) + public void remove( int index ) { - int before = nativeGetSelected(); - - nativeAdd (item, index); - - /* Generate an ItemEvent if we added the first one or - if we inserted at or before the currently selected item. */ - if ((before < 0) || (before >= index)) - { - // Must set our state before notifying listeners - ((Choice) awtComponent).select (((Choice) awtComponent).getItem (0)); - postItemEvent (((Choice) awtComponent).getItem (0), ItemEvent.SELECTED); - } + // 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 ); } - public void remove (int index) - { - int before = nativeGetSelected(); - int after; - - nativeRemove (index); - after = nativeGetSelected(); - - /* Generate an ItemEvent if we are removing the currently selected item - and there are at least one item left. */ - if ((before == index) && (after >= 0)) - { - // Must set our state before notifying listeners - ((Choice) awtComponent).select (((Choice) awtComponent).getItem (0)); - postItemEvent (((Choice) awtComponent).getItem (0), ItemEvent.SELECTED); - } - } - - public void removeAll () + public void removeAll() { + selected = -1; // we do not want to trigger a select event here. nativeRemoveAll(); } @@ -129,8 +110,34 @@ public class GtkChoicePeer extends GtkComponentPeer add (item, position); } - protected void postChoiceItemEvent (String label, int stateChange) + /** + * Callback from the native side on an item-select event, + * which posts an event. The event is only posted if it represents an actual + * change. Selected is set to the peer's state initially, so that the + * first call to select(int) from the constructor will not trigger an event. + * (it should not) + */ + protected void postChoiceItemEvent ( int index ) + { + if( selected != index ) + { + selected = index; + postItemEvent (((Choice) awtComponent).getItem( selected ), + ItemEvent.SELECTED); + } + } + + /** + * Catches the event and calls Choice.select() if the component state + * needs updating. + */ + public void handleEvent (AWTEvent event) { - postItemEvent (label, stateChange); + super.handleEvent( event ); + if( event instanceof ItemEvent ) + if( ((ItemEvent)event).getItemSelectable() == awtComponent && + ((ItemEvent)event).getStateChange() == ItemEvent.SELECTED ) + ((Choice)awtComponent).select( selected ); } } + diff --git a/libjava/classpath/include/gnu_java_awt_peer_gtk_GtkChoicePeer.h b/libjava/classpath/include/gnu_java_awt_peer_gtk_GtkChoicePeer.h index 1d92ed6..5450434 100644 --- a/libjava/classpath/include/gnu_java_awt_peer_gtk_GtkChoicePeer.h +++ b/libjava/classpath/include/gnu_java_awt_peer_gtk_GtkChoicePeer.h @@ -11,9 +11,8 @@ extern "C" #endif JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkChoicePeer_create (JNIEnv *env, jobject); -JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkChoicePeer_append (JNIEnv *env, jobject, jobjectArray); JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_gtk_GtkChoicePeer_nativeGetSelected (JNIEnv *env, jobject); -JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkChoicePeer_nativeAdd (JNIEnv *env, jobject, jstring, jint); +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkChoicePeer_add (JNIEnv *env, jobject, jstring, jint); JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkChoicePeer_nativeRemove (JNIEnv *env, jobject, jint); JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkChoicePeer_nativeRemoveAll (JNIEnv *env, jobject); JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkChoicePeer_connectSignals (JNIEnv *env, jobject); diff --git a/libjava/classpath/java/awt/Choice.java b/libjava/classpath/java/awt/Choice.java index f1da94b..104e30a 100644 --- a/libjava/classpath/java/awt/Choice.java +++ b/libjava/classpath/java/awt/Choice.java @@ -1,5 +1,5 @@ /* Choice.java -- Java choice button widget. - Copyright (C) 1999, 2000, 2001, 2002, 2004 Free Software Foundation, Inc. + Copyright (C) 1999, 2000, 2001, 2002, 2004, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -51,56 +51,47 @@ import javax.accessibility.AccessibleContext; import javax.accessibility.AccessibleRole; /** - * This class implements a drop down choice list. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ + * This class implements a drop down choice list. + * + * @author Aaron M. Renn (arenn@urbanophile.com) + */ public class Choice extends Component implements ItemSelectable, Serializable, Accessible { + /** + * The number used to generate the name returned by getName. + */ + private static transient long next_choice_number; -/* - * Static Variables - */ - -/** - * The number used to generate the name returned by getName. - */ -private static transient long next_choice_number; - -// Serialization constant -private static final long serialVersionUID = -4075310674757313071L; - -/*************************************************************************/ + // Serialization constant + private static final long serialVersionUID = -4075310674757313071L; -/* - * Instance Variables - */ - -/** - * @serial A list of items for the choice box, which can be null. - * This is package-private to avoid an accessor method. - */ -Vector pItems = new Vector(); + /** + * @serial A list of items for the choice box, which can be null. + * This is package-private to avoid an accessor method. + */ + Vector pItems = new Vector(); -/** - * @serial The index of the selected item in the choice box. - */ -private int selectedIndex = -1; + /** + * @serial The index of the selected item in the choice box. + */ + private int selectedIndex = -1; -// Listener chain -private ItemListener item_listeners; + /** + * ItemListener chain + */ + private ItemListener item_listeners; -/** - * This class provides accessibility support for the - * combo box. - * - * @author Jerry Quinn (jlquinn@optonline.net) - * @author Andrew John Hughes (gnu_andrew@member.fsf.org) - */ + /** + * This class provides accessibility support for the + * combo box. + * + * @author Jerry Quinn (jlquinn@optonline.net) + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + */ protected class AccessibleAWTChoice - extends AccessibleAWTComponent - implements AccessibleAction + extends AccessibleAWTComponent + implements AccessibleAction { /** @@ -186,19 +177,12 @@ private ItemListener item_listeners; if (i < 0 || i >= pItems.size()) return false; - Choice.this.processItemEvent(new ItemEvent(Choice.this, - ItemEvent.ITEM_STATE_CHANGED, - this, ItemEvent.SELECTED)); + Choice.this.select( i ); + return true; } } -/*************************************************************************/ - -/* - * Constructors - */ - /** * Initializes a new instance of Choice. * @@ -211,397 +195,323 @@ private ItemListener item_listeners; throw new HeadlessException (); } -/*************************************************************************/ - -/* - * Instance Methods - */ - -/** - * Returns the number of items in the list. - * - * @return The number of items in the list. - */ -public int -getItemCount() -{ - return countItems (); -} - -/*************************************************************************/ - -/** - * Returns the number of items in the list. - * - * @return The number of items in the list. - * - * @deprecated This method is deprecated in favor of getItemCount. - */ -public int -countItems() -{ - return(pItems.size()); -} - -/*************************************************************************/ - -/** - * Returns the item at the specified index in the list. - * - * @param index The index into the list to return the item from. - * - * @exception ArrayIndexOutOfBoundsException If the index is invalid. - */ -public String -getItem(int index) -{ - return((String)pItems.elementAt(index)); -} - -/*************************************************************************/ - -/** - * Adds the specified item to this choice box. - * - * @param item The item to add. - * - * @exception NullPointerException If the item's value is null - * - * @since 1.1 - */ -public synchronized void -add(String item) -{ - if (item == null) - throw new NullPointerException ("item must be non-null"); - - pItems.addElement(item); - - int i = pItems.size () - 1; - if (peer != null) - { - ChoicePeer cp = (ChoicePeer) peer; - cp.add (item, i); - } - else if (selectedIndex == -1) - select(0); -} - -/*************************************************************************/ + /** + * Returns the number of items in the list. + * + * @return The number of items in the list. + */ + public int getItemCount() + { + return countItems (); + } -/** - * Adds the specified item to this choice box. - * - * This method is oboslete since Java 2 platform 1.1. Please use @see add - * instead. - * - * @param item The item to add. - * - * @exception NullPointerException If the item's value is equal to null - */ -public synchronized void -addItem(String item) -{ - add(item); -} + /** + * Returns the number of items in the list. + * + * @return The number of items in the list. + * + * @deprecated This method is deprecated in favor of getItemCount. + */ + public int countItems() + { + return pItems.size(); + } -/*************************************************************************/ + /** + * Returns the item at the specified index in the list. + * + * @param index The index into the list to return the item from. + * + * @exception ArrayIndexOutOfBoundsException If the index is invalid. + */ + public String getItem(int index) + { + return (String)pItems.elementAt(index); + } -/** Inserts an item into this Choice. Existing items are shifted - * upwards. If the new item is the only item, then it is selected. - * If the currently selected item is shifted, then the first item is - * selected. If the currently selected item is not shifted, then it - * remains selected. - * - * @param item The item to add. - * @param index The index at which the item should be inserted. - * - * @exception IllegalArgumentException If index is less than 0 - */ -public synchronized void -insert(String item, int index) -{ - if (index < 0) - throw new IllegalArgumentException ("index may not be less then 0"); + /** + * Adds the specified item to this choice box. + * + * @param item The item to add. + * + * @exception NullPointerException If the item's value is null + * + * @since 1.1 + */ + public synchronized void add(String item) + { + if (item == null) + throw new NullPointerException ("item must be non-null"); - if (index > getItemCount ()) - index = getItemCount (); + pItems.addElement(item); - pItems.insertElementAt(item, index); + if (peer != null) + ((ChoicePeer) peer).add(item, getItemCount() - 1); - if (peer != null) - { - ChoicePeer cp = (ChoicePeer) peer; - cp.add (item, index); - } - else if (selectedIndex == -1 || selectedIndex >= index) - select(0); -} + if (selectedIndex == -1) + select( 0 ); + } -/*************************************************************************/ + /** + * Adds the specified item to this choice box. + * + * This method is oboslete since Java 2 platform 1.1. Please use @see add + * instead. + * + * @param item The item to add. + * + * @exception NullPointerException If the item's value is equal to null + */ + public synchronized void addItem(String item) + { + add(item); + } -/** - * Removes the specified item from the choice box. - * - * @param item The item to remove. - * - * @exception IllegalArgumentException If the specified item doesn't exist. - */ -public synchronized void -remove(String item) -{ - int index = pItems.indexOf(item); - if (index == -1) - throw new IllegalArgumentException ("item \"" - + item + "\" not found in Choice"); - remove(index); -} + /** Inserts an item into this Choice. Existing items are shifted + * upwards. If the new item is the only item, then it is selected. + * If the currently selected item is shifted, then the first item is + * selected. If the currently selected item is not shifted, then it + * remains selected. + * + * @param item The item to add. + * @param index The index at which the item should be inserted. + * + * @exception IllegalArgumentException If index is less than 0 + */ + public synchronized void insert(String item, int index) + { + if (index < 0) + throw new IllegalArgumentException ("index may not be less then 0"); -/*************************************************************************/ + if (index > getItemCount ()) + index = getItemCount (); -/** - * Removes the item at the specified index from the choice box. - * - * @param index The index of the item to remove. - * - * @exception IndexOutOfBoundsException If the index is not valid. - */ -public synchronized void -remove(int index) -{ - if ((index < 0) || (index > getItemCount())) - throw new IllegalArgumentException("Bad index: " + index); + pItems.insertElementAt(item, index); - pItems.removeElementAt(index); + if (peer != null) + ((ChoicePeer) peer).add (item, index); - if (peer != null) - { - ChoicePeer cp = (ChoicePeer) peer; - cp.remove (index); - } - else - { - if (getItemCount() == 0) - selectedIndex = -1; - else if (index == selectedIndex) - select(0); - } + if (selectedIndex == -1 || selectedIndex >= index) + select(0); + } - if (selectedIndex > index) - --selectedIndex; -} + /** + * Removes the specified item from the choice box. + * + * @param item The item to remove. + * + * @exception IllegalArgumentException If the specified item doesn't exist. + */ + public synchronized void remove(String item) + { + int index = pItems.indexOf(item); + if (index == -1) + throw new IllegalArgumentException ("item \"" + + item + "\" not found in Choice"); + remove(index); + } -/*************************************************************************/ + /** + * Removes the item at the specified index from the choice box. + * + * @param index The index of the item to remove. + * + * @exception IndexOutOfBoundsException If the index is not valid. + */ + public synchronized void remove(int index) + { + if ((index < 0) || (index > getItemCount())) + throw new IllegalArgumentException("Bad index: " + index); + + pItems.removeElementAt(index); + + if (peer != null) + ((ChoicePeer) peer).remove( index ); + + if( getItemCount() == 0 ) + selectedIndex = -1; + else + { + if( selectedIndex > index ) + selectedIndex--; + else if( selectedIndex == index ) + selectedIndex = 0; + + if( peer != null ) + ((ChoicePeer)peer).select( selectedIndex ); + } + } -/** - * Removes all of the objects from this choice box. - */ -public synchronized void -removeAll() -{ - if (getItemCount() <= 0) - return; + /** + * Removes all of the objects from this choice box. + */ + public synchronized void removeAll() + { + if (getItemCount() <= 0) + return; - pItems.removeAllElements (); + pItems.removeAllElements (); - if (peer != null) - { - ChoicePeer cp = (ChoicePeer) peer; - cp.removeAll (); - } - - selectedIndex = -1; -} - -/*************************************************************************/ - -/** - * Returns the currently selected item, or null if no item is - * selected. - * - * @return The currently selected item. - */ -public synchronized String -getSelectedItem() -{ - return (selectedIndex == -1 - ? null - : ((String)pItems.elementAt(selectedIndex))); -} - -/*************************************************************************/ - -/** - * Returns an array with one row containing the selected item. - * - * @return An array containing the selected item. - */ -public synchronized Object[] -getSelectedObjects() -{ - if (selectedIndex == -1) - return null; - - Object[] objs = new Object[1]; - objs[0] = pItems.elementAt(selectedIndex); + if (peer != null) + { + ChoicePeer cp = (ChoicePeer) peer; + cp.removeAll (); + } - return(objs); -} + selectedIndex = -1; + } -/*************************************************************************/ + /** + * Returns the currently selected item, or null if no item is + * selected. + * + * @return The currently selected item. + */ + public synchronized String getSelectedItem() + { + return (selectedIndex == -1 + ? null + : ((String)pItems.elementAt(selectedIndex))); + } -/** - * Returns the index of the selected item. - * - * @return The index of the selected item. - */ -public int -getSelectedIndex() -{ - return(selectedIndex); -} + /** + * Returns an array with one row containing the selected item. + * + * @return An array containing the selected item. + */ + public synchronized Object[] getSelectedObjects() + { + if (selectedIndex == -1) + return null; -/*************************************************************************/ + Object[] objs = new Object[1]; + objs[0] = pItems.elementAt(selectedIndex); -/** - * Forces the item at the specified index to be selected. - * - * @param index The index of the row to make selected. - * - * @exception IllegalArgumentException If the specified index is invalid. - */ -public synchronized void -select(int index) -{ - if ((index < 0) || (index >= getItemCount())) - throw new IllegalArgumentException("Bad index: " + index); - - if (pItems.size() > 0) { - selectedIndex = index; - ChoicePeer cp = (ChoicePeer) peer; - if (cp != null) { - cp.select(index); - } + return objs; } -} -/*************************************************************************/ + /** + * Returns the index of the selected item. + * + * @return The index of the selected item. + */ + public int getSelectedIndex() + { + return selectedIndex; + } -/** - * Forces the named item to be selected. - * - * @param item The item to be selected. - * - * @exception IllegalArgumentException If the specified item does not exist. - */ -public synchronized void -select(String item) -{ - int index = pItems.indexOf(item); - if (index >= 0) - select(index); -} + /** + * Forces the item at the specified index to be selected. + * + * @param index The index of the row to make selected. + * + * @exception IllegalArgumentException If the specified index is invalid. + */ + public synchronized void select(int index) + { + if ((index < 0) || (index >= getItemCount())) + throw new IllegalArgumentException("Bad index: " + index); -/*************************************************************************/ + if( selectedIndex == index ) + return; -/** - * Creates the native peer for this object. - */ -public void -addNotify() -{ - if (peer == null) - peer = getToolkit ().createChoice (this); - super.addNotify (); -} + selectedIndex = index; + if( peer != null ) + ((ChoicePeer)peer).select( index ); + } -/*************************************************************************/ + /** + * Forces the named item to be selected. + * + * @param item The item to be selected. + * + * @exception IllegalArgumentException If the specified item does not exist. + */ + public synchronized void select(String item) + { + int index = pItems.indexOf(item); + if( index >= 0 ) + select( index ); + } -/** - * Adds the specified listener to the list of registered listeners for - * this object. - * - * @param listener The listener to add. - */ -public synchronized void -addItemListener(ItemListener listener) -{ - item_listeners = AWTEventMulticaster.add(item_listeners, listener); -} + /** + * Creates the native peer for this object. + */ + public void addNotify() + { + if (peer == null) + peer = getToolkit ().createChoice (this); + super.addNotify (); + } -/*************************************************************************/ + /** + * Adds the specified listener to the list of registered listeners for + * this object. + * + * @param listener The listener to add. + */ + public synchronized void addItemListener(ItemListener listener) + { + item_listeners = AWTEventMulticaster.add(item_listeners, listener); + } -/** - * Removes the specified listener from the list of registered listeners for - * this object. - * - * @param listener The listener to remove. - */ -public synchronized void -removeItemListener(ItemListener listener) -{ - item_listeners = AWTEventMulticaster.remove(item_listeners, listener); -} + /** + * Removes the specified listener from the list of registered listeners for + * this object. + * + * @param listener The listener to remove. + */ + public synchronized void removeItemListener(ItemListener listener) + { + item_listeners = AWTEventMulticaster.remove(item_listeners, listener); + } -/*************************************************************************/ + /** + * Processes this event by invoking processItemEvent() if the + * event is an instance of ItemEvent, otherwise the event + * is passed to the superclass. + * + * @param event The event to process. + */ + protected void processEvent(AWTEvent event) + { + if (event instanceof ItemEvent) + processItemEvent((ItemEvent)event); + else + super.processEvent(event); + } -/** - * Processes this event by invoking processItemEvent() if the - * event is an instance of ItemEvent, otherwise the event - * is passed to the superclass. - * - * @param event The event to process. - */ -protected void -processEvent(AWTEvent event) -{ - if (event instanceof ItemEvent) - processItemEvent((ItemEvent)event); - else - super.processEvent(event); -} - -void -dispatchEventImpl(AWTEvent e) -{ - if (e.id <= ItemEvent.ITEM_LAST - && e.id >= ItemEvent.ITEM_FIRST - && (item_listeners != null || (eventMask & AWTEvent.ITEM_EVENT_MASK) != 0)) - processEvent(e); - else + void dispatchEventImpl(AWTEvent e) + { super.dispatchEventImpl(e); -} -/*************************************************************************/ - -/** - * Processes item event by dispatching to any registered listeners. - * - * @param event The event to process. - */ -protected void -processItemEvent(ItemEvent event) -{ - int index = pItems.indexOf((String) event.getItem()); - // Don't call back into the peers when selecting index here - if (event.getStateChange() == ItemEvent.SELECTED) - this.selectedIndex = index; - if (item_listeners != null) - item_listeners.itemStateChanged(event); -} + if( e.id <= ItemEvent.ITEM_LAST && e.id >= ItemEvent.ITEM_FIRST && + ( item_listeners != null || + ( eventMask & AWTEvent.ITEM_EVENT_MASK ) != 0 ) ) + processEvent(e); + } -/*************************************************************************/ + /** + * Processes item event by dispatching to any registered listeners. + * + * @param event The event to process. + */ + protected void processItemEvent(ItemEvent event) + { + int index = pItems.indexOf((String) event.getItem()); + if (item_listeners != null) + item_listeners.itemStateChanged(event); + } -/** - * Returns a debugging string for this object. - * - * @return A debugging string for this object. - */ -protected String -paramString() -{ - return ("selectedIndex=" + selectedIndex + "," + super.paramString()); -} + /** + * Returns a debugging string for this object. + * + * @return A debugging string for this object. + */ + protected String paramString() + { + return "selectedIndex=" + selectedIndex + "," + super.paramString(); + } /** * Returns an array of all the objects currently registered as FooListeners diff --git a/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkChoicePeer.c b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkChoicePeer.c index 46949d9..ac4df69 100644 --- a/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkChoicePeer.c +++ b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkChoicePeer.c @@ -1,5 +1,5 @@ /* gtkchoicepeer.c -- Native implementation of GtkChoicePeer - Copyright (C) 1998, 1999 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -52,7 +52,7 @@ cp_gtk_choice_init_jni (void) postChoiceItemEventID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), gtkchoicepeer, "postChoiceItemEvent", - "(Ljava/lang/String;I)V"); + "(I)V"); } static void selection_changed_cb (GtkComboBox *combobox, jobject peer); @@ -106,39 +106,7 @@ Java_gnu_java_awt_peer_gtk_GtkChoicePeer_connectSignals } JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkChoicePeer_append - (JNIEnv *env, jobject obj, jobjectArray items) -{ - gpointer ptr; - jsize count, i; - GtkWidget *bin; - - gdk_threads_enter (); - - ptr = NSA_GET_PTR (env, obj); - bin = choice_get_widget (GTK_WIDGET (ptr)); - - count = (*env)->GetArrayLength (env, items); - - for (i = 0; i < count; i++) - { - jobject item; - const char *label; - - item = (*env)->GetObjectArrayElement (env, items, i); - label = (*env)->GetStringUTFChars (env, item, NULL); - - gtk_combo_box_append_text (GTK_COMBO_BOX (bin), label); - - (*env)->ReleaseStringUTFChars (env, item, label); - (*env)->DeleteLocalRef(env, item); - } - - gdk_threads_leave (); -} - -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkChoicePeer_nativeAdd +Java_gnu_java_awt_peer_gtk_GtkChoicePeer_add (JNIEnv *env, jobject obj, jstring item, jint index) { void *ptr; @@ -170,14 +138,16 @@ Java_gnu_java_awt_peer_gtk_GtkChoicePeer_nativeRemove ptr = NSA_GET_PTR (env, obj); bin = choice_get_widget (GTK_WIDGET (ptr)); - + + /* First, unselect everything, to avoid problems when removing items. */ + gtk_combo_box_set_active (GTK_COMBO_BOX (bin), -1); gtk_combo_box_remove_text (GTK_COMBO_BOX (bin), index); gdk_threads_leave (); } -JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkChoicePeer_nativeRemoveAll +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkChoicePeer_nativeRemoveAll (JNIEnv *env, jobject obj) { void *ptr; @@ -224,8 +194,7 @@ Java_gnu_java_awt_peer_gtk_GtkChoicePeer_selectNativeUnlocked ptr = NSA_GET_PTR (env, obj); bin = choice_get_widget (GTK_WIDGET (ptr)); - - gtk_combo_box_set_active (GTK_COMBO_BOX (bin), index); + gtk_combo_box_set_active (GTK_COMBO_BOX (bin), (gint)index); } JNIEXPORT jint JNICALL @@ -251,26 +220,11 @@ Java_gnu_java_awt_peer_gtk_GtkChoicePeer_nativeGetSelected static void selection_changed_cb (GtkComboBox *combobox, jobject peer) { - jstring label; - GtkTreeModel *model; - GtkTreeIter iter; - gchar *selected; - gint index; - - index = gtk_combo_box_get_active(combobox); + gint index = gtk_combo_box_get_active(combobox); if (index >= 0) - { - model = gtk_combo_box_get_model (combobox); - gtk_combo_box_get_active_iter (combobox, &iter); - gtk_tree_model_get (model, &iter, 0, &selected, -1); - label = (*cp_gtk_gdk_env())->NewStringUTF (cp_gtk_gdk_env(), selected); - - (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer, - postChoiceItemEventID, - label, - (jint) AWT_ITEM_SELECTED); - } + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer, + postChoiceItemEventID, (jint)index ); } static GtkWidget * -- 2.7.4