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);
}
int selected = c.getSelectedIndex(); selected = c.getSelectedIndex();
if (selected >= 0) if( selected >= 0 )
select(selected); select( selected );
}
else
selected = -1;
} }
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(); // Ensure the triggering of an event when removing item zero if zero is the
// selected item, even though the selected index doesn't change.
nativeAdd (item, index); if( index == 0 && selected == 0 )
selected = -1;
/* Generate an ItemEvent if we added the first one or nativeRemove( index );
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) public void removeAll()
{
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 ()
{ {
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 )
{
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 );
} }
} }
...@@ -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.
...@@ -51,56 +51,47 @@ import javax.accessibility.AccessibleContext; ...@@ -51,56 +51,47 @@ import javax.accessibility.AccessibleContext;
import javax.accessibility.AccessibleRole; import javax.accessibility.AccessibleRole;
/** /**
* This class implements a drop down choice list. * This class implements a drop down choice list.
* *
* @author Aaron M. Renn (arenn@urbanophile.com) * @author Aaron M. Renn (arenn@urbanophile.com)
*/ */
public class Choice extends Component public class Choice extends Component
implements ItemSelectable, Serializable, Accessible implements ItemSelectable, Serializable, Accessible
{ {
/**
* The number used to generate the name returned by getName.
*/
private static transient long next_choice_number;
/* // Serialization constant
* Static Variables private static final long serialVersionUID = -4075310674757313071L;
*/
/**
* 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;
/*************************************************************************/
/* /**
* Instance Variables * @serial A list of items for the choice box, which can be <code>null</code>.
*/ * 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 <code>null</code>.
* This is package-private to avoid an accessor method.
*/
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.
* *
* @author Jerry Quinn (jlquinn@optonline.net) * @author Jerry Quinn (jlquinn@optonline.net)
* @author Andrew John Hughes (gnu_andrew@member.fsf.org) * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
*/ */
protected class AccessibleAWTChoice protected class AccessibleAWTChoice
extends AccessibleAWTComponent extends AccessibleAWTComponent
implements AccessibleAction implements AccessibleAction
{ {
/** /**
...@@ -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,397 +195,323 @@ private ItemListener item_listeners; ...@@ -211,397 +195,323 @@ private ItemListener item_listeners;
throw new HeadlessException (); throw new HeadlessException ();
} }
/*************************************************************************/ /**
* Returns the number of items in the list.
/* *
* Instance Methods * @return The number of items in the list.
*/ */
public int getItemCount()
/** {
* Returns the number of items in the list. return countItems ();
* }
* @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 <code>getItemCount</code>.
*/
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);
}
/*************************************************************************/
/** /**
* Adds the specified item to this choice box. * Returns the number of items in the list.
* *
* This method is oboslete since Java 2 platform 1.1. Please use @see add * @return The number of items in the list.
* instead. *
* * @deprecated This method is deprecated in favor of <code>getItemCount</code>.
* @param item The item to add. */
* public int countItems()
* @exception NullPointerException If the item's value is equal to null {
*/ return pItems.size();
public synchronized void }
addItem(String item)
{
add(item);
}
/*************************************************************************/ /**
* 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. * Adds the specified item to this choice box.
* If the currently selected item is shifted, then the first item is *
* selected. If the currently selected item is not shifted, then it * @param item The item to add.
* remains selected. *
* * @exception NullPointerException If the item's value is null
* @param item The item to add. *
* @param index The index at which the item should be inserted. * @since 1.1
* */
* @exception IllegalArgumentException If index is less than 0 public synchronized void add(String item)
*/ {
public synchronized void if (item == null)
insert(String item, int index) throw new NullPointerException ("item must be non-null");
{
if (index < 0)
throw new IllegalArgumentException ("index may not be less then 0");
if (index > getItemCount ()) pItems.addElement(item);
index = getItemCount ();
pItems.insertElementAt(item, index); if (peer != null)
((ChoicePeer) peer).add(item, getItemCount() - 1);
if (peer != null) if (selectedIndex == -1)
{ select( 0 );
ChoicePeer cp = (ChoicePeer) peer; }
cp.add (item, index);
}
else if (selectedIndex == -1 || selectedIndex >= index)
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);
}
/** /** Inserts an item into this Choice. Existing items are shifted
* Removes the specified item from the choice box. * 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
* @param item The item to remove. * selected. If the currently selected item is not shifted, then it
* * remains selected.
* @exception IllegalArgumentException If the specified item doesn't exist. *
*/ * @param item The item to add.
public synchronized void * @param index The index at which the item should be inserted.
remove(String item) *
{ * @exception IllegalArgumentException If index is less than 0
int index = pItems.indexOf(item); */
if (index == -1) public synchronized void insert(String item, int index)
throw new IllegalArgumentException ("item \"" {
+ item + "\" not found in Choice"); if (index < 0)
remove(index); throw new IllegalArgumentException ("index may not be less then 0");
}
/*************************************************************************/ if (index > getItemCount ())
index = getItemCount ();
/** pItems.insertElementAt(item, 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).add (item, index);
if (peer != null) if (selectedIndex == -1 || selectedIndex >= index)
{ select(0);
ChoicePeer cp = (ChoicePeer) peer; }
cp.remove (index);
}
else
{
if (getItemCount() == 0)
selectedIndex = -1;
else if (index == selectedIndex)
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. * 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;
pItems.removeAllElements (); pItems.removeAllElements ();
if (peer != null) if (peer != null)
{ {
ChoicePeer cp = (ChoicePeer) peer; ChoicePeer cp = (ChoicePeer) peer;
cp.removeAll (); 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);
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. * Returns an array with one row containing the selected item.
* *
* @return The index of the selected item. * @return An array containing the selected item.
*/ */
public int public synchronized Object[] getSelectedObjects()
getSelectedIndex() {
{ if (selectedIndex == -1)
return(selectedIndex); return null;
}
/*************************************************************************/ Object[] objs = new Object[1];
objs[0] = pItems.elementAt(selectedIndex);
/** return objs;
* 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);
}
} }
}
/*************************************************************************/ /**
* 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. * Forces the item at the specified index to be selected.
* *
* @param item The item to be selected. * @param index The index of the row to make selected.
* *
* @exception IllegalArgumentException If the specified item does not exist. * @exception IllegalArgumentException If the specified index is invalid.
*/ */
public synchronized void public synchronized void select(int index)
select(String item) {
{ if ((index < 0) || (index >= getItemCount()))
int index = pItems.indexOf(item); throw new IllegalArgumentException("Bad index: " + index);
if (index >= 0)
select(index);
}
/*************************************************************************/ if( selectedIndex == index )
return;
/** selectedIndex = index;
* Creates the native peer for this object. if( peer != null )
*/ ((ChoicePeer)peer).select( index );
public void }
addNotify()
{
if (peer == null)
peer = getToolkit ().createChoice (this);
super.addNotify ();
}
/*************************************************************************/ /**
* 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 * Creates the native peer for this object.
* this object. */
* public void addNotify()
* @param listener The listener to add. {
*/ if (peer == null)
public synchronized void peer = getToolkit ().createChoice (this);
addItemListener(ItemListener listener) super.addNotify ();
{ }
item_listeners = AWTEventMulticaster.add(item_listeners, listener);
}
/*************************************************************************/ /**
* 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 * 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
* event is an instance of <code>ItemEvent</code>, 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)
* Processes this event by invoking <code>processItemEvent()</code> if the {
* event is an instance of <code>ItemEvent</code>, 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
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 ) )
* Processes item event by dispatching to any registered listeners. processEvent(e);
* }
* @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);
}
/*************************************************************************/ /**
* 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. * 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;
...@@ -170,14 +138,16 @@ Java_gnu_java_awt_peer_gtk_GtkChoicePeer_nativeRemove ...@@ -170,14 +138,16 @@ 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 ();
} }
JNIEXPORT void JNICALL JNIEXPORT void JNICALL
Java_gnu_java_awt_peer_gtk_GtkChoicePeer_nativeRemoveAll Java_gnu_java_awt_peer_gtk_GtkChoicePeer_nativeRemoveAll
(JNIEnv *env, jobject obj) (JNIEnv *env, jobject obj)
{ {
void *ptr; void *ptr;
...@@ -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)
{ (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer,
model = gtk_combo_box_get_model (combobox); postChoiceItemEventID, (jint)index );
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);
}
} }
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