# HG changeset patch # User lana # Date 1339182022 25200 # Node ID c5ca850e1dff8401e692403f111fbbd36174bf1f # Parent 2e04ed1b4ce0ce0a93d651232fc2ddfa72b99b78# Parent 4157f2200059bfe755a3045d60aae6c4e68701a7 Merge diff -r 2e04ed1b4ce0 -r c5ca850e1dff jdk/src/macosx/classes/com/apple/laf/AquaInternalFrameUI.java --- a/jdk/src/macosx/classes/com/apple/laf/AquaInternalFrameUI.java Fri Jun 08 11:58:45 2012 -0700 +++ b/jdk/src/macosx/classes/com/apple/laf/AquaInternalFrameUI.java Fri Jun 08 12:00:22 2012 -0700 @@ -257,7 +257,7 @@ } public Dimension getPreferredSize(JComponent x) { - Dimension preferredSize = super.getMinimumSize(x); + Dimension preferredSize = super.getPreferredSize(x); Dimension minimumSize = frame.getMinimumSize(); if (preferredSize.width < minimumSize.width) { preferredSize.width = minimumSize.width; diff -r 2e04ed1b4ce0 -r c5ca850e1dff jdk/src/macosx/classes/com/apple/laf/AquaScrollPaneUI.java --- a/jdk/src/macosx/classes/com/apple/laf/AquaScrollPaneUI.java Fri Jun 08 11:58:45 2012 -0700 +++ b/jdk/src/macosx/classes/com/apple/laf/AquaScrollPaneUI.java Fri Jun 08 12:00:22 2012 -0700 @@ -60,6 +60,10 @@ if (wasVisible) { vScrollBar.setVisible(true); } + + // Consume the event even when the scrollBar is invisible + // see #7124320 + e.consume(); } } } diff -r 2e04ed1b4ce0 -r c5ca850e1dff jdk/src/macosx/classes/sun/awt/CGraphicsDevice.java --- a/jdk/src/macosx/classes/sun/awt/CGraphicsDevice.java Fri Jun 08 11:58:45 2012 -0700 +++ b/jdk/src/macosx/classes/sun/awt/CGraphicsDevice.java Fri Jun 08 12:00:22 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -29,6 +29,7 @@ import java.awt.GraphicsDevice; import java.awt.Window; import java.awt.AWTPermission; +import java.awt.DisplayMode; import sun.java2d.opengl.CGLGraphicsConfig; @@ -178,4 +179,33 @@ peer.exitFullScreenMode(); } } + + @Override + public boolean isDisplayChangeSupported() { + return true; + } + + @Override + public void setDisplayMode(DisplayMode dm) { + nativeSetDisplayMode(displayID, dm.getWidth(), dm.getHeight(), dm.getBitDepth(), dm.getRefreshRate()); + if (isFullScreenSupported() && getFullScreenWindow() != null) { + getFullScreenWindow().setSize(dm.getWidth(), dm.getHeight()); + } + } + + @Override + public DisplayMode getDisplayMode() { + return nativeGetDisplayMode(displayID); + } + + @Override + public DisplayMode[] getDisplayModes() { + return nativeGetDisplayModes(displayID); + } + + private native void nativeSetDisplayMode(int displayID, int w, int h, int bpp, int refrate); + + private native DisplayMode nativeGetDisplayMode(int displayID); + + private native DisplayMode[] nativeGetDisplayModes(int displayID); } diff -r 2e04ed1b4ce0 -r c5ca850e1dff jdk/src/macosx/classes/sun/awt/CGraphicsEnvironment.java --- a/jdk/src/macosx/classes/sun/awt/CGraphicsEnvironment.java Fri Jun 08 11:58:45 2012 -0700 +++ b/jdk/src/macosx/classes/sun/awt/CGraphicsEnvironment.java Fri Jun 08 12:00:22 2012 -0700 @@ -181,6 +181,10 @@ return devices.values().toArray(new CGraphicsDevice[devices.values().size()]); } + public synchronized GraphicsDevice getScreenDevice(int displayID) { + return devices.get(displayID); + } + @Override protected synchronized int getNumScreens() { return devices.size(); diff -r 2e04ed1b4ce0 -r c5ca850e1dff jdk/src/macosx/classes/sun/lwawt/LWListPeer.java --- a/jdk/src/macosx/classes/sun/lwawt/LWListPeer.java Fri Jun 08 11:58:45 2012 -0700 +++ b/jdk/src/macosx/classes/sun/lwawt/LWListPeer.java Fri Jun 08 12:00:22 2012 -0700 @@ -245,6 +245,15 @@ } } + @Override + public void setFont(Font font) { + super.setFont(font); + if (getView() != null) { + getView().setFont(font); + LWListPeer.this.revalidate(); + } + } + private final class JListDelegate extends JList { JListDelegate() { diff -r 2e04ed1b4ce0 -r c5ca850e1dff jdk/src/macosx/classes/sun/lwawt/LWWindowPeer.java --- a/jdk/src/macosx/classes/sun/lwawt/LWWindowPeer.java Fri Jun 08 11:58:45 2012 -0700 +++ b/jdk/src/macosx/classes/sun/lwawt/LWWindowPeer.java Fri Jun 08 12:00:22 2012 -0700 @@ -68,7 +68,7 @@ private Insets insets = new Insets(0, 0, 0, 0); - private int screenOn = -1; + private GraphicsDevice graphicsDevice; private GraphicsConfiguration graphicsConfig; private SurfaceData surfaceData; @@ -868,17 +868,6 @@ return 0; } - private static GraphicsConfiguration getScreenGraphicsConfig(int screen) { - GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); - GraphicsDevice[] gds = ge.getScreenDevices(); - if (screen >= gds.length) { - // This could happen during device addition/removal. Use - // the default screen device in this case - return ge.getDefaultScreenDevice().getDefaultConfiguration(); - } - return gds[screen].getDefaultConfiguration(); - } - /* * This method is called when window's graphics config is changed from * the app code (e.g. when the window is made non-opaque) or when @@ -893,7 +882,7 @@ } // If window's graphics config is changed from the app code, the // config correspond to the same device as before; when the window - // is moved by user, screenOn is updated in checkIfOnNewScreen(). + // is moved by user, graphicsDevice is updated in checkIfOnNewScreen(). // In either case, there's nothing to do with screenOn here graphicsConfig = gc; } @@ -902,16 +891,17 @@ } private void checkIfOnNewScreen() { - int windowScreen = platformWindow.getScreenImOn(); + GraphicsDevice newGraphicsDevice = platformWindow.getGraphicsDevice(); synchronized (getStateLock()) { - if (windowScreen == screenOn) { + if (graphicsDevice == newGraphicsDevice) { return; } - screenOn = windowScreen; + graphicsDevice = newGraphicsDevice; } // TODO: DisplayChangedListener stuff - final GraphicsConfiguration newGC = getScreenGraphicsConfig(windowScreen); + final GraphicsConfiguration newGC = newGraphicsDevice.getDefaultConfiguration(); + if (!setGraphicsConfig(newGC)) return; SunToolkit.executeOnEventHandlerThread(getTarget(), new Runnable() { diff -r 2e04ed1b4ce0 -r c5ca850e1dff jdk/src/macosx/classes/sun/lwawt/PlatformWindow.java --- a/jdk/src/macosx/classes/sun/lwawt/PlatformWindow.java Fri Jun 08 11:58:45 2012 -0700 +++ b/jdk/src/macosx/classes/sun/lwawt/PlatformWindow.java Fri Jun 08 12:00:22 2012 -0700 @@ -67,9 +67,9 @@ public void setBounds(int x, int y, int w, int h); /* - * Returns the screen number where the window is. + * Returns the graphics device where the window is. */ - public int getScreenImOn(); + public GraphicsDevice getGraphicsDevice(); /* * Returns the location of the window. diff -r 2e04ed1b4ce0 -r c5ca850e1dff jdk/src/macosx/classes/sun/lwawt/macosx/CCustomCursor.java --- a/jdk/src/macosx/classes/sun/lwawt/macosx/CCustomCursor.java Fri Jun 08 11:58:45 2012 -0700 +++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CCustomCursor.java Fri Jun 08 12:00:22 2012 -0700 @@ -26,6 +26,7 @@ package sun.lwawt.macosx; import java.awt.*; +import java.awt.image.BufferedImage; public class CCustomCursor extends Cursor { static Dimension sMaxCursorSize; @@ -36,7 +37,6 @@ } Image fImage; - private boolean isImageOk = false; Point fHotspot; public CCustomCursor(final Image cursor, final Point hotSpot, final String name) throws IndexOutOfBoundsException, HeadlessException { @@ -61,21 +61,19 @@ // Fix for bug 4212593 The Toolkit.createCustomCursor does not // check absence of the image of cursor // If the image is invalid, the cursor will be hidden (made completely - // transparent). In this case, getBestCursorSize() will adjust negative w and h, - // but we need to set the hotspot inside the image here. + // transparent). if (tracker.isErrorAny() || width < 0 || height < 0) { fHotspot.x = fHotspot.y = 0; - isImageOk = false; + width = height = 1; + fImage = createTransparentImage(width, height); } else { - isImageOk = true; - } - - // Scale image to nearest supported size - final Dimension nativeSize = toolkit.getBestCursorSize(width, height); - if (nativeSize.width != width || nativeSize.height != height) { - fImage = fImage.getScaledInstance(nativeSize.width, nativeSize.height, Image.SCALE_DEFAULT); - width = nativeSize.width; - height = nativeSize.height; + // Scale image to nearest supported size + final Dimension nativeSize = toolkit.getBestCursorSize(width, height); + if (nativeSize.width != width || nativeSize.height != height) { + fImage = fImage.getScaledInstance(nativeSize.width, nativeSize.height, Image.SCALE_DEFAULT); + width = nativeSize.width; + height = nativeSize.height; + } } // NOTE: this was removed for 3169146, but in 1.5 the JCK tests for an exception and fails if one isn't thrown. @@ -98,6 +96,21 @@ } } + private static BufferedImage createTransparentImage(int w, int h) { + GraphicsEnvironment ge = + GraphicsEnvironment.getLocalGraphicsEnvironment(); + GraphicsDevice gs = ge.getDefaultScreenDevice(); + GraphicsConfiguration gc = gs.getDefaultConfiguration(); + + BufferedImage img = gc.createCompatibleImage(w, h, Transparency.BITMASK); + Graphics2D g = (Graphics2D)img.getGraphics(); + g.setBackground(new Color(0, 0, 0, 0)); + g.clearRect(0, 0, w, h); + g.dispose(); + + return img; + } + public static Dimension getBestCursorSize(final int preferredWidth, final int preferredHeight) { // With Panther, cursors have no limit on their size. So give the client their // preferred size, but no larger than half the dimensions of the main screen @@ -111,31 +124,26 @@ } // Called from native when the cursor is set - // Returns long array of [NSImage ptr, x hotspot, y hotspot] CImage fCImage; long getImageData() { if (fCImage != null) { return fCImage.ptr; } - if (isImageOk) { - try { - fCImage = CImage.getCreator().createFromImage(fImage); - - if (fCImage == null) { - isImageOk = false; - return 0L; - } else { - return fCImage.ptr; - } - } catch (IllegalArgumentException iae) { - // Silently return null - we want to hide cursor by providing an empty - // ByteArray or just null + try { + fCImage = CImage.getCreator().createFromImage(fImage); + if (fCImage == null) { + // Something unexpected happened: CCustomCursor constructor + // takes care of invalid cursor images, yet createFromImage() + // failed to do its job. Return null to keep the cursor unchanged. return 0L; + } else { + return fCImage.ptr; } + } catch (IllegalArgumentException iae) { + // see comment above + return 0L; } - - return 0L; } Point getHotSpot() { diff -r 2e04ed1b4ce0 -r c5ca850e1dff jdk/src/macosx/classes/sun/lwawt/macosx/CPlatformEmbeddedFrame.java --- a/jdk/src/macosx/classes/sun/lwawt/macosx/CPlatformEmbeddedFrame.java Fri Jun 08 11:58:45 2012 -0700 +++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CPlatformEmbeddedFrame.java Fri Jun 08 12:00:22 2012 -0700 @@ -86,11 +86,10 @@ } @Override - public int getScreenImOn() { + public GraphicsDevice getGraphicsDevice() { // REMIND: return the main screen for the initial implementation - CGraphicsConfig gc = (CGraphicsConfig)peer.getGraphicsConfiguration(); - CGraphicsDevice device = gc.getDevice(); - return device.getCoreGraphicsScreen(); + GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); + return ge.getDefaultScreenDevice(); } @Override diff -r 2e04ed1b4ce0 -r c5ca850e1dff jdk/src/macosx/classes/sun/lwawt/macosx/CPlatformResponder.java --- a/jdk/src/macosx/classes/sun/lwawt/macosx/CPlatformResponder.java Fri Jun 08 11:58:45 2012 -0700 +++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CPlatformResponder.java Fri Jun 08 12:00:22 2012 -0700 @@ -109,8 +109,14 @@ final long when = System.currentTimeMillis(); final int scrollType = MouseWheelEvent.WHEEL_UNIT_SCROLL; final int scrollAmount = 1; + int wheelRotation = (int) delta; + int signum = (int) Math.signum(delta); + if (signum * delta < 1) { + wheelRotation = signum; + } + // invert the wheelRotation for the peer peer.dispatchMouseWheelEvent(when, x, y, modifiers, scrollType, - scrollAmount, (int) -delta, -delta, null); + scrollAmount, -wheelRotation, -delta, null); } /** diff -r 2e04ed1b4ce0 -r c5ca850e1dff jdk/src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java --- a/jdk/src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java Fri Jun 08 11:58:45 2012 -0700 +++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java Fri Jun 08 12:00:22 2012 -0700 @@ -64,7 +64,7 @@ private static native void nativeSetEnabled(long nsWindowPtr, boolean isEnabled); private static native void nativeSynthesizeMouseEnteredExitedEvents(long nsWindowPtr); - private static native int nativeGetScreenNSWindowIsOn_AppKitThread(long nsWindowPtr); + private static native int nativeGetNSWindowDisplayID_AppKitThread(long nsWindowPtr); // Loger to report issues happened during execution but that do not affect functionality private static final PlatformLogger logger = PlatformLogger.getLogger("sun.lwawt.macosx.CPlatformWindow"); @@ -452,13 +452,18 @@ return new Point(nativeBounds.x, nativeBounds.y); } - @Override // PlatformWindow - public int getScreenImOn() { - // REMIND: we could also acquire screenID from the - // graphicsConfig.getDevice().getCoreGraphicsScreen() - // which might look a bit less natural but don't - // require new native accessor. - return nativeGetScreenNSWindowIsOn_AppKitThread(getNSWindowPtr()); + @Override + public GraphicsDevice getGraphicsDevice() { + GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); + CGraphicsEnvironment cge = (CGraphicsEnvironment)ge; + int displayID = nativeGetNSWindowDisplayID_AppKitThread(getNSWindowPtr()); + GraphicsDevice gd = cge.getScreenDevice(displayID); + if (gd == null) { + // this could possibly happen during device removal + // use the default screen device in this case + gd = ge.getDefaultScreenDevice(); + } + return gd; } @Override // PlatformWindow diff -r 2e04ed1b4ce0 -r c5ca850e1dff jdk/src/macosx/native/sun/awt/AWTWindow.h --- a/jdk/src/macosx/native/sun/awt/AWTWindow.h Fri Jun 08 11:58:45 2012 -0700 +++ b/jdk/src/macosx/native/sun/awt/AWTWindow.h Fri Jun 08 12:00:22 2012 -0700 @@ -43,6 +43,7 @@ NSSize javaMaxSize; jint styleBits; BOOL isEnabled; + NSWindow *nsWindow; } // An instance of either AWTWindow_Normal or AWTWindow_Panel diff -r 2e04ed1b4ce0 -r c5ca850e1dff jdk/src/macosx/native/sun/awt/AWTWindow.m --- a/jdk/src/macosx/native/sun/awt/AWTWindow.m Fri Jun 08 11:58:45 2012 -0700 +++ b/jdk/src/macosx/native/sun/awt/AWTWindow.m Fri Jun 08 12:00:22 2012 -0700 @@ -1080,39 +1080,29 @@ /* * Class: sun_lwawt_macosx_CPlatformWindow - * Method: nativeGetScreenNSWindowIsOn_AppKitThread + * Method: nativeGetDisplayID_AppKitThread * Signature: (J)I */ -JNIEXPORT jint JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeGetScreenNSWindowIsOn_1AppKitThread +JNIEXPORT jint JNICALL +Java_sun_lwawt_macosx_CPlatformWindow_nativeGetNSWindowDisplayID_1AppKitThread (JNIEnv *env, jclass clazz, jlong windowPtr) { - jint index = -1; + jint ret; // CGDirectDisplayID JNF_COCOA_ENTER(env); AWT_ASSERT_APPKIT_THREAD; - NSWindow *nsWindow = OBJC(windowPtr); - NSScreen* screen = [nsWindow screen]; - - //+++gdb NOTE: This is using a linear search of the screens. If it should - // prove to be a bottleneck, this can definitely be improved. However, - // many screens should prove to be the exception, rather than the rule. - NSArray* screens = [NSScreen screens]; - NSUInteger i; - for (i = 0; i < [screens count]; i++) - { - if ([[screens objectAtIndex:i] isEqualTo:screen]) - { - index = i; - break; - } - } + NSWindow *window = OBJC(windowPtr); + NSScreen *screen = [window screen]; + NSDictionary *deviceDescription = [screen deviceDescription]; + NSNumber *displayID = [deviceDescription objectForKey:@"NSScreenNumber"]; + ret = (jint)[displayID intValue]; JNF_COCOA_EXIT(env); - return 1; + + return ret; } - /* * Class: sun_lwawt_macosx_CPlatformWindow * Method: _toggleFullScreenMode diff -r 2e04ed1b4ce0 -r c5ca850e1dff jdk/src/macosx/native/sun/awt/CGraphicsDevice.m --- a/jdk/src/macosx/native/sun/awt/CGraphicsDevice.m Fri Jun 08 11:58:45 2012 -0700 +++ b/jdk/src/macosx/native/sun/awt/CGraphicsDevice.m Fri Jun 08 12:00:22 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -26,6 +26,84 @@ #include "LWCToolkit.h" /* + * Convert the mode string to the more convinient bits per pixel value + */ +static int getBPPFromModeString(CFStringRef mode) +{ + if ((CFStringCompare(mode, CFSTR(kIO30BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo)) { + // This is a strange mode, where we using 10 bits per RGB component and pack it into 32 bits + // Java is not ready to work with this mode but we have to specify it as supported + return 30; + } + else if (CFStringCompare(mode, CFSTR(IO32BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo) { + return 32; + } + else if (CFStringCompare(mode, CFSTR(IO16BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo) { + return 16; + } + else if (CFStringCompare(mode, CFSTR(IO8BitIndexedPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo) { + return 8; + } + + return 0; +} + +/* + * Find the best possible match in the list of display modes that we can switch to based on + * the provided parameters. + */ +static CGDisplayModeRef getBestModeForParameters(CFArrayRef allModes, int w, int h, int bpp, int refrate) { + CGDisplayModeRef bestGuess = NULL; + CFIndex numModes = CFArrayGetCount(allModes), n; + int thisBpp = 0; + for(n = 0; n < numModes; n++ ) { + CGDisplayModeRef cRef = (CGDisplayModeRef) CFArrayGetValueAtIndex(allModes, n); + if(cRef == NULL) { + continue; + } + CFStringRef modeString = CGDisplayModeCopyPixelEncoding(cRef); + thisBpp = getBPPFromModeString(modeString); + CFRelease(modeString); + if (thisBpp != bpp || (int)CGDisplayModeGetHeight(cRef) != h || (int)CGDisplayModeGetWidth(cRef) != w) { + // One of the key parameters does not match + continue; + } + // Refresh rate might be 0 in display mode and we ask for specific display rate + // but if we do not find exact match then 0 refresh rate might be just Ok + if (CGDisplayModeGetRefreshRate(cRef) == refrate) { + // Exact match + return cRef; + } + if (CGDisplayModeGetRefreshRate(cRef) == 0) { + // Not exactly what was asked for, but may fit our needs if we don't find an exact match + bestGuess = cRef; + } + } + return bestGuess; +} + +/* + * Create a new java.awt.DisplayMode instance based on provided CGDisplayModeRef + */ +static jobject createJavaDisplayMode(CGDisplayModeRef mode, JNIEnv *env, jint displayID) { + jobject ret = NULL; + jint h, w, bpp, refrate; + JNF_COCOA_ENTER(env); + CFStringRef currentBPP = CGDisplayModeCopyPixelEncoding(mode); + bpp = getBPPFromModeString(currentBPP); + refrate = CGDisplayModeGetRefreshRate(mode); + h = CGDisplayModeGetHeight(mode); + w = CGDisplayModeGetWidth(mode); + CFRelease(currentBPP); + static JNF_CLASS_CACHE(jc_DisplayMode, "java/awt/DisplayMode"); + static JNF_CTOR_CACHE(jc_DisplayMode_ctor, jc_DisplayMode, "(IIII)V"); + ret = JNFNewObject(env, jc_DisplayMode_ctor, w, h, bpp, refrate); + JNF_COCOA_EXIT(env); + return ret; +} + + +/* * Class: sun_awt_CGraphicsDevice * Method: nativeGetXResolution * Signature: (I)D @@ -62,3 +140,89 @@ jfloat dpi = rect.size.height / inches; return dpi; } + +/* + * Class: sun_awt_CGraphicsDevice + * Method: nativeSetDisplayMode + * Signature: (IIIII)V + */ +JNIEXPORT void JNICALL +Java_sun_awt_CGraphicsDevice_nativeSetDisplayMode +(JNIEnv *env, jclass class, jint displayID, jint w, jint h, jint bpp, jint refrate) +{ + JNF_COCOA_ENTER(env); + CFArrayRef allModes = CGDisplayCopyAllDisplayModes(displayID, NULL); + CGDisplayModeRef closestMatch = getBestModeForParameters(allModes, (int)w, (int)h, (int)bpp, (int)refrate); + if (closestMatch != NULL) { + [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){ + CGDisplayConfigRef config; + CGError retCode = CGBeginDisplayConfiguration(&config); + if (retCode == kCGErrorSuccess) { + CGConfigureDisplayWithDisplayMode(config, displayID, closestMatch, NULL); + CGCompleteDisplayConfiguration(config, kCGConfigureForAppOnly); + if (config != NULL) { + CFRelease(config); + } + } + }]; + } + CFRelease(allModes); + JNF_COCOA_EXIT(env); +} + +/* + * Class: sun_awt_CGraphicsDevice + * Method: nativeGetDisplayMode + * Signature: (I)Ljava/awt/DisplayMode + */ +JNIEXPORT jobject JNICALL +Java_sun_awt_CGraphicsDevice_nativeGetDisplayMode +(JNIEnv *env, jclass class, jint displayID) +{ + jobject ret = NULL; + CGDisplayModeRef currentMode = CGDisplayCopyDisplayMode(displayID); + ret = createJavaDisplayMode(currentMode, env, displayID); + CGDisplayModeRelease(currentMode); + return ret; +} + +/* + * Class: sun_awt_CGraphicsDevice + * Method: nativeGetDisplayMode + * Signature: (I)[Ljava/awt/DisplayModes + */ +JNIEXPORT jobjectArray JNICALL +Java_sun_awt_CGraphicsDevice_nativeGetDisplayModes +(JNIEnv *env, jclass class, jint displayID) +{ + jobjectArray jreturnArray = NULL; + JNF_COCOA_ENTER(env); + CFArrayRef allModes = CGDisplayCopyAllDisplayModes(displayID, NULL); + CFIndex numModes = CFArrayGetCount(allModes); + static JNF_CLASS_CACHE(jc_DisplayMode, "java/awt/DisplayMode"); + + jreturnArray = JNFNewObjectArray(env, &jc_DisplayMode, (jsize) numModes); + if (!jreturnArray) { + NSLog(@"CGraphicsDevice can't create java array of DisplayMode objects"); + return nil; + } + + CFIndex n; + for (n=0; n < numModes; n++) { + CGDisplayModeRef cRef = (CGDisplayModeRef) CFArrayGetValueAtIndex(allModes, n); + if (cRef != NULL) { + jobject oneMode = createJavaDisplayMode(cRef, env, displayID); + (*env)->SetObjectArrayElement(env, jreturnArray, n, oneMode); + if ((*env)->ExceptionOccurred(env)) { + (*env)->ExceptionDescribe(env); + (*env)->ExceptionClear(env); + continue; + } + (*env)->DeleteLocalRef(env, oneMode); + } + } + CFRelease(allModes); + JNF_COCOA_EXIT(env); + + return jreturnArray; +} diff -r 2e04ed1b4ce0 -r c5ca850e1dff jdk/src/share/classes/java/awt/KeyboardFocusManager.java --- a/jdk/src/share/classes/java/awt/KeyboardFocusManager.java Fri Jun 08 11:58:45 2012 -0700 +++ b/jdk/src/share/classes/java/awt/KeyboardFocusManager.java Fri Jun 08 12:00:22 2012 -0700 @@ -561,7 +561,7 @@ rootAncestor = (Container)focusOwner; } if (rootAncestor != null) { - setGlobalCurrentFocusCycleRoot(rootAncestor); + setGlobalCurrentFocusCycleRootPriv(rootAncestor); } } diff -r 2e04ed1b4ce0 -r c5ca850e1dff jdk/src/share/classes/javax/swing/JPopupMenu.java --- a/jdk/src/share/classes/javax/swing/JPopupMenu.java Fri Jun 08 11:58:45 2012 -0700 +++ b/jdk/src/share/classes/javax/swing/JPopupMenu.java Fri Jun 08 12:00:22 2012 -0700 @@ -826,7 +826,7 @@ popupFactory.setPopupType(PopupFactory.LIGHT_WEIGHT_POPUP); } else { - popupFactory.setPopupType(PopupFactory.MEDIUM_WEIGHT_POPUP); + popupFactory.setPopupType(PopupFactory.HEAVY_WEIGHT_POPUP); } // adjust the location of the popup @@ -853,6 +853,11 @@ /** * Sets the location of the upper left corner of the * popup menu using x, y coordinates. + *

