changeset 2841:d3fdf9e7e9c2

6480547: REG: bug 4118621 which got Integrated in 1.1.8 fails in mustang from b25 onwards. 6808185: test/closed/java/awt/Menu/NullMenuLabelTest crashes Reviewed-by: dcherepanov
author dav
date Tue, 31 Aug 2010 15:05:09 +0400
parents 7e26538596be
children 7f8a9157544a
files src/windows/native/sun/windows/awt_MenuItem.cpp src/windows/native/sun/windows/awt_TextComponent.h src/windows/native/sun/windows/awt_TextField.cpp src/windows/native/sun/windows/awt_TextField.h test/java/awt/Menu/NullMenuLabelTest/NullMenuLabelTest.java test/java/awt/TextField/ScrollSelectionTest/ScrollSelectionTest.java test/java/awt/event/MouseEvent/SpuriousExitEnter/SpuriousExitEnter_3.java
diffstat 7 files changed, 90 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/src/windows/native/sun/windows/awt_MenuItem.cpp	Tue Aug 24 12:54:46 2010 +0400
+++ b/src/windows/native/sun/windows/awt_MenuItem.cpp	Tue Aug 31 15:05:09 2010 +0400
@@ -794,6 +794,11 @@
     jobject jitem = GetTarget(env);
     jstring label  =
         (jstring)(env)->GetObjectField(jitem, AwtMenuItem::labelID);
+    if (label == NULL) {
+        env->DeleteLocalRef(label);
+        env->DeleteLocalRef(jitem);
+        return FALSE; //separator must has '-' as label.
+    }
     LPCWSTR labelW = JNU_GetStringPlatformChars(env, label, NULL);
     BOOL isSeparator = (labelW && (wcscmp(labelW, L"-") == 0));
     JNU_ReleaseStringPlatformChars(env, label, labelW);
--- a/src/windows/native/sun/windows/awt_TextComponent.h	Tue Aug 24 12:54:46 2010 +0400
+++ b/src/windows/native/sun/windows/awt_TextComponent.h	Tue Aug 31 15:05:09 2010 +0400
@@ -113,8 +113,6 @@
     // Used to prevent untrusted code from synthesizing a WM_PASTE message
     // by posting a <CTRL>-V KeyEvent
     BOOL    m_synthetic;
-    virtual void EditSetSel(CHARRANGE &cr) = 0;
-    virtual void EditGetSel(CHARRANGE &cr) = 0;
     virtual LONG EditGetCharFromPos(POINT& pt) = 0;
 
 private:
--- a/src/windows/native/sun/windows/awt_TextField.cpp	Tue Aug 24 12:54:46 2010 +0400
+++ b/src/windows/native/sun/windows/awt_TextField.cpp	Tue Aug 31 15:05:09 2010 +0400
@@ -41,7 +41,9 @@
  * AwtTextField methods
  */
 
-AwtTextField::AwtTextField() {
+AwtTextField::AwtTextField()
+    : m_initialRescrollFlag( true )
+{
 }
 
 /* Create a new AwtTextField object and window.   */
@@ -116,10 +118,6 @@
     SendMessage(EM_SETSEL, cr.cpMin, cr.cpMax);
 }
 
-void AwtTextField::EditGetSel(CHARRANGE &cr) {
-    SendMessage(EM_SETSEL, reinterpret_cast<WPARAM>(&cr.cpMin), reinterpret_cast<LPARAM>(&cr.cpMax));
-}
-
 LONG AwtTextField::EditGetCharFromPos(POINT& pt) {
     return static_cast<LONG>(SendMessage(EM_CHARFROMPOS, 0, MAKELPARAM(pt.x, pt.y)));
 }
