src/windows/native/sun/windows/awt_Choice.cpp

Print this page

        

@@ -77,18 +77,21 @@
 
 BOOL AwtChoice::sm_isMouseMoveInList = FALSE;
 
 static const UINT MINIMUM_NUMBER_OF_VISIBLE_ITEMS = 8;
 
+namespace {
+    jfieldID selectedIndexID;
+}
+
 /*************************************************************************
  * AwtChoice class methods
  */
 
 AwtChoice::AwtChoice() {
     m_hList = NULL;
     m_listDefWindowProc = NULL;
-    m_selectedItem = -1;
 }
 
 LPCTSTR AwtChoice::GetClassName() {
     return TEXT("COMBOBOX");  /* System provided combobox class */
 }

@@ -100,11 +103,10 @@
     AwtComponent::Dispose();
 }
 
 AwtChoice* AwtChoice::Create(jobject peer, jobject parent) {
 
-
     JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
 
     jobject target = NULL;
     AwtChoice* c = NULL;
     RECT rc;

@@ -436,14 +438,18 @@
 
 
 MsgRouting AwtChoice::WmNotify(UINT notifyCode)
 {
     if (notifyCode == CBN_SELCHANGE) {
-        int selectedItem = (int)SendMessage(CB_GETCURSEL);
-        if (selectedItem != CB_ERR && m_selectedItem != selectedItem){
-            m_selectedItem = selectedItem;
-            DoCallback("handleAction", "(I)V", selectedItem);
+        int selectedIndex = (int)SendMessage(CB_GETCURSEL);
+        
+        JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
+        jobject target = GetTarget(env);
+        int previousIndex = env->GetIntField(target, selectedIndexID);
+        
+        if (selectedIndex != CB_ERR && selectedIndex != previousIndex){
+            DoCallback("handleAction", "(I)V", selectedIndex);
         }
     } else if (notifyCode == CBN_DROPDOWN) {
 
         if (m_hList == NULL) {
             COMBOBOXINFO cbi;

@@ -693,10 +699,19 @@
  * WChoicePeer native methods
  */
 
 extern "C" {
 
+JNIEXPORT void JNICALL
+Java_java_awt_Choice_initIDs(JNIEnv *env, jclass cls)
+{
+    TRY;
+    selectedIndexID = env->GetFieldID(cls, "selectedIndex", "I");
+    DASSERT(selectedIndexID);
+    CATCH_BAD_ALLOC;
+}
+
 /*
  * Class:     sun_awt_windows_WChoicePeer
  * Method:    select
  * Signature: (I)V
  */