+ * The method changes the geometry-related data. Therefore, + * the native windowing system may ignore such requests, or it may modify + * the requested data, so that the {@code JPopupMenu} object is placed and sized + * in a way that corresponds closely to the desktop settings. * * @param x the x coordinate of the popup's new position * in the screen's coordinate space diff -r 2e04ed1b4ce0 -r c5ca850e1dff jdk/src/share/classes/javax/swing/PopupFactory.java --- a/jdk/src/share/classes/javax/swing/PopupFactory.java Fri Jun 08 11:58:45 2012 -0700 +++ b/jdk/src/share/classes/javax/swing/PopupFactory.java Fri Jun 08 12:00:22 2012 -0700 @@ -203,12 +203,6 @@ popupType = HEAVY_WEIGHT_POPUP; break; } - } else if (c instanceof Window) { - Window w = (Window) c; - if (!w.isOpaque() || w.getOpacity() < 1 || w.getShape() != null) { - popupType = HEAVY_WEIGHT_POPUP; - break; - } } c = c.getParent(); } diff -r 2e04ed1b4ce0 -r c5ca850e1dff jdk/src/share/demo/jfc/TransparentRuler/transparentruler/Ruler.java --- a/jdk/src/share/demo/jfc/TransparentRuler/transparentruler/Ruler.java Fri Jun 08 11:58:45 2012 -0700 +++ b/jdk/src/share/demo/jfc/TransparentRuler/transparentruler/Ruler.java Fri Jun 08 12:00:22 2012 -0700 @@ -134,6 +134,9 @@ { jPopupMenu.add(new JMenuItem(exitAction)); + + // To avoid popup cutting by main window shape forbid light-weight popups + jPopupMenu.setLightWeightPopupEnabled(false); } /** diff -r 2e04ed1b4ce0 -r c5ca850e1dff jdk/src/solaris/classes/sun/awt/X11/XDecoratedPeer.java --- a/jdk/src/solaris/classes/sun/awt/X11/XDecoratedPeer.java Fri Jun 08 11:58:45 2012 -0700 +++ b/jdk/src/solaris/classes/sun/awt/X11/XDecoratedPeer.java Fri Jun 08 12:00:22 2012 -0700 @@ -721,15 +721,17 @@ // Location, Client size + insets newLocation = new Point(xe.get_x() - currentInsets.left, xe.get_y() - currentInsets.top); } else { - // CDE/MWM/Metacity/Sawfish bug: if shell is resized using - // top or left border, we don't receive synthetic - // ConfigureNotify, only the one from X with zero - // coordinates. This is the workaround to get real - // location, 6261336 + // ICCCM 4.1.5 states that a real ConfigureNotify will be sent when + // a window is resized but the client can not tell if the window was + // moved or not. The client should consider the position as unkown + // and use TranslateCoordinates to find the actual position. + // + // TODO this should be the default for every case. switch (XWM.getWMID()) { case XWM.CDE_WM: case XWM.MOTIF_WM: case XWM.METACITY_WM: + case XWM.MUTTER_WM: case XWM.SAWFISH_WM: { Point xlocation = queryXLocation(); diff -r 2e04ed1b4ce0 -r c5ca850e1dff jdk/src/solaris/classes/sun/awt/X11/XKeysym.java --- a/jdk/src/solaris/classes/sun/awt/X11/XKeysym.java Fri Jun 08 11:58:45 2012 -0700 +++ b/jdk/src/solaris/classes/sun/awt/X11/XKeysym.java Fri Jun 08 12:00:22 2012 -0700 @@ -1416,6 +1416,7 @@ keysym2JavaKeycodeHash.put( Long.valueOf(XKeySymConstants.XK_Meta_L), new Keysym2JavaKeycode(java.awt.event.KeyEvent.VK_META, java.awt.event.KeyEvent.KEY_LOCATION_LEFT)); keysym2JavaKeycodeHash.put( Long.valueOf(XKeySymConstants.XK_Meta_R), new Keysym2JavaKeycode(java.awt.event.KeyEvent.VK_META, java.awt.event.KeyEvent.KEY_LOCATION_RIGHT)); keysym2JavaKeycodeHash.put( Long.valueOf(XKeySymConstants.XK_Caps_Lock), new Keysym2JavaKeycode(java.awt.event.KeyEvent.VK_CAPS_LOCK, java.awt.event.KeyEvent.KEY_LOCATION_STANDARD)); + keysym2JavaKeycodeHash.put( Long.valueOf(XKeySymConstants.XK_Shift_Lock), new Keysym2JavaKeycode(java.awt.event.KeyEvent.VK_CAPS_LOCK, java.awt.event.KeyEvent.KEY_LOCATION_STANDARD)); /* Misc Functions */ keysym2JavaKeycodeHash.put( Long.valueOf(XKeySymConstants.XK_Print), new Keysym2JavaKeycode(java.awt.event.KeyEvent.VK_PRINTSCREEN, java.awt.event.KeyEvent.KEY_LOCATION_STANDARD)); @@ -1590,6 +1591,21 @@ keysym2JavaKeycodeHash.put( Long.valueOf(XKeySymConstants.XK_Kanji), new Keysym2JavaKeycode(java.awt.event.KeyEvent.VK_CONVERT, java.awt.event.KeyEvent.KEY_LOCATION_STANDARD)); /* Type 5c Japanese keyboard: nihongo */ keysym2JavaKeycodeHash.put( Long.valueOf(XKeySymConstants.XK_Henkan_Mode), new Keysym2JavaKeycode(java.awt.event.KeyEvent.VK_INPUT_METHOD_ON_OFF, java.awt.event.KeyEvent.KEY_LOCATION_STANDARD)); + keysym2JavaKeycodeHash.put( Long.valueOf(XKeySymConstants.XK_Eisu_Shift ), new Keysym2JavaKeycode(java.awt.event.KeyEvent.VK_ALPHANUMERIC , java.awt.event.KeyEvent.KEY_LOCATION_STANDARD)); + keysym2JavaKeycodeHash.put( Long.valueOf(XKeySymConstants.XK_Eisu_toggle ), new Keysym2JavaKeycode(java.awt.event.KeyEvent.VK_ALPHANUMERIC , java.awt.event.KeyEvent.KEY_LOCATION_STANDARD)); + keysym2JavaKeycodeHash.put( Long.valueOf(XKeySymConstants.XK_Zenkaku ), new Keysym2JavaKeycode(java.awt.event.KeyEvent.VK_FULL_WIDTH , java.awt.event.KeyEvent.KEY_LOCATION_STANDARD)); + keysym2JavaKeycodeHash.put( Long.valueOf(XKeySymConstants.XK_Hankaku ), new Keysym2JavaKeycode(java.awt.event.KeyEvent.VK_HALF_WIDTH , java.awt.event.KeyEvent.KEY_LOCATION_STANDARD)); + keysym2JavaKeycodeHash.put( Long.valueOf(XKeySymConstants.XK_Hiragana ), new Keysym2JavaKeycode(java.awt.event.KeyEvent.VK_HIRAGANA , java.awt.event.KeyEvent.KEY_LOCATION_STANDARD)); + keysym2JavaKeycodeHash.put( Long.valueOf(XKeySymConstants.XK_Katakana ), new Keysym2JavaKeycode(java.awt.event.KeyEvent.VK_KATAKANA , java.awt.event.KeyEvent.KEY_LOCATION_STANDARD)); + keysym2JavaKeycodeHash.put( Long.valueOf(XKeySymConstants.XK_Romaji ), new Keysym2JavaKeycode(java.awt.event.KeyEvent.VK_JAPANESE_ROMAN , java.awt.event.KeyEvent.KEY_LOCATION_STANDARD)); + keysym2JavaKeycodeHash.put( Long.valueOf(XKeySymConstants.XK_Kana_Shift ), new Keysym2JavaKeycode(java.awt.event.KeyEvent.VK_KANA , java.awt.event.KeyEvent.KEY_LOCATION_STANDARD)); + keysym2JavaKeycodeHash.put( Long.valueOf(XKeySymConstants.XK_Kana_Lock ), new Keysym2JavaKeycode(java.awt.event.KeyEvent.VK_KANA_LOCK , java.awt.event.KeyEvent.KEY_LOCATION_STANDARD)); + keysym2JavaKeycodeHash.put( Long.valueOf(XKeySymConstants.XK_Muhenkan ), new Keysym2JavaKeycode(java.awt.event.KeyEvent.VK_NONCONVERT , java.awt.event.KeyEvent.KEY_LOCATION_STANDARD)); + keysym2JavaKeycodeHash.put( Long.valueOf(XKeySymConstants.XK_Zen_Koho ), new Keysym2JavaKeycode(java.awt.event.KeyEvent.VK_ALL_CANDIDATES , java.awt.event.KeyEvent.KEY_LOCATION_STANDARD)); + keysym2JavaKeycodeHash.put( Long.valueOf(XKeySymConstants.XK_Kanji_Bangou ), new Keysym2JavaKeycode(java.awt.event.KeyEvent.VK_CODE_INPUT , java.awt.event.KeyEvent.KEY_LOCATION_STANDARD)); + keysym2JavaKeycodeHash.put( Long.valueOf(XKeySymConstants.XK_Mae_Koho ), new Keysym2JavaKeycode(java.awt.event.KeyEvent.VK_PREVIOUS_CANDIDATE , java.awt.event.KeyEvent.KEY_LOCATION_STANDARD)); + + /* VK_KANA_LOCK is handled separately because it generates the * same keysym as ALT_GRAPH in spite of its different behavior. */ diff -r 2e04ed1b4ce0 -r c5ca850e1dff jdk/src/solaris/classes/sun/awt/X11/XLabelPeer.java --- a/jdk/src/solaris/classes/sun/awt/X11/XLabelPeer.java Fri Jun 08 11:58:45 2012 -0700 +++ b/jdk/src/solaris/classes/sun/awt/X11/XLabelPeer.java Fri Jun 08 12:00:22 2012 -0700 @@ -141,7 +141,7 @@ } public void setFont(Font f) { super.setFont(f); - target.repaint(); + repaint(); } public void setAlignment(int align) { diff -r 2e04ed1b4ce0 -r c5ca850e1dff jdk/src/solaris/classes/sun/awt/X11/XWM.java --- a/jdk/src/solaris/classes/sun/awt/X11/XWM.java Fri Jun 08 11:58:45 2012 -0700 +++ b/jdk/src/solaris/classes/sun/awt/X11/XWM.java Fri Jun 08 12:00:22 2012 -0700 @@ -102,7 +102,8 @@ METACITY_WM = 11, COMPIZ_WM = 12, LG3D_WM = 13, - CWM_WM = 14; + CWM_WM = 14, + MUTTER_WM = 15; public String toString() { switch (WMID) { case NO_WM: @@ -131,6 +132,8 @@ return "LookingGlass"; case CWM_WM: return "CWM"; + case MUTTER_WM: + return "Mutter"; case UNDETERMINED_WM: default: return "Undetermined WM"; @@ -573,6 +576,10 @@ // getIntProperty(XToolkit.getDefaultRootWindow(), XAtom.XA_CARDINAL)) == 0); } + static boolean isMutter() { + return isNetWMName("Mutter"); + } + static boolean isNonReparentingWM() { return (XWM.getWMID() == XWM.COMPIZ_WM || XWM.getWMID() == XWM.LG3D_WM || XWM.getWMID() == XWM.CWM_WM); } @@ -742,6 +749,8 @@ awt_wmgr = XWM.ENLIGHTEN_WM; } else if (isMetacity()) { awt_wmgr = XWM.METACITY_WM; + } else if (isMutter()) { + awt_wmgr = XWM.MUTTER_WM; } else if (isSawfish()) { awt_wmgr = XWM.SAWFISH_WM; } else if (isKDE2()) { diff -r 2e04ed1b4ce0 -r c5ca850e1dff jdk/src/solaris/native/java/lang/java_props_md.c --- a/jdk/src/solaris/native/java/lang/java_props_md.c Fri Jun 08 11:58:45 2012 -0700 +++ b/jdk/src/solaris/native/java/lang/java_props_md.c Fri Jun 08 12:00:22 2012 -0700 @@ -406,7 +406,7 @@ #ifdef MACOSX break; default: - sprops.graphics_env = "sun.awt.HeadlessGraphicsEnvironment"; + sprops.graphics_env = "sun.java2d.HeadlessGraphicsEnvironment"; break; } #endif diff -r 2e04ed1b4ce0 -r c5ca850e1dff jdk/src/solaris/native/sun/awt/swing_GTKEngine.c --- a/jdk/src/solaris/native/sun/awt/swing_GTKEngine.c Fri Jun 08 11:58:45 2012 -0700 +++ b/jdk/src/solaris/native/sun/awt/swing_GTKEngine.c Fri Jun 08 12:00:22 2012 -0700 @@ -323,9 +323,8 @@ JNIEXPORT void JNICALL Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1switch_1theme( JNIEnv *env, jobject this) { - fp_gdk_threads_enter(); + // Note that flush_gtk_event_loop takes care of locks (7053002) flush_gtk_event_loop(); - fp_gdk_threads_leave(); } /* diff -r 2e04ed1b4ce0 -r c5ca850e1dff jdk/src/solaris/native/sun/xawt/XWindow.c --- a/jdk/src/solaris/native/sun/xawt/XWindow.c Fri Jun 08 11:58:45 2012 -0700 +++ b/jdk/src/solaris/native/sun/xawt/XWindow.c Fri Jun 08 12:00:22 2012 -0700 @@ -175,6 +175,7 @@ {java_awt_event_KeyEvent_VK_META, XK_Meta_L, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_LEFT}, {java_awt_event_KeyEvent_VK_META, XK_Meta_R, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_RIGHT}, {java_awt_event_KeyEvent_VK_CAPS_LOCK, XK_Caps_Lock, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, + {java_awt_event_KeyEvent_VK_CAPS_LOCK, XK_Shift_Lock, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, /* Misc Functions */ {java_awt_event_KeyEvent_VK_PRINTSCREEN, XK_Print, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, @@ -350,6 +351,24 @@ * same keysym as ALT_GRAPH in spite of its different behavior. */ + {java_awt_event_KeyEvent_VK_ALL_CANDIDATES, XK_Zen_Koho, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, + {java_awt_event_KeyEvent_VK_ALPHANUMERIC, XK_Eisu_Shift, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, + {java_awt_event_KeyEvent_VK_ALPHANUMERIC, XK_Eisu_toggle, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, + {java_awt_event_KeyEvent_VK_CODE_INPUT, XK_Kanji_Bangou, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, + {java_awt_event_KeyEvent_VK_FULL_WIDTH, XK_Zenkaku, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, + {java_awt_event_KeyEvent_VK_HALF_WIDTH, XK_Hankaku, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, + {java_awt_event_KeyEvent_VK_HIRAGANA, XK_Hiragana, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, + {java_awt_event_KeyEvent_VK_JAPANESE_HIRAGANA, XK_Hiragana, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, + {java_awt_event_KeyEvent_VK_KATAKANA, XK_Katakana, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, + {java_awt_event_KeyEvent_VK_JAPANESE_KATAKANA, XK_Katakana, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, + {java_awt_event_KeyEvent_VK_JAPANESE_ROMAN, XK_Romaji, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, + {java_awt_event_KeyEvent_VK_KANA, XK_Kana_Shift, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, + {java_awt_event_KeyEvent_VK_KANA_LOCK, XK_Kana_Lock, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, + {java_awt_event_KeyEvent_VK_KANJI, XK_Kanji, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, + {java_awt_event_KeyEvent_VK_NONCONVERT, XK_Muhenkan, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, + {java_awt_event_KeyEvent_VK_PREVIOUS_CANDIDATE, XK_Mae_Koho, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, + {java_awt_event_KeyEvent_VK_ROMAN_CHARACTERS, XK_Romaji, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, + {java_awt_event_KeyEvent_VK_COMPOSE, XK_Multi_key, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, {java_awt_event_KeyEvent_VK_ALT_GRAPH, XK_Mode_switch, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, diff -r 2e04ed1b4ce0 -r c5ca850e1dff jdk/src/windows/native/sun/windows/awt_Component.cpp --- a/jdk/src/windows/native/sun/windows/awt_Component.cpp Fri Jun 08 11:58:45 2012 -0700 +++ b/jdk/src/windows/native/sun/windows/awt_Component.cpp Fri Jun 08 12:00:22 2012 -0700 @@ -558,6 +558,8 @@ m_hwnd = hwnd; + ::ImmAssociateContext(m_hwnd, NULL); + SetDrawState((jint)JAWT_LOCK_SURFACE_CHANGED | (jint)JAWT_LOCK_BOUNDS_CHANGED | (jint)JAWT_LOCK_CLIP_CHANGED); diff -r 2e04ed1b4ce0 -r c5ca850e1dff jdk/src/windows/native/sun/windows/awt_TextArea.cpp --- a/jdk/src/windows/native/sun/windows/awt_TextArea.cpp Fri Jun 08 11:58:45 2012 -0700 +++ b/jdk/src/windows/native/sun/windows/awt_TextArea.cpp Fri Jun 08 12:00:22 2012 -0700 @@ -74,135 +74,10 @@ AwtTextComponent::Dispose(); } -LPCTSTR AwtTextArea::GetClassName() { - static BOOL richedLibraryLoaded = FALSE; - if (!richedLibraryLoaded) { - JDK_LoadSystemLibrary("RICHED20.DLL"); - richedLibraryLoaded = TRUE; - } - return RICHEDIT_CLASS; -} - /* Create a new AwtTextArea object and window. */ AwtTextArea* AwtTextArea::Create(jobject peer, jobject parent) { - JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); - - jobject target = NULL; - AwtTextArea* c = NULL; - - try { - if (env->EnsureLocalCapacity(1) < 0) { - return NULL; - } - - PDATA pData; - AwtCanvas* awtParent; - JNI_CHECK_PEER_GOTO(parent, done); - - awtParent = (AwtCanvas*)pData; - JNI_CHECK_NULL_GOTO(awtParent, "null awtParent", done); - - target = env->GetObjectField(peer, AwtObject::targetID); - JNI_CHECK_NULL_GOTO(target, "null target", done); - - c = new AwtTextArea(); - - { - /* Adjust style for scrollbar visibility and word wrap */ - DWORD scroll_style; - jint scrollbarVisibility = - env->GetIntField(target, AwtTextArea::scrollbarVisibilityID); - - switch (scrollbarVisibility) { - case java_awt_TextArea_SCROLLBARS_NONE: - scroll_style = ES_AUTOVSCROLL; - break; - case java_awt_TextArea_SCROLLBARS_VERTICAL_ONLY: - scroll_style = WS_VSCROLL | ES_AUTOVSCROLL; - break; - case java_awt_TextArea_SCROLLBARS_HORIZONTAL_ONLY: - scroll_style = WS_HSCROLL | ES_AUTOHSCROLL | ES_AUTOVSCROLL; - break; - case java_awt_TextArea_SCROLLBARS_BOTH: - scroll_style = WS_VSCROLL | WS_HSCROLL | - ES_AUTOVSCROLL | ES_AUTOHSCROLL; - break; - } - - /* - * Specify ES_DISABLENOSCROLL - RichEdit control style to disable - * scrollbars instead of hiding them when not needed. - */ - DWORD style = WS_CHILD | WS_CLIPSIBLINGS | ES_LEFT | ES_MULTILINE | - ES_WANTRETURN | scroll_style | ES_DISABLENOSCROLL; - DWORD exStyle = WS_EX_CLIENTEDGE; - if (GetRTL()) { - exStyle |= WS_EX_RIGHT | WS_EX_LEFTSCROLLBAR; - if (GetRTLReadingOrder()) - exStyle |= WS_EX_RTLREADING; - } - - jint x = env->GetIntField(target, AwtComponent::xID); - jint y = env->GetIntField(target, AwtComponent::yID); - jint width = env->GetIntField(target, AwtComponent::widthID); - jint height = env->GetIntField(target, AwtComponent::heightID); - - c->CreateHWnd(env, L"", style, exStyle, - x, y, width, height, - awtParent->GetHWnd(), - reinterpret_cast(static_cast( - awtParent->CreateControlID())), - ::GetSysColor(COLOR_WINDOWTEXT), - ::GetSysColor(COLOR_WINDOW), - peer); - - // Fix for 4753116. - // If it is not win95 (we are using Richedit 2.0) - // we set plain text mode, in which the control is - // similar to a standard edit control: - // - The text in a plain text control can have only - // one format. - // - The user cannot paste rich text formats, such as RTF - // or embedded objects into a plain text control. - // - Rich text mode controls always have a default - // end-of-document marker or carriage return, - // to format paragraphs. - // kdm@sparc.spb.su - c->SendMessage(EM_SETTEXTMODE, TM_PLAINTEXT, 0); - - c->m_backgroundColorSet = TRUE; - /* suppress inheriting parent's color. */ - c->UpdateBackground(env, target); - c->SendMessage(EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, - MAKELPARAM(1, 1)); - /* - * Fix for BugTraq Id 4260109. - * Set the text limit to the maximum. - * Use EM_EXLIMITTEXT for RichEdit controls. - * For some reason RichEdit 1.0 becomes read-only if the - * specified limit is greater than 0x7FFFFFFD. - */ - c->SendMessage(EM_EXLIMITTEXT, 0, 0x7FFFFFFD); - - /* Unregister RichEdit built-in drop target. */ - VERIFY(::RevokeDragDrop(c->GetHWnd()) != DRAGDROP_E_INVALIDHWND); - - /* To enforce CF_TEXT format for paste operations. */ - VERIFY(c->SendMessage(EM_SETOLECALLBACK, 0, - (LPARAM)&GetOleCallback())); - - c->SendMessage(EM_SETEVENTMASK, 0, ENM_CHANGE); - } - } catch (...) { - env->DeleteLocalRef(target); - throw; - } - -done: - env->DeleteLocalRef(target); - - return c; + return (AwtTextArea*) AwtTextComponent::Create(peer, parent, true); } void AwtTextArea::EditSetSel(CHARRANGE &cr) { @@ -220,11 +95,6 @@ SendMessage(EM_EXGETSEL, 0, reinterpret_cast(&cr)); } -LONG AwtTextArea::EditGetCharFromPos(POINT& pt) { - return static_cast(SendMessage(EM_CHARFROMPOS, 0, - reinterpret_cast(&pt))); -} - /* Count how many '\n's are there in jStr */ size_t AwtTextArea::CountNewLines(JNIEnv *env, jstring jStr, size_t maxlen) { @@ -253,34 +123,6 @@ BOOL AwtTextArea::InheritsNativeMouseWheelBehavior() {return true;} -MsgRouting -AwtTextArea::PreProcessMsg(MSG& msg) -{ - MsgRouting mr = mrPassAlong; - static BOOL bPassAlongWmLButtonUp = TRUE; - - if (msg.message == WM_LBUTTONDBLCLK) { - bPassAlongWmLButtonUp = FALSE; - } - - /* - * For some reason RichEdit 1.0 filters out WM_LBUTTONUP after - * WM_LBUTTONDBLCLK. To work around this "feature" we send WM_LBUTTONUP - * directly to the window procedure and consume instead of passing it - * to the next hook. - */ - if (msg.message == WM_LBUTTONUP && bPassAlongWmLButtonUp == FALSE) { - SendMessage(WM_LBUTTONUP, msg.wParam, msg.lParam); - bPassAlongWmLButtonUp = TRUE; - mr = mrConsume; - } - - if (mr == mrPassAlong) { - mr = AwtComponent::PreProcessMsg(msg); - } - - return mr; -} LRESULT AwtTextArea::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) { @@ -800,54 +642,6 @@ return returnVal; } -/* - * WM_CTLCOLOR is not sent by rich edit controls. - * Use EM_SETCHARFORMAT and EM_SETBKGNDCOLOR to set - * respectively foreground and background color. - */ -void AwtTextArea::SetColor(COLORREF c) { - AwtComponent::SetColor(c); - - CHARFORMAT cf; - memset(&cf, 0, sizeof(cf)); - cf.cbSize = sizeof(cf); - cf.dwMask = CFM_COLOR; - - cf.crTextColor = ::IsWindowEnabled(GetHWnd()) ? GetColor() : ::GetSysColor(COLOR_3DSHADOW); - - /* - * The documentation for EM_GETCHARFORMAT is not exactly - * correct. It appears that wParam has the same meaning - * as for EM_SETCHARFORMAT. Our task is to secure that - * all the characters in the control have the required - * formatting. That's why we use SCF_ALL. - */ - VERIFY(SendMessage(EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf)); - VERIFY(SendMessage(EM_SETCHARFORMAT, SCF_DEFAULT, (LPARAM)&cf)); -} - -/* - * In responce to EM_SETBKGNDCOLOR rich edit changes - * its bg color and repaints itself so we don't need - * to force repaint. - */ -void AwtTextArea::SetBackgroundColor(COLORREF c) { - AwtComponent::SetBackgroundColor(c); - SendMessage(EM_SETBKGNDCOLOR, (WPARAM)FALSE, (LPARAM)GetBackgroundColor()); -} - -/* - * Disabled edit control has grayed foreground. - * Disabled RichEdit 1.0 control has original foreground. - * Thus we have to set grayed foreground manually. - */ -void AwtTextArea::Enable(BOOL bEnable) -{ - AwtComponent::Enable(bEnable); - - SetColor(GetColor()); -} - /* Fix for 4776535, 4648702 * If width is 0 or 1 Windows hides the horizontal scroll bar even @@ -1048,133 +842,3 @@ } /* extern "C" */ -AwtTextArea::OleCallback AwtTextArea::sm_oleCallback; - -/************************************************************************ - * Inner class OleCallback definition. - */ - -AwtTextArea::OleCallback::OleCallback() { - m_refs = 0; - AddRef(); -} - -STDMETHODIMP -AwtTextArea::OleCallback::QueryInterface(REFIID riid, LPVOID * ppvObj) { - - TRY; - - if (::IsEqualIID(riid, IID_IUnknown)) { - *ppvObj = (void __RPC_FAR *__RPC_FAR)(IUnknown*)this; - AddRef(); - return S_OK; - } else if (::IsEqualIID(riid, IID_IRichEditOleCallback)) { - *ppvObj = (void __RPC_FAR *__RPC_FAR)(IRichEditOleCallback*)this; - AddRef(); - return S_OK; - } else { - *ppvObj = NULL; - return E_NOINTERFACE; - } - - CATCH_BAD_ALLOC_RET(E_OUTOFMEMORY); -} - -STDMETHODIMP_(ULONG) -AwtTextArea::OleCallback::AddRef() { - return ++m_refs; -} - -STDMETHODIMP_(ULONG) -AwtTextArea::OleCallback::Release() { - int refs; - - if ((refs = --m_refs) == 0) delete this; - - return (ULONG)refs; -} - -STDMETHODIMP -AwtTextArea::OleCallback::GetNewStorage(LPSTORAGE FAR * ppstg) { - return E_NOTIMPL; -} - -STDMETHODIMP -AwtTextArea::OleCallback::GetInPlaceContext(LPOLEINPLACEFRAME FAR * ppipframe, - LPOLEINPLACEUIWINDOW FAR* ppipuiDoc, - LPOLEINPLACEFRAMEINFO pipfinfo) -{ - return E_NOTIMPL; -} - -STDMETHODIMP -AwtTextArea::OleCallback::ShowContainerUI(BOOL fShow) { - return E_NOTIMPL; -} - -STDMETHODIMP -AwtTextArea::OleCallback::QueryInsertObject(LPCLSID pclsid, - LPSTORAGE pstg, - LONG cp) { - return NOERROR; -} - -STDMETHODIMP -AwtTextArea::OleCallback::DeleteObject(LPOLEOBJECT poleobj) { - return NOERROR; -} - -STDMETHODIMP -AwtTextArea::OleCallback::QueryAcceptData(LPDATAOBJECT pdataobj, - CLIPFORMAT *pcfFormat, - DWORD reco, - BOOL fReally, - HGLOBAL hMetaPict) { - if (reco == RECO_PASTE) { - // If CF_TEXT format is available edit controls will select it, - // otherwise if it is CF_UNICODETEXT is available it will be - // selected, otherwise if CF_OEMTEXT is available it will be selected. - if (::IsClipboardFormatAvailable(CF_TEXT)) { - *pcfFormat = CF_TEXT; - } else if (::IsClipboardFormatAvailable(CF_UNICODETEXT)) { - *pcfFormat = CF_UNICODETEXT; - } else if (::IsClipboardFormatAvailable(CF_OEMTEXT)) { - *pcfFormat = CF_OEMTEXT; - } else { - // Don't allow rich edit to paste clipboard data - // in other formats. - *pcfFormat = CF_TEXT; - } - } - - return NOERROR; -} - -STDMETHODIMP -AwtTextArea::OleCallback::ContextSensitiveHelp(BOOL fEnterMode) { - return NOERROR; -} - -STDMETHODIMP -AwtTextArea::OleCallback::GetClipboardData(CHARRANGE *pchrg, - DWORD reco, - LPDATAOBJECT *ppdataobj) { - return E_NOTIMPL; -} - -STDMETHODIMP -AwtTextArea::OleCallback::GetDragDropEffect(BOOL fDrag, - DWORD grfKeyState, - LPDWORD pdwEffect) { - - return E_NOTIMPL; -} - - -STDMETHODIMP -AwtTextArea::OleCallback::GetContextMenu(WORD seltype, - LPOLEOBJECT lpoleobj, - CHARRANGE FAR * lpchrg, - HMENU FAR * lphmenu) { - return E_NOTIMPL; -} diff -r 2e04ed1b4ce0 -r c5ca850e1dff jdk/src/windows/native/sun/windows/awt_TextArea.h --- a/jdk/src/windows/native/sun/windows/awt_TextArea.h Fri Jun 08 11:58:45 2012 -0700 +++ b/jdk/src/windows/native/sun/windows/awt_TextArea.h Fri Jun 08 12:00:22 2012 -0700 @@ -51,15 +51,11 @@ virtual void Dispose(); - LPCTSTR GetClassName(); - static AwtTextArea* Create(jobject self, jobject parent); static size_t CountNewLines(JNIEnv *env, jstring jStr, size_t maxlen); static size_t GetALength(JNIEnv* env, jstring jStr, size_t maxlen); - MsgRouting PreProcessMsg(MSG& msg); - LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam); static LRESULT CALLBACK EditProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); @@ -72,9 +68,6 @@ INLINE void SetIgnoreEnChange(BOOL b) { m_bIgnoreEnChange = b; } - virtual void SetColor(COLORREF c); - virtual void SetBackgroundColor(COLORREF c); - virtual void Enable(BOOL bEnable); virtual BOOL InheritsNativeMouseWheelBehavior(); virtual void Reshape(int x, int y, int w, int h); @@ -87,40 +80,8 @@ protected: - /***************************************************************** - * Inner class OleCallback declaration. - */ - class OleCallback : public IRichEditOleCallback { - public: - OleCallback(); - - STDMETHODIMP QueryInterface(REFIID riid, LPVOID * ppvObj); - STDMETHODIMP_(ULONG) AddRef(); - STDMETHODIMP_(ULONG) Release(); - STDMETHODIMP GetNewStorage(LPSTORAGE FAR * ppstg); - STDMETHODIMP GetInPlaceContext(LPOLEINPLACEFRAME FAR * ppipframe, - LPOLEINPLACEUIWINDOW FAR* ppipuiDoc, - LPOLEINPLACEFRAMEINFO pipfinfo); - STDMETHODIMP ShowContainerUI(BOOL fShow); - STDMETHODIMP QueryInsertObject(LPCLSID pclsid, LPSTORAGE pstg, LONG cp); - STDMETHODIMP DeleteObject(LPOLEOBJECT poleobj); - STDMETHODIMP QueryAcceptData(LPDATAOBJECT pdataobj, CLIPFORMAT *pcfFormat, - DWORD reco, BOOL fReally, HGLOBAL hMetaPict); - STDMETHODIMP ContextSensitiveHelp(BOOL fEnterMode); - STDMETHODIMP GetClipboardData(CHARRANGE *pchrg, DWORD reco, - LPDATAOBJECT *ppdataobj); - STDMETHODIMP GetDragDropEffect(BOOL fDrag, DWORD grfKeyState, - LPDWORD pdwEffect); - STDMETHODIMP GetContextMenu(WORD seltype, LPOLEOBJECT poleobj, - CHARRANGE FAR * pchrg, HMENU FAR * phmenu); - private: - ULONG m_refs; // Reference count - };//OleCallback class - - INLINE static OleCallback& GetOleCallback() { return sm_oleCallback; } void EditSetSel(CHARRANGE &cr); void EditGetSel(CHARRANGE &cr); - LONG EditGetCharFromPos(POINT& pt); private: // RichEdit 1.0 control generates EN_CHANGE notifications not only // on text changes, but also on any character formatting change. @@ -140,8 +101,6 @@ LONG m_lVDeltaAccum; - static OleCallback sm_oleCallback; - }; #endif /* AWT_TEXTAREA_H */ diff -r 2e04ed1b4ce0 -r c5ca850e1dff jdk/src/windows/native/sun/windows/awt_TextComponent.cpp --- a/jdk/src/windows/native/sun/windows/awt_TextComponent.cpp Fri Jun 08 11:58:45 2012 -0700 +++ b/jdk/src/windows/native/sun/windows/awt_TextComponent.cpp Fri Jun 08 12:00:22 2012 -0700 @@ -25,6 +25,8 @@ #include "awt_Toolkit.h" #include "awt_TextComponent.h" +#include "awt_TextArea.h" +#include "awt_TextField.h" #include "awt_Canvas.h" #include "jni.h" @@ -70,7 +72,152 @@ } LPCTSTR AwtTextComponent::GetClassName() { - return TEXT("EDIT"); /* System provided edit control class */ + static BOOL richedLibraryLoaded = FALSE; + if (!richedLibraryLoaded) { + JDK_LoadSystemLibrary("RICHED20.DLL"); + richedLibraryLoaded = TRUE; + } + return RICHEDIT_CLASS; +} + +/* Create a new AwtTextArea or AwtTextField object and window. */ +AwtTextComponent* AwtTextComponent::Create(jobject peer, jobject parent, BOOL isMultiline) +{ + JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); + + jobject target = NULL; + AwtTextComponent* c = NULL; + + try { + if (env->EnsureLocalCapacity(1) < 0) { + return NULL; + } + + PDATA pData; + AwtCanvas* awtParent; + JNI_CHECK_PEER_GOTO(parent, done); + + awtParent = (AwtCanvas*)pData; + JNI_CHECK_NULL_GOTO(awtParent, "null awtParent", done); + + target = env->GetObjectField(peer, AwtObject::targetID); + JNI_CHECK_NULL_GOTO(target, "null target", done); + + if(isMultiline){ + c = new AwtTextArea(); + }else{ + c = new AwtTextField(); + } + + { + /* Adjust style for scrollbar visibility and word wrap */ + DWORD scroll_style; + + if(isMultiline){ + + jint scrollbarVisibility = + env->GetIntField(target, AwtTextArea::scrollbarVisibilityID); + + switch (scrollbarVisibility) { + case java_awt_TextArea_SCROLLBARS_NONE: + scroll_style = ES_AUTOVSCROLL; + break; + case java_awt_TextArea_SCROLLBARS_VERTICAL_ONLY: + scroll_style = WS_VSCROLL | ES_AUTOVSCROLL; + break; + case java_awt_TextArea_SCROLLBARS_HORIZONTAL_ONLY: + scroll_style = WS_HSCROLL | ES_AUTOHSCROLL | ES_AUTOVSCROLL; + break; + case java_awt_TextArea_SCROLLBARS_BOTH: + scroll_style = WS_VSCROLL | WS_HSCROLL | + ES_AUTOVSCROLL | ES_AUTOHSCROLL; + break; + } + } + + DWORD style = WS_CHILD | WS_CLIPSIBLINGS | ES_LEFT; + + /* + * Specify ES_DISABLENOSCROLL - RichEdit control style to disable + * scrollbars instead of hiding them when not needed. + */ + style |= isMultiline ? ES_MULTILINE | ES_WANTRETURN | scroll_style + | ES_DISABLENOSCROLL : ES_AUTOHSCROLL; + + + DWORD exStyle = WS_EX_CLIENTEDGE; + if (GetRTL()) { + exStyle |= WS_EX_RIGHT | WS_EX_LEFTSCROLLBAR; + if (GetRTLReadingOrder()) + exStyle |= WS_EX_RTLREADING; + } + + + jint x = env->GetIntField(target, AwtComponent::xID); + jint y = env->GetIntField(target, AwtComponent::yID); + jint width = env->GetIntField(target, AwtComponent::widthID); + jint height = env->GetIntField(target, AwtComponent::heightID); + + c->CreateHWnd(env, L"", style, exStyle, + x, y, width, height, + awtParent->GetHWnd(), + reinterpret_cast(static_cast( + awtParent->CreateControlID())), + ::GetSysColor(COLOR_WINDOWTEXT), + ::GetSysColor(COLOR_WINDOW), + peer); + + // Fix for 4753116. + // If it is not win95 (we are using Richedit 2.0) + // we set plain text mode, in which the control is + // similar to a standard edit control: + // - The text in a plain text control can have only + // one format. + // - The user cannot paste rich text formats, such as RTF + // or embedded objects into a plain text control. + // - Rich text mode controls always have a default + // end-of-document marker or carriage return, + // to format paragraphs. + // kdm@sparc.spb.su + c->SendMessage(EM_SETTEXTMODE, TM_PLAINTEXT, 0); + + c->m_backgroundColorSet = TRUE; + /* suppress inheriting parent's color. */ + c->UpdateBackground(env, target); + c->SendMessage(EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, + MAKELPARAM(1, 1)); + /* + * Fix for BugTraq Id 4260109. + * Set the text limit to the maximum. + * Use EM_EXLIMITTEXT for RichEdit controls. + * For some reason RichEdit 1.0 becomes read-only if the + * specified limit is greater than 0x7FFFFFFD. + */ + c->SendMessage(EM_EXLIMITTEXT, 0, 0x7FFFFFFD); + + /* Unregister RichEdit built-in drop target. */ + VERIFY(::RevokeDragDrop(c->GetHWnd()) != DRAGDROP_E_INVALIDHWND); + + /* To enforce CF_TEXT format for paste operations. */ + VERIFY(c->SendMessage(EM_SETOLECALLBACK, 0, + (LPARAM)&GetOleCallback())); + + c->SendMessage(EM_SETEVENTMASK, 0, ENM_CHANGE); + } + } catch (...) { + env->DeleteLocalRef(target); + throw; + } + +done: + env->DeleteLocalRef(target); + + return c; +} + +LONG AwtTextComponent::EditGetCharFromPos(POINT& pt) { + return static_cast(SendMessage(EM_CHARFROMPOS, 0, + reinterpret_cast(&pt))); } /* Set a suitable font to IME against the component font. */ @@ -463,6 +610,54 @@ delete ees; } +/* + * Disabled edit control has grayed foreground. + * Disabled RichEdit 1.0 control has original foreground. + * Thus we have to set grayed foreground manually. + */ +void AwtTextComponent::Enable(BOOL bEnable) +{ + AwtComponent::Enable(bEnable); + SetColor(GetColor()); +} + + +/* + * WM_CTLCOLOR is not sent by rich edit controls. + * Use EM_SETCHARFORMAT and EM_SETBKGNDCOLOR to set + * respectively foreground and background color. + */ +void AwtTextComponent::SetColor(COLORREF c) { + AwtComponent::SetColor(c); + + CHARFORMAT cf; + memset(&cf, 0, sizeof(cf)); + cf.cbSize = sizeof(cf); + cf.dwMask = CFM_COLOR; + + cf.crTextColor = ::IsWindowEnabled(GetHWnd()) ? GetColor() : ::GetSysColor(COLOR_3DSHADOW); + + /* + * The documentation for EM_GETCHARFORMAT is not exactly + * correct. It appears that wParam has the same meaning + * as for EM_SETCHARFORMAT. Our task is to secure that + * all the characters in the control have the required + * formatting. That's why we use SCF_ALL. + */ + VERIFY(SendMessage(EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf)); + VERIFY(SendMessage(EM_SETCHARFORMAT, SCF_DEFAULT, (LPARAM)&cf)); +} + +/* + * In responce to EM_SETBKGNDCOLOR rich edit changes + * its bg color and repaints itself so we don't need + * to force repaint. + */ +void AwtTextComponent::SetBackgroundColor(COLORREF c) { + AwtComponent::SetBackgroundColor(c); + SendMessage(EM_SETBKGNDCOLOR, (WPARAM)FALSE, (LPARAM)GetBackgroundColor()); +} + /************************************************************************ * WTextComponentPeer native methods @@ -623,6 +818,127 @@ CATCH_BAD_ALLOC; } + +AwtTextComponent::OleCallback AwtTextComponent::sm_oleCallback; + +/************************************************************************ + * Inner class OleCallback definition. + */ + +AwtTextComponent::OleCallback::OleCallback() { + m_refs = 0; + AddRef(); +} + +STDMETHODIMP +AwtTextComponent::OleCallback::QueryInterface(REFIID riid, LPVOID * ppvObj) { + if (::IsEqualIID(riid, IID_IUnknown) ||::IsEqualIID(riid, IID_IRichEditOleCallback) ) { + *ppvObj = static_cast(this); + AddRef(); + return S_OK; + } + *ppvObj = NULL; + return E_NOINTERFACE; +} + + +STDMETHODIMP_(ULONG) +AwtTextComponent::OleCallback::AddRef() { + return ++m_refs; +} + +STDMETHODIMP_(ULONG) +AwtTextComponent::OleCallback::Release() { + return (ULONG)--m_refs; +} + +STDMETHODIMP +AwtTextComponent::OleCallback::GetNewStorage(LPSTORAGE FAR * ppstg) { + return E_NOTIMPL; +} + +STDMETHODIMP +AwtTextComponent::OleCallback::GetInPlaceContext(LPOLEINPLACEFRAME FAR * ppipframe, + LPOLEINPLACEUIWINDOW FAR* ppipuiDoc, + LPOLEINPLACEFRAMEINFO pipfinfo) +{ + return E_NOTIMPL; +} + +STDMETHODIMP +AwtTextComponent::OleCallback::ShowContainerUI(BOOL fShow) { + return E_NOTIMPL; +} + +STDMETHODIMP +AwtTextComponent::OleCallback::QueryInsertObject(LPCLSID pclsid, + LPSTORAGE pstg, + LONG cp) { + return S_OK; +} + +STDMETHODIMP +AwtTextComponent::OleCallback::DeleteObject(LPOLEOBJECT poleobj) { + return S_OK; +} + +STDMETHODIMP +AwtTextComponent::OleCallback::QueryAcceptData(LPDATAOBJECT pdataobj, + CLIPFORMAT *pcfFormat, + DWORD reco, + BOOL fReally, + HGLOBAL hMetaPict) { + if (reco == RECO_PASTE) { + // If CF_TEXT format is available edit controls will select it, + // otherwise if it is CF_UNICODETEXT is available it will be + // selected, otherwise if CF_OEMTEXT is available it will be selected. + if (::IsClipboardFormatAvailable(CF_TEXT)) { + *pcfFormat = CF_TEXT; + } else if (::IsClipboardFormatAvailable(CF_UNICODETEXT)) { + *pcfFormat = CF_UNICODETEXT; + } else if (::IsClipboardFormatAvailable(CF_OEMTEXT)) { + *pcfFormat = CF_OEMTEXT; + } else { + // Don't allow rich edit to paste clipboard data + // in other formats. + *pcfFormat = CF_TEXT; + } + } + + return S_OK; +} + +STDMETHODIMP +AwtTextComponent::OleCallback::ContextSensitiveHelp(BOOL fEnterMode) { + return S_OK; +} + +STDMETHODIMP +AwtTextComponent::OleCallback::GetClipboardData(CHARRANGE *pchrg, + DWORD reco, + LPDATAOBJECT *ppdataobj) { + return E_NOTIMPL; +} + +STDMETHODIMP +AwtTextComponent::OleCallback::GetDragDropEffect(BOOL fDrag, + DWORD grfKeyState, + LPDWORD pdwEffect) { + + return E_NOTIMPL; +} + + +STDMETHODIMP +AwtTextComponent::OleCallback::GetContextMenu(WORD seltype, + LPOLEOBJECT lpoleobj, + CHARRANGE FAR * lpchrg, + HMENU FAR * lphmenu) { + return E_NOTIMPL; +} + + + // // Accessibility support // diff -r 2e04ed1b4ce0 -r c5ca850e1dff jdk/src/windows/native/sun/windows/awt_TextComponent.h --- a/jdk/src/windows/native/sun/windows/awt_TextComponent.h Fri Jun 08 11:58:45 2012 -0700 +++ b/jdk/src/windows/native/sun/windows/awt_TextComponent.h Fri Jun 08 12:00:22 2012 -0700 @@ -47,6 +47,8 @@ AwtTextComponent(); + static AwtTextComponent* Create(jobject self, jobject parent, BOOL isMultiline); + virtual LPCTSTR GetClassName(); int RemoveCR(WCHAR *pStr); @@ -71,6 +73,10 @@ void SetFont(AwtFont* font); + virtual void Enable(BOOL bEnable); + virtual void SetColor(COLORREF c); + virtual void SetBackgroundColor(COLORREF c); + /* * Windows message handler functions */ @@ -113,7 +119,40 @@ // Used to prevent untrusted code from synthesizing a WM_PASTE message // by posting a -V KeyEvent BOOL m_synthetic; - virtual LONG EditGetCharFromPos(POINT& pt) = 0; + LONG EditGetCharFromPos(POINT& pt); + + /***************************************************************** + * Inner class OleCallback declaration. + */ + class OleCallback : public IRichEditOleCallback { + public: + OleCallback(); + + STDMETHODIMP QueryInterface(REFIID riid, LPVOID * ppvObj); + STDMETHODIMP_(ULONG) AddRef(); + STDMETHODIMP_(ULONG) Release(); + STDMETHODIMP GetNewStorage(LPSTORAGE FAR * ppstg); + STDMETHODIMP GetInPlaceContext(LPOLEINPLACEFRAME FAR * ppipframe, + LPOLEINPLACEUIWINDOW FAR* ppipuiDoc, + LPOLEINPLACEFRAMEINFO pipfinfo); + STDMETHODIMP ShowContainerUI(BOOL fShow); + STDMETHODIMP QueryInsertObject(LPCLSID pclsid, LPSTORAGE pstg, LONG cp); + STDMETHODIMP DeleteObject(LPOLEOBJECT poleobj); + STDMETHODIMP QueryAcceptData(LPDATAOBJECT pdataobj, CLIPFORMAT *pcfFormat, + DWORD reco, BOOL fReally, HGLOBAL hMetaPict); + STDMETHODIMP ContextSensitiveHelp(BOOL fEnterMode); + STDMETHODIMP GetClipboardData(CHARRANGE *pchrg, DWORD reco, + LPDATAOBJECT *ppdataobj); + STDMETHODIMP GetDragDropEffect(BOOL fDrag, DWORD grfKeyState, + LPDWORD pdwEffect); + STDMETHODIMP GetContextMenu(WORD seltype, LPOLEOBJECT poleobj, + CHARRANGE FAR * pchrg, HMENU FAR * phmenu); + private: + ULONG m_refs; // Reference count + };//OleCallback class + + INLINE static OleCallback& GetOleCallback() { return sm_oleCallback; } + private: @@ -126,6 +165,7 @@ HFONT m_hFont; //im --- end + static OleCallback sm_oleCallback; // // Accessibility support diff -r 2e04ed1b4ce0 -r c5ca850e1dff jdk/src/windows/native/sun/windows/awt_TextField.cpp --- a/jdk/src/windows/native/sun/windows/awt_TextField.cpp Fri Jun 08 11:58:45 2012 -0700 +++ b/jdk/src/windows/native/sun/windows/awt_TextField.cpp Fri Jun 08 12:00:22 2012 -0700 @@ -42,84 +42,23 @@ */ AwtTextField::AwtTextField() - : m_initialRescrollFlag( true ) { } /* Create a new AwtTextField object and window. */ AwtTextField* AwtTextField::Create(jobject peer, jobject parent) { - JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); - - jobject target = NULL; - AwtTextField* c = NULL; - - try { - PDATA pData; - AwtCanvas* awtParent; - JNI_CHECK_PEER_GOTO(parent, done); - awtParent = (AwtCanvas*)pData; - - JNI_CHECK_NULL_GOTO(awtParent, "null awtParent", done); - - target = env->GetObjectField(peer, AwtObject::targetID); - JNI_CHECK_NULL_GOTO(target, "null target", done); - - c = new AwtTextField(); - - { - DWORD style = WS_CHILD | WS_CLIPSIBLINGS | - ES_LEFT | ES_AUTOHSCROLL; - DWORD exStyle = WS_EX_CLIENTEDGE; - if (GetRTL()) { - exStyle |= WS_EX_RIGHT | WS_EX_LEFTSCROLLBAR; - if (GetRTLReadingOrder()) - exStyle |= WS_EX_RTLREADING; - } - - jint x = env->GetIntField(target, AwtComponent::xID); - jint y = env->GetIntField(target, AwtComponent::yID); - jint width = env->GetIntField(target, AwtComponent::widthID); - jint height = env->GetIntField(target, AwtComponent::heightID); - - c->CreateHWnd(env, L"", style, exStyle, - x, y, width, height, - awtParent->GetHWnd(), - reinterpret_cast(static_cast( - awtParent->CreateControlID())), - ::GetSysColor(COLOR_WINDOWTEXT), - ::GetSysColor(COLOR_WINDOW), - peer); - - c->m_backgroundColorSet = TRUE; - /* suppress inheriting parent's color. */ - c->UpdateBackground(env, target); - c->SendMessage(EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, - MAKELPARAM(1, 1)); - /* - * Fix for BugTraq Id 4260109. - * Set the text limit to the maximum. - */ - c->SendMessage(EM_SETLIMITTEXT); - - } - } catch (...) { - env->DeleteLocalRef(target); - throw; - } - -done: - env->DeleteLocalRef(target); - - return c; + return (AwtTextField*) AwtTextComponent::Create(peer, parent, false); } void AwtTextField::EditSetSel(CHARRANGE &cr) { - SendMessage(EM_SETSEL, cr.cpMin, cr.cpMax); -} + SendMessage(EM_EXSETSEL, 0, reinterpret_cast(&cr)); -LONG AwtTextField::EditGetCharFromPos(POINT& pt) { - return static_cast(SendMessage(EM_CHARFROMPOS, 0, MAKELPARAM(pt.x, pt.y))); + // 6417581: force expected drawing + if (IS_WINVISTA && cr.cpMin == cr.cpMax) { + ::InvalidateRect(GetHWnd(), NULL, TRUE); + } + } LRESULT AwtTextField::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) @@ -162,10 +101,18 @@ * to allow dnd of the current selection. */ if (msg->message == WM_LBUTTONDBLCLK) { - SetStartSelectionPos(static_cast(SendMessage( - EM_FINDWORDBREAK, WB_MOVEWORDLEFT, lCurPos))); - SetEndSelectionPos(static_cast(SendMessage( - EM_FINDWORDBREAK, WB_MOVEWORDRIGHT, lCurPos))); + jchar echo = SendMessage(EM_GETPASSWORDCHAR); + + if(echo == 0){ + SetStartSelectionPos(static_cast(SendMessage( + EM_FINDWORDBREAK, WB_MOVEWORDLEFT, lCurPos))); + SetEndSelectionPos(static_cast(SendMessage( + EM_FINDWORDBREAK, WB_MOVEWORDRIGHT, lCurPos))); + }else{ + SetStartSelectionPos(0); + SetEndSelectionPos(GetTextLength()); + } + } else { SetStartSelectionPos(lCurPos); SetEndSelectionPos(lCurPos); @@ -307,46 +254,6 @@ 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 -r 2e04ed1b4ce0 -r c5ca850e1dff jdk/src/windows/native/sun/windows/awt_TextField.h --- a/jdk/src/windows/native/sun/windows/awt_TextField.h Fri Jun 08 11:58:45 2012 -0700 +++ b/jdk/src/windows/native/sun/windows/awt_TextField.h Fri Jun 08 12:00:22 2012 -0700 @@ -54,15 +54,11 @@ // invoked on Toolkit thread static void _SetEchoChar(void *param); - protected: - LONG EditGetCharFromPos(POINT& pt); - virtual void Reshape(int x, int y, int w, int h); +protected: private: void EditSetSel(CHARRANGE &cr); - void initialRescroll(); - bool m_initialRescrollFlag; }; #endif /* AWT_TEXTFIELD_H */ diff -r 2e04ed1b4ce0 -r c5ca850e1dff jdk/test/java/awt/Frame/ResizeAfterSetFont/ResizeAfterSetFont.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/awt/Frame/ResizeAfterSetFont/ResizeAfterSetFont.java Fri Jun 08 12:00:22 2012 -0700 @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2012 Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * Portions Copyright (c) 2012 IBM Corporation + */ + +/* + @test + @bug 7170655 + @summary Frame size does not change after changing font + @author Jonathan Lu + @library ../../regtesthelpers + @build Util + @run main ResizeAfterSetFont + */ + +import java.awt.*; +import test.java.awt.regtesthelpers.Util; + +public class ResizeAfterSetFont { + + public static void main(String[] args) throws Exception { + Frame frame = new Frame("bug7170655"); + frame.setLayout(new BorderLayout()); + frame.setBackground(Color.LIGHT_GRAY); + + Panel panel = new Panel(); + panel.setLayout(new GridLayout(0, 1, 1, 1)); + + Label label = new Label("Test Label"); + label.setBackground(Color.white); + label.setForeground(Color.RED); + label.setFont(new Font("Dialog", Font.PLAIN, 12)); + + panel.add(label); + frame.add(panel, "South"); + frame.pack(); + frame.setVisible(true); + + Util.waitForIdle(null); + + Dimension dimBefore = frame.getSize(); + label.setFont(new Font("Dialog", Font.PLAIN, 24)); + + frame.validate(); + frame.pack(); + Dimension dimAfter = frame.getSize(); + + if (dimBefore.equals(dimAfter)) { + throw new Exception( + "Frame size does not change after Label.setFont()!"); + } + } +} diff -r 2e04ed1b4ce0 -r c5ca850e1dff jdk/test/java/awt/WMSpecificTests/Mutter/MutterMaximizeTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/awt/WMSpecificTests/Mutter/MutterMaximizeTest.java Fri Jun 08 12:00:22 2012 -0700 @@ -0,0 +1,160 @@ +/* + * Copyright 2012 Red Hat, Inc. All Rights Reserved. + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + + +/* + @test + @bug 7043963 + @summary Tests that the screen location of windows is + updated properly after a maximize. + @author Denis Lila + @library ../../regtesthelpers + @build Util + @run main MutterMaximizeTest +*/ + +import java.awt.AWTException; +import java.awt.Dimension; +import java.awt.Frame; +import java.awt.Point; +import java.awt.Robot; +import java.awt.Window; +import java.awt.event.InputEvent; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; + +import test.java.awt.regtesthelpers.Util; + +@SuppressWarnings("serial") +public class MutterMaximizeTest extends Frame { + + public static void main(String[] args) throws InterruptedException { + if (Util.getWMID() != Util.MUTTER_WM) { + System.out.println("This test is only useful on Mutter"); + return; + } + MutterMaximizeTest frame = new MutterMaximizeTest(); + frame.addWindowListener(Util.getClosingWindowAdapter()); + + //Display the window. + frame.setSize(500, 500); + Util.showWindowWait(frame); + runRobotTest(frame); + } + + private static void runRobotTest(Frame frame) { + try { + Thread robotThread = startRegTest(frame); + robotThread.start(); + waitForThread(robotThread); + } finally { + frame.dispose(); + } + } + + private static void waitForThread(Thread t) { + while (t.isAlive()) { + try { + t.join(); + } catch (InterruptedException e) { + } + } + } + + private static void sleepFor(long millis) { + long dT = 0; + long start = System.nanoTime(); + while (dT < millis) { + try { + long toSleep = millis - dT/1000000; + if (toSleep > 0) { + Thread.sleep(toSleep); + } + // if this ends without an interrupted exception, + // that's good enough. + break; + } catch (InterruptedException e) { + long now = System.nanoTime(); + dT = now - start; + } + } + } + + private static void rmove(Robot robot, Point p) { + robot.mouseMove(p.x, p.y); + } + private static void rdown(Robot robot) { + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.delay(50); + } + private static void rup(Robot robot) { + robot.mouseRelease(InputEvent.BUTTON1_MASK); + robot.delay(50); + } + + public static void click(Robot robot) { + rdown(robot); + rup(robot); + } + + public static void doubleClick(Robot robot) { + click(robot); + click(robot); + } + + private static void dragWindow(Window w, int dx, int dy, Robot robot) { + Point p = Util.getTitlePoint(w); + rmove(robot, p); + rdown(robot); + p.translate(dx, dy); + rmove(robot, p); + rup(robot); + } + + // f must be visible + private static Thread startRegTest(final Frame f) { + Thread robot = new Thread(new Runnable() { + public void run() { + Robot r = Util.createRobot(); + dragWindow(f, 100, 100, r); + // wait for the location to be set. + sleepFor(2000); + + final Point l2 = f.getLocationOnScreen(); + + // double click should maximize the frame + doubleClick(r); + + // wait for location again. + sleepFor(2000); + final Point l3 = f.getLocationOnScreen(); + if (l3.equals(l2)) { + throw new RuntimeException("Bad location after maximize. Window location has not moved"); + } + } + }); + return robot; + } +} + diff -r 2e04ed1b4ce0 -r c5ca850e1dff jdk/test/java/awt/regtesthelpers/Util.java --- a/jdk/test/java/awt/regtesthelpers/Util.java Fri Jun 08 11:58:45 2012 -0700 +++ b/jdk/test/java/awt/regtesthelpers/Util.java Fri Jun 08 12:00:22 2012 -0700 @@ -162,16 +162,21 @@ clickOnComp(comp, robot, 50); } + public static Point getTitlePoint(Window decoratedWindow) { + Point p = decoratedWindow.getLocationOnScreen(); + Dimension d = decoratedWindow.getSize(); + return new Point(p.x + (int)(d.getWidth()/2), + p.y + (int)(decoratedWindow.getInsets().top/2)); + } + /* * Clicks on a title of Frame/Dialog. * WARNING: it may fail on some platforms when the window is not wide enough. */ public static void clickOnTitle(final Window decoratedWindow, final Robot robot) { - Point p = decoratedWindow.getLocationOnScreen(); - Dimension d = decoratedWindow.getSize(); - if (decoratedWindow instanceof Frame || decoratedWindow instanceof Dialog) { - robot.mouseMove(p.x + (int)(d.getWidth()/2), p.y + (int)decoratedWindow.getInsets().top/2); + Point p = getTitlePoint(decoratedWindow); + robot.mouseMove(p.x, p.y); robot.delay(50); robot.mousePress(InputEvent.BUTTON1_MASK); robot.delay(50); @@ -409,7 +414,9 @@ ICE_WM = 10, METACITY_WM = 11, COMPIZ_WM = 12, - LG3D_WM = 13; + LG3D_WM = 13, + CWM_WM = 14, + MUTTER_WM = 15; /* * Returns -1 in case of not X Window or any problems. diff -r 2e04ed1b4ce0 -r c5ca850e1dff jdk/test/javax/swing/JPopupMenu/6694823/bug6694823.java --- a/jdk/test/javax/swing/JPopupMenu/6694823/bug6694823.java Fri Jun 08 11:58:45 2012 -0700 +++ b/jdk/test/javax/swing/JPopupMenu/6694823/bug6694823.java Fri Jun 08 12:00:22 2012 -0700 @@ -33,6 +33,8 @@ import javax.swing.*; import java.awt.*; import sun.awt.SunToolkit; +import java.security.Permission; +import sun.security.util.SecurityConstants; public class bug6694823 { private static JFrame frame; @@ -48,6 +50,8 @@ } }); + toolkit.realSync(); + // Get screen insets screenInsets = toolkit.getScreenInsets(frame.getGraphicsConfiguration()); if (screenInsets.bottom == 0) { @@ -55,26 +59,23 @@ return; } - // Show popup as if from a standalone application - // The popup should be able to overlap the task bar - showPopup(false); + System.setSecurityManager(new SecurityManager(){ + + private String allowsAlwaysOnTopPermission = SecurityConstants.AWT.SET_WINDOW_ALWAYS_ON_TOP_PERMISSION.getName(); - // Emulate applet security restrictions - toolkit.realSync(); - System.setSecurityManager(new SecurityManager()); + @Override + public void checkPermission(Permission perm) { + if (allowsAlwaysOnTopPermission.equals(perm.getName())) { + throw new SecurityException(); + } + } + + }); // Show popup as if from an applet // The popup shouldn't overlap the task bar. It should be shifted up. - showPopup(true); - - toolkit.realSync(); - System.out.println("Test passed!"); + checkPopup(); - SwingUtilities.invokeAndWait(new Runnable() { - public void run() { - frame.dispose(); - } - }); } private static void createGui() { @@ -93,7 +94,7 @@ frame.setSize(200, 200); } - private static void showPopup(final boolean shouldBeShifted) throws Exception { + private static void checkPopup() throws Exception { SwingUtilities.invokeAndWait(new Runnable() { public void run() { // Place frame just above the task bar @@ -121,20 +122,14 @@ toolkit.realSync(); SwingUtilities.invokeAndWait(new Runnable() { + public void run() { Point frameLoc = frame.getLocationOnScreen(); - if (shouldBeShifted) { - if (popup.getLocationOnScreen() - .equals(new Point(frameLoc.x, frameLoc.y + point.y))) { - throw new RuntimeException("Popup is not shifted"); - } - } else { - if (!popup.getLocationOnScreen() - .equals(new Point(frameLoc.x, frameLoc.y + point.y))) { - throw new RuntimeException("Popup is unexpectedly shifted"); - } + if (popup.getLocationOnScreen().equals(new Point(frameLoc.x, frameLoc.y + point.y))) { + throw new RuntimeException("Popup is not shifted"); } popup.setVisible(false); + frame.dispose(); } }); } diff -r 2e04ed1b4ce0 -r c5ca850e1dff jdk/test/javax/swing/JPopupMenu/6800513/bug6800513.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/javax/swing/JPopupMenu/6800513/bug6800513.java Fri Jun 08 12:00:22 2012 -0700 @@ -0,0 +1,147 @@ +/* + * Copyright 2012 Red Hat, Inc. All Rights Reserved. + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 6800513 + * @summary GTK-LaF renders menus incompletely + * @author Mario Torre + * @library ../../regtesthelpers/ + * @build Util + * @run main bug6800513 + */ + +import sun.awt.SunToolkit; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.InputEvent; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.lang.reflect.Field; +import java.util.concurrent.Callable; + +public class bug6800513 { + + private static JPopupMenu popupMenu; + private static JMenu menu; + private static JFrame frame; + + public static void testFrame(final boolean defaultLightWeightPopupEnabled, + String expectedPopupClass) throws Exception { + SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); + + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + JPopupMenu.setDefaultLightWeightPopupEnabled(defaultLightWeightPopupEnabled); + createAndShowUI(); + } + }); + + toolkit.realSync(); + + clickOnMenu(); + + toolkit.realSync(); + + Field getPopup = JPopupMenu.class.getDeclaredField("popup"); + getPopup.setAccessible(true); + Popup popup = (Popup) getPopup.get(popupMenu); + + if (popup == null) { + throw new Exception("popup is null!"); + } + + String className = popup.getClass().getName(); + if (!className.equals(expectedPopupClass)) { + throw new Exception("popup class is: " + className + + ", expected: " + expectedPopupClass); + } + + SwingUtilities.invokeAndWait(new Runnable() { + @Override + public void run() { + frame.dispose(); + popupMenu = null; + } + }); + + toolkit.realSync(); + } + + + public static void clickOnMenu() throws Exception { + Rectangle bounds = Util.invokeOnEDT(new Callable() { + @Override + public Rectangle call() throws Exception { + return new Rectangle(menu.getLocationOnScreen(), menu.getSize()); + } + }); + + Robot robot = new Robot(); + robot.setAutoDelay(100); + + robot.mouseMove(bounds.x + bounds.width / 2, bounds.y + bounds.height / 2); + + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + } + + private static class PopupListener implements PropertyChangeListener { + @Override + public void propertyChange(PropertyChangeEvent evt) { + if (evt.toString().contains("visible") && ((Boolean) evt.getNewValue() == true)) { + popupMenu = (JPopupMenu) evt.getSource(); + } + } + } + + public static void createAndShowUI() { + frame = new JFrame(); + + JMenuBar menuBar = new JMenuBar(); + menu = new JMenu("Menu"); + + menu.add(new JMenuItem("Menu Item #1")); + menu.add(new JMenuItem("Menu Item #2")); + menu.add(new JMenuItem("Menu Item #3")); + + menuBar.add(menu); + + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setJMenuBar(menuBar); + frame.setSize(500, 500); + + PopupListener listener = new PopupListener(); + menu.getPopupMenu().addPropertyChangeListener(listener); + + frame.setVisible(true); + } + + public static void main(String[] args) throws Exception { + testFrame(false, "javax.swing.PopupFactory$HeavyWeightPopup"); + + testFrame(true, "javax.swing.PopupFactory$LightWeightPopup"); + } +} diff -r 2e04ed1b4ce0 -r c5ca850e1dff jdk/test/javax/swing/JPopupMenu/7156657/bug7156657.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/javax/swing/JPopupMenu/7156657/bug7156657.java Fri Jun 08 12:00:22 2012 -0700 @@ -0,0 +1,157 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import com.sun.awt.AWTUtilities; +import sun.awt.SunToolkit; + +import javax.swing.*; +import java.awt.*; +import java.awt.image.BufferedImage; +import java.util.concurrent.Callable; + +/* @test + @bug 7156657 + @summary Version 7 doesn't support translucent popup menus against a translucent window + @library ../../regtesthelpers + @author Pavel Porvatov +*/ +public class bug7156657 { + private static JFrame lowerFrame; + + private static JFrame frame; + + private static JPopupMenu popupMenu; + + public static void main(String[] args) throws Exception { + final Robot robot = new Robot(); + final SunToolkit toolkit = ((SunToolkit) Toolkit.getDefaultToolkit()); + + Boolean skipTest = Util.invokeOnEDT(new Callable() { + @Override + public Boolean call() throws Exception { + frame = createFrame(); + + if (!AWTUtilities.isTranslucencyCapable(frame.getGraphicsConfiguration())) { + System.out.println("Translucency is not supported, the test skipped"); + + return true; + } + + lowerFrame = createFrame(); + lowerFrame.getContentPane().setBackground(Color.RED); + lowerFrame.setVisible(true); + + popupMenu = new JPopupMenu(); + popupMenu.setOpaque(false); + popupMenu.add(new TransparentMenuItem("1111")); + popupMenu.add(new TransparentMenuItem("2222")); + popupMenu.add(new TransparentMenuItem("3333")); + + AWTUtilities.setWindowOpaque(frame, false); + JPanel pnContent = new JPanel(); + pnContent.setBackground(new Color(255, 255, 255, 128)); + frame.add(pnContent); + frame.setVisible(true); + + return false; + } + }); + + if (skipTest) { + return; + } + + toolkit.realSync(); + + SwingUtilities.invokeAndWait(new Runnable() { + @Override + public void run() { + popupMenu.show(frame, 0, 0); + } + }); + + toolkit.realSync(); + + Rectangle popupRectangle = Util.invokeOnEDT(new Callable() { + @Override + public Rectangle call() throws Exception { + return popupMenu.getBounds(); + } + }); + + BufferedImage redBackgroundCapture = robot.createScreenCapture(popupRectangle); + + SwingUtilities.invokeAndWait(new Runnable() { + @Override + public void run() { + lowerFrame.getContentPane().setBackground(Color.GREEN); + } + }); + + toolkit.realSync(); + + BufferedImage greenBackgroundCapture = robot.createScreenCapture(popupRectangle); + + if (Util.compareBufferedImages(redBackgroundCapture, greenBackgroundCapture)) { + throw new RuntimeException("The test failed"); + } + + SwingUtilities.invokeAndWait(new Runnable() { + @Override + public void run() { + popupMenu.setVisible(false); + frame.dispose(); + lowerFrame.dispose(); + } + }); + + System.out.println("The test passed"); + } + + + private static JFrame createFrame() { + JFrame result = new JFrame(); + + result.setLocation(0, 0); + result.setSize(400, 300); + result.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + result.setUndecorated(true); + + return result; + } + + private static class TransparentMenuItem extends JMenuItem { + public TransparentMenuItem(String text) { + super(text); + setOpaque(false); + } + + @Override + public void paint(Graphics g) { + Graphics2D g2 = (Graphics2D) g.create(); + g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f)); + super.paint(g2); + g2.dispose(); + } + } +} diff -r 2e04ed1b4ce0 -r c5ca850e1dff jdk/test/javax/swing/JSpinner/5012888/bug5012888.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/javax/swing/JSpinner/5012888/bug5012888.java Fri Jun 08 12:00:22 2012 -0700 @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* @test 1.0 04/04/23 + @bug 5012888 + @summary REGRESSION: Click & hold on arrow of JSpinner only transfers focus + @author Konstantin Eremin + @run main bug5012888 +*/ +import javax.swing.*; +import javax.swing.event.*; +import java.awt.*; +import java.awt.event.*; + +public class bug5012888 extends JFrame { + JSpinner spinner1, spinner2; + public bug5012888() { + spinner1 = new JSpinner(new SpinnerNumberModel(0, -1000, 1000, 1)); + spinner2 = new JSpinner(new SpinnerNumberModel(1, -1000, 1000, 1)); + Container pane = getContentPane(); + pane.setLayout(new BorderLayout()); + pane.add(spinner1, BorderLayout.NORTH); + pane.add(spinner2, BorderLayout.SOUTH); + } + public void doTest() throws Exception { + ((sun.awt.SunToolkit)Toolkit.getDefaultToolkit()).realSync(); + Point p = spinner2.getLocationOnScreen(); + Rectangle rect = spinner2.getBounds(); + Robot robot = new Robot(); + robot.mouseMove(p.x+rect.width-5, p.y+5); + robot.mousePress(InputEvent.BUTTON1_MASK); + Thread.sleep(1000); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + if ( ((Integer) spinner2.getValue()).intValue() == 1 ) { + throw new Error("Spinner value should be more than 1"); + } + } + public static void main(String[] argv) throws Exception { + bug5012888 b = new bug5012888(); + b.setBounds(0, 0, 100, 100); + b.setVisible(true); + b.doTest(); + } +}