@@ -153,11 +151,9 @@
      * The workaround also allows us to implement synthetic focus mechanism.
      */
     if (IsFocusingMouseMessage(msg)) {
-        CHARRANGE cr;
 
         LONG lCurPos = EditGetCharFromPos(msg->pt);
 
-        EditGetSel(cr);
         /*
          * NOTE: Plain EDIT control always clears selection on mouse
          * button press. We are clearing the current selection only if
@@ -174,6 +170,7 @@
             SetStartSelectionPos(lCurPos);
             SetEndSelectionPos(lCurPos);
         }
+        CHARRANGE cr;
         cr.cpMin = GetStartSelectionPos();
         cr.cpMax = GetEndSelectionPos();
         EditSetSel(cr);
@@ -310,6 +307,47 @@
     delete secs;
 }
 
+void AwtTextField::Reshape(int x, int y, int w, int h)
+{
+    AwtTextComponent::Reshape( x, y, w, h );
+
+    // Another option would be to call this
+    // after WM_SIZE notification is handled
+    initialRescroll();
+}
+
+
+// Windows' Edit control features:
+// (i) if text selection is set while control's width or height is 0,
+//   text is scrolled oddly.
+// (ii) if control's size is changed, text seems never be automatically
+//   rescrolled.
+//
+// This method is designed for the following scenario: AWT spawns Edit
+// control with 0x0 dimensions, then sets text selection, then resizes the
+// control (couple of times). This might cause text appear undesirably scrolled.
+// So we reset/set selection again to rescroll text. (see also CR 6480547)
+void AwtTextField::initialRescroll()
+{
+    if( ! m_initialRescrollFlag ) {
+        return;
+    }
+
+    ::RECT r;
+    BOOL ok = ::GetClientRect( GetHWnd(), &r );
+    if( ! ok || r.right==0 || r.bottom==0 ) {
+        return;
+    }
+
+    m_initialRescrollFlag = false;
+
+    DWORD start, end;
+    SendMessage( EM_GETSEL, (WPARAM)&start, (LPARAM)&end );
+    SendMessage( EM_SETSEL, (WPARAM)0, (LPARAM)0 );
+    SendMessage( EM_SETSEL, (WPARAM)start, (LPARAM)end );
+}
+
+
 /************************************************************************
  * WTextFieldPeer native methods
  */
--- a/src/windows/native/sun/windows/awt_TextField.h	Tue Aug 24 12:54:46 2010 +0400
+++ b/src/windows/native/sun/windows/awt_TextField.h	Tue Aug 31 15:05:09 2010 +0400
@@ -55,9 +55,14 @@
     static void _SetEchoChar(void *param);
 
   protected:
+    LONG EditGetCharFromPos(POINT& pt);
+    virtual void Reshape(int x, int y, int w, int h);
+
+private:
     void EditSetSel(CHARRANGE &cr);
-    void EditGetSel(CHARRANGE &cr);
-    LONG EditGetCharFromPos(POINT& pt);
+    void initialRescroll();
+
+    bool m_initialRescrollFlag;
 };
 
 #endif /* AWT_TEXTFIELD_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/Menu/NullMenuLabelTest/NullMenuLabelTest.java	Tue Aug 31 15:05:09 2010 +0400
@@ -0,0 +1,26 @@
+/*      @test 1.5 98/07/23
+        @bug 4064202 4253466
+        @summary Test for Win32 NPE when MenuItem with null label added.
+        @author fred.ecks
+        @run main/othervm NullMenuLabelTest
+*/
+
+import java.awt.*;
+
+public class NullMenuLabelTest {
+
+    public static void main(String[] args) {
+        Frame frame = new Frame("Test Frame");
+        frame.pack();
+        frame.setVisible(true);
+        MenuBar menuBar = new MenuBar();
+        frame.setMenuBar(menuBar);
+        Menu menu = new Menu(null);
+        menuBar.add(menu);
+        menu.add(new MenuItem(null));
+        // If we got this far, the test succeeded
+        frame.setVisible(false);
+        frame.dispose();
+    }
+
+} // class NullMenuLabelTest
--- a/test/java/awt/TextField/ScrollSelectionTest/ScrollSelectionTest.java	Tue Aug 24 12:54:46 2010 +0400
+++ b/test/java/awt/TextField/ScrollSelectionTest/ScrollSelectionTest.java	Tue Aug 31 15:05:09 2010 +0400
@@ -53,13 +53,14 @@
       frame.add(tf);
       tf.select(0, 20);
 
-      String[] instructions =
-       {
+      String[] instructions = {
           "INSTRUCTIONS:",
           "This is a test for a win32 specific problem",
-          "If you see all the letters from 'a' to 'z' and",
-          "letters from 'a' to 't' are selected then test passes"
-       };
+         "If you see all the letters from 'a' to 'z' and",
+          "letters from 'a' to 't' are selected then test passes.",
+          "You may have to activate the frame to see the selection"
+          + " highlighted (e.g. by clicking on frame's title)."
+      };
       Sysout.createDialogWithInstructions( instructions );
 
     }// init()
--- a/test/java/awt/event/MouseEvent/SpuriousExitEnter/SpuriousExitEnter_3.java	Tue Aug 24 12:54:46 2010 +0400
+++ b/test/java/awt/event/MouseEvent/SpuriousExitEnter/SpuriousExitEnter_3.java	Tue Aug 31 15:05:09 2010 +0400
@@ -114,6 +114,7 @@
         checkEvents(frameAdapter, 1, 1);
         checkEvents(buttonAdapter, 0, 0);
         w.setVisible(false);
+        Util.waitForIdle(r);
     }
 
     public static void main(String []s)