Commit 2067150e by Sven de Marothy Committed by Thomas Fitzsimmons

[multiple changes]

2006-08-02  Sven de Marothy  <sven@physto.se>

	* 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  <sven@physto.se>

	* 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.

From-SVN: r117142
parent 36b24193
2006-08-02 Sven de Marothy <sven@physto.se>
* 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 <sven@physto.se>
* 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 <eggert@cs.ucla.edu> 2006-07-06 Paul Eggert <eggert@cs.ucla.edu>
Port to hosts whose 'sort' and 'tail' implementations Port to hosts whose 'sort' and 'tail' implementations
......
...@@ -39,12 +39,15 @@ exception statement from your version. */ ...@@ -39,12 +39,15 @@ exception statement from your version. */
package gnu.java.awt.peer.gtk; package gnu.java.awt.peer.gtk;
import java.awt.Choice; import java.awt.Choice;
import java.awt.AWTEvent;
import java.awt.event.ItemEvent; import java.awt.event.ItemEvent;
import java.awt.peer.ChoicePeer; import java.awt.peer.ChoicePeer;
public class GtkChoicePeer extends GtkComponentPeer public class GtkChoicePeer extends GtkComponentPeer
implements ChoicePeer implements ChoicePeer
{ {
private int selected;
public GtkChoicePeer (Choice c) public GtkChoicePeer (Choice c)
{ {
super (c); super (c);
...@@ -52,31 +55,33 @@ public class GtkChoicePeer extends GtkComponentPeer ...@@ -52,31 +55,33 @@ public class GtkChoicePeer extends GtkComponentPeer
int count = c.getItemCount (); int count = c.getItemCount ();
if (count > 0) if (count > 0)
{ {
String items[] = new String[count];
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
items[i] = c.getItem (i); add( c.getItem(i), i );
append (items); selected = c.getSelectedIndex();
if( selected >= 0 )
select( selected );
} }
else
int selected = c.getSelectedIndex(); selected = -1;
if (selected >= 0)
select(selected);
} }
native void create (); native void create ();
native void append (String items[]);
native int nativeGetSelected (); native int nativeGetSelected ();
native void nativeAdd (String item, int index);
native void nativeRemove (int index);
native void nativeRemoveAll ();
native void connectSignals (); native void connectSignals ();
native void selectNative (int position); native void selectNative (int position);
native void selectNativeUnlocked (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) public void select (int position)
{ {
if (Thread.currentThread() == GtkToolkit.mainThread) if (Thread.currentThread() == GtkToolkit.mainThread)
...@@ -85,42 +90,18 @@ public class GtkChoicePeer extends GtkComponentPeer ...@@ -85,42 +90,18 @@ public class GtkChoicePeer extends GtkComponentPeer
selectNative (position); 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);
}
}
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 // Ensure the triggering of an event when removing item zero if zero is the
((Choice) awtComponent).select (((Choice) awtComponent).getItem (0)); // selected item, even though the selected index doesn't change.
postItemEvent (((Choice) awtComponent).getItem (0), ItemEvent.SELECTED); if( index == 0 && selected == 0 )
} selected = -1;
nativeRemove( index );
} }
public void removeAll () public void removeAll()
{ {
selected = -1; // we do not want to trigger a select event here.
nativeRemoveAll(); nativeRemoveAll();
} }
...@@ -129,8 +110,34 @@ public class GtkChoicePeer extends GtkComponentPeer ...@@ -129,8 +110,34 @@ public class GtkChoicePeer extends GtkComponentPeer
add (item, position); 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 )
{ {
postItemEvent (label, stateChange); 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)
{
super.handleEvent( event );
if( event instanceof ItemEvent )
if( ((ItemEvent)event).getItemSelectable() == awtComponent &&
((ItemEvent)event).getStateChange() == ItemEvent.SELECTED )
((Choice)awtComponent).select( selected );
} }
} }
...@@ -11,9 +11,8 @@ extern "C" ...@@ -11,9 +11,8 @@ extern "C"
#endif #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_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 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_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_nativeRemoveAll (JNIEnv *env, jobject);
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkChoicePeer_connectSignals (JNIEnv *env, jobject); JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkChoicePeer_connectSignals (JNIEnv *env, jobject);
......
/* Choice.java -- Java choice button widget. /* 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. This file is part of GNU Classpath.
...@@ -58,40 +58,31 @@ import javax.accessibility.AccessibleRole; ...@@ -58,40 +58,31 @@ import javax.accessibility.AccessibleRole;
public class Choice extends Component public class Choice extends Component
implements ItemSelectable, Serializable, Accessible implements ItemSelectable, Serializable, Accessible
{ {
/**
/*
* Static Variables
*/
/**
* The number used to generate the name returned by getName. * The number used to generate the name returned by getName.
*/ */
private static transient long next_choice_number; 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 <code>null</code>. * @serial A list of items for the choice box, which can be <code>null</code>.
* This is package-private to avoid an accessor method. * This is package-private to avoid an accessor method.
*/ */
Vector pItems = new Vector(); Vector pItems = new Vector();
/** /**
* @serial The index of the selected item in the choice box. * @serial The index of the selected item in the choice box.
*/ */
private int selectedIndex = -1; private int selectedIndex = -1;
// Listener chain /**
private ItemListener item_listeners; * ItemListener chain
*/
private ItemListener item_listeners;
/** /**
* This class provides accessibility support for the * This class provides accessibility support for the
* combo box. * combo box.
* *
...@@ -186,19 +177,12 @@ private ItemListener item_listeners; ...@@ -186,19 +177,12 @@ private ItemListener item_listeners;
if (i < 0 || i >= pItems.size()) if (i < 0 || i >= pItems.size())
return false; return false;
Choice.this.processItemEvent(new ItemEvent(Choice.this, Choice.this.select( i );
ItemEvent.ITEM_STATE_CHANGED,
this, ItemEvent.SELECTED));
return true; return true;
} }
} }
/*************************************************************************/
/*
* Constructors
*/
/** /**
* Initializes a new instance of <code>Choice</code>. * Initializes a new instance of <code>Choice</code>.
* *
...@@ -211,56 +195,41 @@ private ItemListener item_listeners; ...@@ -211,56 +195,41 @@ private ItemListener item_listeners;
throw new HeadlessException (); throw new HeadlessException ();
} }
/*************************************************************************/ /**
/*
* Instance Methods
*/
/**
* Returns the number of items in the list. * Returns the number of items in the list.
* *
* @return The number of items in the list. * @return The number of items in the list.
*/ */
public int public int getItemCount()
getItemCount() {
{
return countItems (); return countItems ();
} }
/*************************************************************************/
/** /**
* Returns the number of items in the list. * Returns the number of items in the list.
* *
* @return The number of items in the list. * @return The number of items in the list.
* *
* @deprecated This method is deprecated in favor of <code>getItemCount</code>. * @deprecated This method is deprecated in favor of <code>getItemCount</code>.
*/ */
public int public int countItems()
countItems() {
{ return pItems.size();
return(pItems.size()); }
}
/*************************************************************************/
/** /**
* Returns the item at the specified index in the list. * Returns the item at the specified index in the list.
* *
* @param index The index into the list to return the item from. * @param index The index into the list to return the item from.
* *
* @exception ArrayIndexOutOfBoundsException If the index is invalid. * @exception ArrayIndexOutOfBoundsException If the index is invalid.
*/ */
public String public String getItem(int index)
getItem(int index) {
{ return (String)pItems.elementAt(index);
return((String)pItems.elementAt(index)); }
}
/*************************************************************************/
/** /**
* Adds the specified item to this choice box. * Adds the specified item to this choice box.
* *
* @param item The item to add. * @param item The item to add.
...@@ -269,27 +238,21 @@ getItem(int index) ...@@ -269,27 +238,21 @@ getItem(int index)
* *
* @since 1.1 * @since 1.1
*/ */
public synchronized void public synchronized void add(String item)
add(String item) {
{
if (item == null) if (item == null)
throw new NullPointerException ("item must be non-null"); throw new NullPointerException ("item must be non-null");
pItems.addElement(item); pItems.addElement(item);
int i = pItems.size () - 1;
if (peer != null) if (peer != null)
{ ((ChoicePeer) peer).add(item, getItemCount() - 1);
ChoicePeer cp = (ChoicePeer) peer;
cp.add (item, i);
}
else if (selectedIndex == -1)
select(0);
}
/*************************************************************************/ if (selectedIndex == -1)
select( 0 );
}
/** /**
* Adds the specified item to this choice box. * Adds the specified item to this choice box.
* *
* This method is oboslete since Java 2 platform 1.1. Please use @see add * This method is oboslete since Java 2 platform 1.1. Please use @see add
...@@ -299,15 +262,12 @@ add(String item) ...@@ -299,15 +262,12 @@ add(String item)
* *
* @exception NullPointerException If the item's value is equal to null * @exception NullPointerException If the item's value is equal to null
*/ */
public synchronized void public synchronized void addItem(String item)
addItem(String item) {
{
add(item); add(item);
} }
/*************************************************************************/
/** Inserts an item into this Choice. Existing items are shifted /** Inserts an item into this Choice. Existing items are shifted
* upwards. If the new item is the only item, then it is selected. * 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 * If the currently selected item is shifted, then the first item is
* selected. If the currently selected item is not shifted, then it * selected. If the currently selected item is not shifted, then it
...@@ -318,9 +278,8 @@ addItem(String item) ...@@ -318,9 +278,8 @@ addItem(String item)
* *
* @exception IllegalArgumentException If index is less than 0 * @exception IllegalArgumentException If index is less than 0
*/ */
public synchronized void public synchronized void insert(String item, int index)
insert(String item, int index) {
{
if (index < 0) if (index < 0)
throw new IllegalArgumentException ("index may not be less then 0"); throw new IllegalArgumentException ("index may not be less then 0");
...@@ -330,75 +289,64 @@ insert(String item, int index) ...@@ -330,75 +289,64 @@ insert(String item, int index)
pItems.insertElementAt(item, index); pItems.insertElementAt(item, index);
if (peer != null) if (peer != null)
{ ((ChoicePeer) peer).add (item, index);
ChoicePeer cp = (ChoicePeer) peer;
cp.add (item, index);
}
else if (selectedIndex == -1 || selectedIndex >= index)
select(0);
}
/*************************************************************************/ if (selectedIndex == -1 || selectedIndex >= index)
select(0);
}
/** /**
* Removes the specified item from the choice box. * Removes the specified item from the choice box.
* *
* @param item The item to remove. * @param item The item to remove.
* *
* @exception IllegalArgumentException If the specified item doesn't exist. * @exception IllegalArgumentException If the specified item doesn't exist.
*/ */
public synchronized void public synchronized void remove(String item)
remove(String item) {
{
int index = pItems.indexOf(item); int index = pItems.indexOf(item);
if (index == -1) if (index == -1)
throw new IllegalArgumentException ("item \"" throw new IllegalArgumentException ("item \""
+ item + "\" not found in Choice"); + item + "\" not found in Choice");
remove(index); remove(index);
} }
/*************************************************************************/
/** /**
* Removes the item at the specified index from the choice box. * Removes the item at the specified index from the choice box.
* *
* @param index The index of the item to remove. * @param index The index of the item to remove.
* *
* @exception IndexOutOfBoundsException If the index is not valid. * @exception IndexOutOfBoundsException If the index is not valid.
*/ */
public synchronized void public synchronized void remove(int index)
remove(int index) {
{
if ((index < 0) || (index > getItemCount())) if ((index < 0) || (index > getItemCount()))
throw new IllegalArgumentException("Bad index: " + index); throw new IllegalArgumentException("Bad index: " + index);
pItems.removeElementAt(index); pItems.removeElementAt(index);
if (peer != null) if (peer != null)
{ ((ChoicePeer) peer).remove( index );
ChoicePeer cp = (ChoicePeer) peer;
cp.remove (index); if( getItemCount() == 0 )
} selectedIndex = -1;
else else
{ {
if (getItemCount() == 0) if( selectedIndex > index )
selectedIndex = -1; selectedIndex--;
else if (index == selectedIndex) else if( selectedIndex == index )
select(0); selectedIndex = 0;
}
if (selectedIndex > index)
--selectedIndex;
}
/*************************************************************************/ if( peer != null )
((ChoicePeer)peer).select( selectedIndex );
}
}
/** /**
* Removes all of the objects from this choice box. * Removes all of the objects from this choice box.
*/ */
public synchronized void public synchronized void removeAll()
removeAll() {
{
if (getItemCount() <= 0) if (getItemCount() <= 0)
return; return;
...@@ -411,197 +359,159 @@ removeAll() ...@@ -411,197 +359,159 @@ removeAll()
} }
selectedIndex = -1; selectedIndex = -1;
} }
/*************************************************************************/
/** /**
* Returns the currently selected item, or null if no item is * Returns the currently selected item, or null if no item is
* selected. * selected.
* *
* @return The currently selected item. * @return The currently selected item.
*/ */
public synchronized String public synchronized String getSelectedItem()
getSelectedItem() {
{
return (selectedIndex == -1 return (selectedIndex == -1
? null ? null
: ((String)pItems.elementAt(selectedIndex))); : ((String)pItems.elementAt(selectedIndex)));
} }
/*************************************************************************/
/** /**
* Returns an array with one row containing the selected item. * Returns an array with one row containing the selected item.
* *
* @return An array containing the selected item. * @return An array containing the selected item.
*/ */
public synchronized Object[] public synchronized Object[] getSelectedObjects()
getSelectedObjects() {
{
if (selectedIndex == -1) if (selectedIndex == -1)
return null; return null;
Object[] objs = new Object[1]; Object[] objs = new Object[1];
objs[0] = pItems.elementAt(selectedIndex); objs[0] = pItems.elementAt(selectedIndex);
return(objs); return objs;
} }
/*************************************************************************/
/** /**
* Returns the index of the selected item. * Returns the index of the selected item.
* *
* @return The index of the selected item. * @return The index of the selected item.
*/ */
public int public int getSelectedIndex()
getSelectedIndex() {
{ return selectedIndex;
return(selectedIndex); }
}
/*************************************************************************/
/** /**
* Forces the item at the specified index to be selected. * Forces the item at the specified index to be selected.
* *
* @param index The index of the row to make selected. * @param index The index of the row to make selected.
* *
* @exception IllegalArgumentException If the specified index is invalid. * @exception IllegalArgumentException If the specified index is invalid.
*/ */
public synchronized void public synchronized void select(int index)
select(int index) {
{
if ((index < 0) || (index >= getItemCount())) if ((index < 0) || (index >= getItemCount()))
throw new IllegalArgumentException("Bad index: " + index); throw new IllegalArgumentException("Bad index: " + index);
if (pItems.size() > 0) { if( selectedIndex == index )
return;
selectedIndex = index; selectedIndex = index;
ChoicePeer cp = (ChoicePeer) peer; if( peer != null )
if (cp != null) { ((ChoicePeer)peer).select( index );
cp.select(index);
} }
}
}
/*************************************************************************/
/** /**
* Forces the named item to be selected. * Forces the named item to be selected.
* *
* @param item The item to be selected. * @param item The item to be selected.
* *
* @exception IllegalArgumentException If the specified item does not exist. * @exception IllegalArgumentException If the specified item does not exist.
*/ */
public synchronized void public synchronized void select(String item)
select(String item) {
{
int index = pItems.indexOf(item); int index = pItems.indexOf(item);
if (index >= 0) if( index >= 0 )
select(index); select( index );
} }
/*************************************************************************/
/** /**
* Creates the native peer for this object. * Creates the native peer for this object.
*/ */
public void public void addNotify()
addNotify() {
{
if (peer == null) if (peer == null)
peer = getToolkit ().createChoice (this); peer = getToolkit ().createChoice (this);
super.addNotify (); super.addNotify ();
} }
/*************************************************************************/
/** /**
* Adds the specified listener to the list of registered listeners for * Adds the specified listener to the list of registered listeners for
* this object. * this object.
* *
* @param listener The listener to add. * @param listener The listener to add.
*/ */
public synchronized void public synchronized void addItemListener(ItemListener listener)
addItemListener(ItemListener listener) {
{
item_listeners = AWTEventMulticaster.add(item_listeners, listener); item_listeners = AWTEventMulticaster.add(item_listeners, listener);
} }
/*************************************************************************/
/** /**
* Removes the specified listener from the list of registered listeners for * Removes the specified listener from the list of registered listeners for
* this object. * this object.
* *
* @param listener The listener to remove. * @param listener The listener to remove.
*/ */
public synchronized void public synchronized void removeItemListener(ItemListener listener)
removeItemListener(ItemListener listener) {
{
item_listeners = AWTEventMulticaster.remove(item_listeners, listener); item_listeners = AWTEventMulticaster.remove(item_listeners, listener);
} }
/*************************************************************************/
/** /**
* Processes this event by invoking <code>processItemEvent()</code> if the * Processes this event by invoking <code>processItemEvent()</code> if the
* event is an instance of <code>ItemEvent</code>, otherwise the event * event is an instance of <code>ItemEvent</code>, otherwise the event
* is passed to the superclass. * is passed to the superclass.
* *
* @param event The event to process. * @param event The event to process.
*/ */
protected void protected void processEvent(AWTEvent event)
processEvent(AWTEvent event) {
{
if (event instanceof ItemEvent) if (event instanceof ItemEvent)
processItemEvent((ItemEvent)event); processItemEvent((ItemEvent)event);
else else
super.processEvent(event); super.processEvent(event);
} }
void void dispatchEventImpl(AWTEvent e)
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
super.dispatchEventImpl(e); super.dispatchEventImpl(e);
}
/*************************************************************************/ 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. * Processes item event by dispatching to any registered listeners.
* *
* @param event The event to process. * @param event The event to process.
*/ */
protected void protected void processItemEvent(ItemEvent event)
processItemEvent(ItemEvent event) {
{
int index = pItems.indexOf((String) event.getItem()); 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) if (item_listeners != null)
item_listeners.itemStateChanged(event); item_listeners.itemStateChanged(event);
} }
/*************************************************************************/
/** /**
* Returns a debugging string for this object. * Returns a debugging string for this object.
* *
* @return A debugging string for this object. * @return A debugging string for this object.
*/ */
protected String protected String paramString()
paramString() {
{ return "selectedIndex=" + selectedIndex + "," + super.paramString();
return ("selectedIndex=" + selectedIndex + "," + super.paramString()); }
}
/** /**
* Returns an array of all the objects currently registered as FooListeners * Returns an array of all the objects currently registered as FooListeners
......
/* gtkchoicepeer.c -- Native implementation of GtkChoicePeer /* 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. This file is part of GNU Classpath.
...@@ -52,7 +52,7 @@ cp_gtk_choice_init_jni (void) ...@@ -52,7 +52,7 @@ cp_gtk_choice_init_jni (void)
postChoiceItemEventID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), gtkchoicepeer, postChoiceItemEventID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), gtkchoicepeer,
"postChoiceItemEvent", "postChoiceItemEvent",
"(Ljava/lang/String;I)V"); "(I)V");
} }
static void selection_changed_cb (GtkComboBox *combobox, jobject peer); static void selection_changed_cb (GtkComboBox *combobox, jobject peer);
...@@ -106,39 +106,7 @@ Java_gnu_java_awt_peer_gtk_GtkChoicePeer_connectSignals ...@@ -106,39 +106,7 @@ Java_gnu_java_awt_peer_gtk_GtkChoicePeer_connectSignals
} }
JNIEXPORT void JNICALL JNIEXPORT void JNICALL
Java_gnu_java_awt_peer_gtk_GtkChoicePeer_append Java_gnu_java_awt_peer_gtk_GtkChoicePeer_add
(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
(JNIEnv *env, jobject obj, jstring item, jint index) (JNIEnv *env, jobject obj, jstring item, jint index)
{ {
void *ptr; void *ptr;
...@@ -171,6 +139,8 @@ Java_gnu_java_awt_peer_gtk_GtkChoicePeer_nativeRemove ...@@ -171,6 +139,8 @@ Java_gnu_java_awt_peer_gtk_GtkChoicePeer_nativeRemove
ptr = NSA_GET_PTR (env, obj); ptr = NSA_GET_PTR (env, obj);
bin = choice_get_widget (GTK_WIDGET (ptr)); 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); gtk_combo_box_remove_text (GTK_COMBO_BOX (bin), index);
gdk_threads_leave (); gdk_threads_leave ();
...@@ -224,8 +194,7 @@ Java_gnu_java_awt_peer_gtk_GtkChoicePeer_selectNativeUnlocked ...@@ -224,8 +194,7 @@ Java_gnu_java_awt_peer_gtk_GtkChoicePeer_selectNativeUnlocked
ptr = NSA_GET_PTR (env, obj); ptr = NSA_GET_PTR (env, obj);
bin = choice_get_widget (GTK_WIDGET (ptr)); bin = choice_get_widget (GTK_WIDGET (ptr));
gtk_combo_box_set_active (GTK_COMBO_BOX (bin), (gint)index);
gtk_combo_box_set_active (GTK_COMBO_BOX (bin), index);
} }
JNIEXPORT jint JNICALL JNIEXPORT jint JNICALL
...@@ -251,26 +220,11 @@ Java_gnu_java_awt_peer_gtk_GtkChoicePeer_nativeGetSelected ...@@ -251,26 +220,11 @@ Java_gnu_java_awt_peer_gtk_GtkChoicePeer_nativeGetSelected
static void static void
selection_changed_cb (GtkComboBox *combobox, jobject peer) selection_changed_cb (GtkComboBox *combobox, jobject peer)
{ {
jstring label; gint index = gtk_combo_box_get_active(combobox);
GtkTreeModel *model;
GtkTreeIter iter;
gchar *selected;
gint index;
index = gtk_combo_box_get_active(combobox);
if (index >= 0) 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, (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer,
postChoiceItemEventID, postChoiceItemEventID, (jint)index );
label,
(jint) AWT_ITEM_SELECTED);
}
} }
static GtkWidget * static GtkWidget *
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment