From 41e1560d14f090c0c53e2cd8a96b0b2787d93c53 Mon Sep 17 00:00:00 2001 From: Andrei Dmitriev Date: Tue, 31 Aug 2010 15:05:09 +0400 Subject: [PATCH] 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 --- .../native/sun/windows/awt_MenuItem.cpp | 5 ++ .../native/sun/windows/awt_TextComponent.h | 2 - .../native/sun/windows/awt_TextField.cpp | 52 ++++++++++++++++--- .../native/sun/windows/awt_TextField.h | 9 +++- .../NullMenuLabelTest/NullMenuLabelTest.java | 26 ++++++++++ .../ScrollSelectionTest.java | 11 ++-- .../SpuriousExitEnter_3.java | 1 + 7 files changed, 90 insertions(+), 16 deletions(-) create mode 100644 jdk/test/java/awt/Menu/NullMenuLabelTest/NullMenuLabelTest.java diff --git a/jdk/src/windows/native/sun/windows/awt_MenuItem.cpp b/jdk/src/windows/native/sun/windows/awt_MenuItem.cpp index 67b2fa262a8..6ed2a73d6af 100644 --- a/jdk/src/windows/native/sun/windows/awt_MenuItem.cpp +++ b/jdk/src/windows/native/sun/windows/awt_MenuItem.cpp @@ -794,6 +794,11 @@ BOOL AwtMenuItem::IsSeparator() { 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); diff --git a/jdk/src/windows/native/sun/windows/awt_TextComponent.h b/jdk/src/windows/native/sun/windows/awt_TextComponent.h index 3a993742d11..7581c5c7aae 100644 --- a/jdk/src/windows/native/sun/windows/awt_TextComponent.h +++ b/jdk/src/windows/native/sun/windows/awt_TextComponent.h @@ -113,8 +113,6 @@ public: // Used to prevent untrusted code from synthesizing a WM_PASTE message // by posting a -V KeyEvent BOOL m_synthetic; - virtual void EditSetSel(CHARRANGE &cr) = 0; - virtual void EditGetSel(CHARRANGE &cr) = 0; virtual LONG EditGetCharFromPos(POINT& pt) = 0; private: diff --git a/jdk/src/windows/native/sun/windows/awt_TextField.cpp b/jdk/src/windows/native/sun/windows/awt_TextField.cpp index 94e8baca1b2..8f72dc06b56 100644 --- a/jdk/src/windows/native/sun/windows/awt_TextField.cpp +++ b/jdk/src/windows/native/sun/windows/awt_TextField.cpp @@ -41,7 +41,9 @@ struct SetEchoCharStruct { * AwtTextField methods */ -AwtTextField::AwtTextField() { +AwtTextField::AwtTextField() + : m_initialRescrollFlag( true ) +{ } /* Create a new AwtTextField object and window. */ @@ -116,10 +118,6 @@ void AwtTextField::EditSetSel(CHARRANGE &cr) { SendMessage(EM_SETSEL, cr.cpMin, cr.cpMax); } -void AwtTextField::EditGetSel(CHARRANGE &cr) { - SendMessage(EM_SETSEL, reinterpret_cast(&cr.cpMin), reinterpret_cast(&cr.cpMax)); -} - LONG AwtTextField::EditGetCharFromPos(POINT& pt) { return static_cast(SendMessage(EM_CHARFROMPOS, 0, MAKELPARAM(pt.x, pt.y))); } @@ -153,11 +151,9 @@ AwtTextField::HandleEvent(MSG *msg, BOOL synthetic) * 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 @@ AwtTextField::HandleEvent(MSG *msg, BOOL synthetic) SetStartSelectionPos(lCurPos); SetEndSelectionPos(lCurPos); } + CHARRANGE cr; cr.cpMin = GetStartSelectionPos(); cr.cpMax = GetEndSelectionPos(); EditSetSel(cr); @@ -310,6 +307,47 @@ ret: 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 */ diff --git a/jdk/src/windows/native/sun/windows/awt_TextField.h b/jdk/src/windows/native/sun/windows/awt_TextField.h index 177329cf860..a037adff795 100644 --- a/jdk/src/windows/native/sun/windows/awt_TextField.h +++ b/jdk/src/windows/native/sun/windows/awt_TextField.h @@ -55,9 +55,14 @@ public: static void _SetEchoChar(void *param); protected: - void EditSetSel(CHARRANGE &cr); - void EditGetSel(CHARRANGE &cr); LONG EditGetCharFromPos(POINT& pt); + virtual void Reshape(int x, int y, int w, int h); + +private: + void EditSetSel(CHARRANGE &cr); + void initialRescroll(); + + bool m_initialRescrollFlag; }; #endif /* AWT_TEXTFIELD_H */ diff --git a/jdk/test/java/awt/Menu/NullMenuLabelTest/NullMenuLabelTest.java b/jdk/test/java/awt/Menu/NullMenuLabelTest/NullMenuLabelTest.java new file mode 100644 index 00000000000..e779f40aab2 --- /dev/null +++ b/jdk/test/java/awt/Menu/NullMenuLabelTest/NullMenuLabelTest.java @@ -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 diff --git a/jdk/test/java/awt/TextField/ScrollSelectionTest/ScrollSelectionTest.java b/jdk/test/java/awt/TextField/ScrollSelectionTest/ScrollSelectionTest.java index 9f9073fb590..fb9df2cedab 100644 --- a/jdk/test/java/awt/TextField/ScrollSelectionTest/ScrollSelectionTest.java +++ b/jdk/test/java/awt/TextField/ScrollSelectionTest/ScrollSelectionTest.java @@ -53,13 +53,14 @@ public class ScrollSelectionTest extends Applet 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() diff --git a/jdk/test/java/awt/event/MouseEvent/SpuriousExitEnter/SpuriousExitEnter_3.java b/jdk/test/java/awt/event/MouseEvent/SpuriousExitEnter/SpuriousExitEnter_3.java index 2b03496b850..d2de08e0f72 100644 --- a/jdk/test/java/awt/event/MouseEvent/SpuriousExitEnter/SpuriousExitEnter_3.java +++ b/jdk/test/java/awt/event/MouseEvent/SpuriousExitEnter/SpuriousExitEnter_3.java @@ -114,6 +114,7 @@ public class SpuriousExitEnter_3 { checkEvents(frameAdapter, 1, 1); checkEvents(buttonAdapter, 0, 0); w.setVisible(false); + Util.waitForIdle(r); } public static void main(String []s)