37 import sun.awt.AWTAccessor.ComponentAccessor;
38 import sun.util.logging.PlatformLogger;
39
40 import sun.awt.*;
41
42 import sun.awt.image.PixelConverter;
43
44 import sun.java2d.SunGraphics2D;
45 import sun.java2d.SurfaceData;
46
47 class XWindow extends XBaseWindow implements X11ComponentPeer {
48 private static PlatformLogger log = PlatformLogger.getLogger("sun.awt.X11.XWindow");
49 private static PlatformLogger insLog = PlatformLogger.getLogger("sun.awt.X11.insets.XWindow");
50 private static PlatformLogger eventLog = PlatformLogger.getLogger("sun.awt.X11.event.XWindow");
51 private static final PlatformLogger focusLog = PlatformLogger.getLogger("sun.awt.X11.focus.XWindow");
52 private static PlatformLogger keyEventLog = PlatformLogger.getLogger("sun.awt.X11.kye.XWindow");
53 /* If a motion comes in while a multi-click is pending,
54 * allow a smudge factor so that moving the mouse by a small
55 * amount does not wipe out the multi-click state variables.
56 */
57 private final static int AWT_MULTICLICK_SMUDGE = 4;
58 // ButtonXXX events stuff
59 static int lastX = 0, lastY = 0;
60 static long lastTime = 0;
61 static long lastButton = 0;
62 static WeakReference<XWindow> lastWindowRef = null;
63 static int clickCount = 0;
64
65 // used to check if we need to re-create surfaceData.
66 int oldWidth = -1;
67 int oldHeight = -1;
68
69 protected PropMwmHints mwm_hints;
70 protected static XAtom wm_protocols;
71 protected static XAtom wm_delete_window;
72 protected static XAtom wm_take_focus;
73
74 private boolean stateChanged; // Indicates whether the value on savedState is valid
75 private int savedState; // Holds last known state of the top-level window
76
77 XWindowAttributesData winAttr;
106 static synchronized Font getDefaultFont() {
107 if (null == defaultFont) {
108 defaultFont = new Font(Font.DIALOG, Font.PLAIN, 12);
109 }
110 return defaultFont;
111 }
112
113 /* A bitmask keeps the button's numbers as Button1Mask, Button2Mask, Button3Mask
114 * which are allowed to
115 * generate the CLICK event after the RELEASE has happened.
116 * There are conditions that must be true for that sending CLICK event:
117 * 1) button was initially PRESSED
118 * 2) no movement or drag has happened until RELEASE
119 */
120 private int mouseButtonClickAllowed = 0;
121
122 native int getNativeColor(Color clr, GraphicsConfiguration gc);
123 native void getWMInsets(long window, long left, long top, long right, long bottom, long border);
124 native long getTopWindow(long window, long rootWin);
125 native void getWindowBounds(long window, long x, long y, long width, long height);
126 private native static void initIDs();
127
128 static {
129 initIDs();
130 }
131
132 XWindow(XCreateWindowParams params) {
133 super(params);
134 }
135
136 XWindow() {
137 }
138
139 XWindow(long parentWindow, Rectangle bounds) {
140 super(new XCreateWindowParams(new Object[] {
141 BOUNDS, bounds,
142 PARENT_WINDOW, Long.valueOf(parentWindow)}));
143 }
144
145 XWindow(Component target, long parentWindow, Rectangle bounds) {
146 super(new XCreateWindowParams(new Object[] {
424 XToolkit.postEvent(XToolkit.targetToAppContext(event.getSource()), event);
425 }
426
427 public void postEventToEventQueue(final AWTEvent event) {
428 //fix for 6239938 : Choice drop-down does not disappear when it loses focus, on XToolkit
429 if (!prePostEvent(event)) {
430 //event hasn't been handled and must be posted to EventQueue
431 postEvent(event);
432 }
433 }
434
435 // overriden in XCanvasPeer
436 protected boolean doEraseBackground() {
437 return true;
438 }
439
440 // We need a version of setBackground that does not call repaint !!
441 // and one that does not get overridden. The problem is that in postInit
442 // we call setBackground and we don't have all the stuff initialized to
443 // do a full paint for most peers. So we cannot call setBackground in postInit.
444 final public void xSetBackground(Color c) {
445 XToolkit.awtLock();
446 try {
447 winBackground(c);
448 // fix for 6558510: handle sun.awt.noerasebackground flag,
449 // see doEraseBackground() and preInit() methods in XCanvasPeer
450 if (!doEraseBackground()) {
451 return;
452 }
453 // 6304250: XAWT: Items in choice show a blue border on OpenGL + Solaris10 when background color is set
454 // Note: When OGL is enabled, surfaceData.pixelFor() will not
455 // return a pixel value appropriate for passing to
456 // XSetWindowBackground(). Therefore, we will use the ColorModel
457 // for this component in order to calculate a pixel value from
458 // the given RGB value.
459 ColorModel cm = getColorModel();
460 int pixel = PixelConverter.instance.rgbToPixel(c.getRGB(), cm);
461 XlibWrapper.XSetWindowBackground(XToolkit.getDisplay(), getContentWindow(), pixel);
462 XlibWrapper.XClearWindow(XToolkit.getDisplay(), getContentWindow());
463 }
464 finally {
1029 private void dumpKeysymArray(XKeyEvent ev) {
1030 if (keyEventLog.isLoggable(PlatformLogger.Level.FINE)) {
1031 keyEventLog.fine(" "+Long.toHexString(XlibWrapper.XKeycodeToKeysym(XToolkit.getDisplay(), ev.get_keycode(), 0))+
1032 "\n "+Long.toHexString(XlibWrapper.XKeycodeToKeysym(XToolkit.getDisplay(), ev.get_keycode(), 1))+
1033 "\n "+Long.toHexString(XlibWrapper.XKeycodeToKeysym(XToolkit.getDisplay(), ev.get_keycode(), 2))+
1034 "\n "+Long.toHexString(XlibWrapper.XKeycodeToKeysym(XToolkit.getDisplay(), ev.get_keycode(), 3)));
1035 }
1036 }
1037 /**
1038 Return unicode character or 0 if no correspondent character found.
1039 Parameter is a keysym basically from keysymdef.h
1040 XXX: how about vendor keys? Is there some with Unicode value and not in the list?
1041 */
1042 int keysymToUnicode( long keysym, int state ) {
1043 return XKeysym.convertKeysym( keysym, state );
1044 }
1045 int keyEventType2Id( int xEventType ) {
1046 return xEventType == XConstants.KeyPress ? java.awt.event.KeyEvent.KEY_PRESSED :
1047 xEventType == XConstants.KeyRelease ? java.awt.event.KeyEvent.KEY_RELEASED : 0;
1048 }
1049 static private long xkeycodeToKeysym(XKeyEvent ev) {
1050 return XKeysym.getKeysym( ev );
1051 }
1052 private long xkeycodeToPrimaryKeysym(XKeyEvent ev) {
1053 return XKeysym.xkeycode2primary_keysym( ev );
1054 }
1055 static private int primaryUnicode2JavaKeycode(int uni) {
1056 return (uni > 0? sun.awt.ExtendedKeyCodes.getExtendedKeyCodeForChar(uni) : 0);
1057 //return (uni > 0? uni + 0x01000000 : 0);
1058 }
1059 void logIncomingKeyEvent(XKeyEvent ev) {
1060 if (keyEventLog.isLoggable(PlatformLogger.Level.FINE)) {
1061 keyEventLog.fine("--XWindow.java:handleKeyEvent:"+ev);
1062 }
1063 dumpKeysymArray(ev);
1064 if (keyEventLog.isLoggable(PlatformLogger.Level.FINE)) {
1065 keyEventLog.fine("XXXXXXXXXXXXXX javakeycode will be most probably:0x"+ Integer.toHexString(XKeysym.getJavaKeycodeOnly(ev)));
1066 }
1067 }
1068 public void handleKeyPress(XEvent xev) {
1069 super.handleKeyPress(xev);
1070 XKeyEvent ev = xev.get_xkey();
1071 if (eventLog.isLoggable(PlatformLogger.Level.FINE)) {
1072 eventLog.fine(ev.toString());
1073 }
1074 if (isEventDisabled(xev)) {
1075 return;
|
37 import sun.awt.AWTAccessor.ComponentAccessor;
38 import sun.util.logging.PlatformLogger;
39
40 import sun.awt.*;
41
42 import sun.awt.image.PixelConverter;
43
44 import sun.java2d.SunGraphics2D;
45 import sun.java2d.SurfaceData;
46
47 class XWindow extends XBaseWindow implements X11ComponentPeer {
48 private static PlatformLogger log = PlatformLogger.getLogger("sun.awt.X11.XWindow");
49 private static PlatformLogger insLog = PlatformLogger.getLogger("sun.awt.X11.insets.XWindow");
50 private static PlatformLogger eventLog = PlatformLogger.getLogger("sun.awt.X11.event.XWindow");
51 private static final PlatformLogger focusLog = PlatformLogger.getLogger("sun.awt.X11.focus.XWindow");
52 private static PlatformLogger keyEventLog = PlatformLogger.getLogger("sun.awt.X11.kye.XWindow");
53 /* If a motion comes in while a multi-click is pending,
54 * allow a smudge factor so that moving the mouse by a small
55 * amount does not wipe out the multi-click state variables.
56 */
57 private static final int AWT_MULTICLICK_SMUDGE = 4;
58 // ButtonXXX events stuff
59 static int lastX = 0, lastY = 0;
60 static long lastTime = 0;
61 static long lastButton = 0;
62 static WeakReference<XWindow> lastWindowRef = null;
63 static int clickCount = 0;
64
65 // used to check if we need to re-create surfaceData.
66 int oldWidth = -1;
67 int oldHeight = -1;
68
69 protected PropMwmHints mwm_hints;
70 protected static XAtom wm_protocols;
71 protected static XAtom wm_delete_window;
72 protected static XAtom wm_take_focus;
73
74 private boolean stateChanged; // Indicates whether the value on savedState is valid
75 private int savedState; // Holds last known state of the top-level window
76
77 XWindowAttributesData winAttr;
106 static synchronized Font getDefaultFont() {
107 if (null == defaultFont) {
108 defaultFont = new Font(Font.DIALOG, Font.PLAIN, 12);
109 }
110 return defaultFont;
111 }
112
113 /* A bitmask keeps the button's numbers as Button1Mask, Button2Mask, Button3Mask
114 * which are allowed to
115 * generate the CLICK event after the RELEASE has happened.
116 * There are conditions that must be true for that sending CLICK event:
117 * 1) button was initially PRESSED
118 * 2) no movement or drag has happened until RELEASE
119 */
120 private int mouseButtonClickAllowed = 0;
121
122 native int getNativeColor(Color clr, GraphicsConfiguration gc);
123 native void getWMInsets(long window, long left, long top, long right, long bottom, long border);
124 native long getTopWindow(long window, long rootWin);
125 native void getWindowBounds(long window, long x, long y, long width, long height);
126 private static native void initIDs();
127
128 static {
129 initIDs();
130 }
131
132 XWindow(XCreateWindowParams params) {
133 super(params);
134 }
135
136 XWindow() {
137 }
138
139 XWindow(long parentWindow, Rectangle bounds) {
140 super(new XCreateWindowParams(new Object[] {
141 BOUNDS, bounds,
142 PARENT_WINDOW, Long.valueOf(parentWindow)}));
143 }
144
145 XWindow(Component target, long parentWindow, Rectangle bounds) {
146 super(new XCreateWindowParams(new Object[] {
424 XToolkit.postEvent(XToolkit.targetToAppContext(event.getSource()), event);
425 }
426
427 public void postEventToEventQueue(final AWTEvent event) {
428 //fix for 6239938 : Choice drop-down does not disappear when it loses focus, on XToolkit
429 if (!prePostEvent(event)) {
430 //event hasn't been handled and must be posted to EventQueue
431 postEvent(event);
432 }
433 }
434
435 // overriden in XCanvasPeer
436 protected boolean doEraseBackground() {
437 return true;
438 }
439
440 // We need a version of setBackground that does not call repaint !!
441 // and one that does not get overridden. The problem is that in postInit
442 // we call setBackground and we don't have all the stuff initialized to
443 // do a full paint for most peers. So we cannot call setBackground in postInit.
444 public final void xSetBackground(Color c) {
445 XToolkit.awtLock();
446 try {
447 winBackground(c);
448 // fix for 6558510: handle sun.awt.noerasebackground flag,
449 // see doEraseBackground() and preInit() methods in XCanvasPeer
450 if (!doEraseBackground()) {
451 return;
452 }
453 // 6304250: XAWT: Items in choice show a blue border on OpenGL + Solaris10 when background color is set
454 // Note: When OGL is enabled, surfaceData.pixelFor() will not
455 // return a pixel value appropriate for passing to
456 // XSetWindowBackground(). Therefore, we will use the ColorModel
457 // for this component in order to calculate a pixel value from
458 // the given RGB value.
459 ColorModel cm = getColorModel();
460 int pixel = PixelConverter.instance.rgbToPixel(c.getRGB(), cm);
461 XlibWrapper.XSetWindowBackground(XToolkit.getDisplay(), getContentWindow(), pixel);
462 XlibWrapper.XClearWindow(XToolkit.getDisplay(), getContentWindow());
463 }
464 finally {
1029 private void dumpKeysymArray(XKeyEvent ev) {
1030 if (keyEventLog.isLoggable(PlatformLogger.Level.FINE)) {
1031 keyEventLog.fine(" "+Long.toHexString(XlibWrapper.XKeycodeToKeysym(XToolkit.getDisplay(), ev.get_keycode(), 0))+
1032 "\n "+Long.toHexString(XlibWrapper.XKeycodeToKeysym(XToolkit.getDisplay(), ev.get_keycode(), 1))+
1033 "\n "+Long.toHexString(XlibWrapper.XKeycodeToKeysym(XToolkit.getDisplay(), ev.get_keycode(), 2))+
1034 "\n "+Long.toHexString(XlibWrapper.XKeycodeToKeysym(XToolkit.getDisplay(), ev.get_keycode(), 3)));
1035 }
1036 }
1037 /**
1038 Return unicode character or 0 if no correspondent character found.
1039 Parameter is a keysym basically from keysymdef.h
1040 XXX: how about vendor keys? Is there some with Unicode value and not in the list?
1041 */
1042 int keysymToUnicode( long keysym, int state ) {
1043 return XKeysym.convertKeysym( keysym, state );
1044 }
1045 int keyEventType2Id( int xEventType ) {
1046 return xEventType == XConstants.KeyPress ? java.awt.event.KeyEvent.KEY_PRESSED :
1047 xEventType == XConstants.KeyRelease ? java.awt.event.KeyEvent.KEY_RELEASED : 0;
1048 }
1049 private static long xkeycodeToKeysym(XKeyEvent ev) {
1050 return XKeysym.getKeysym( ev );
1051 }
1052 private long xkeycodeToPrimaryKeysym(XKeyEvent ev) {
1053 return XKeysym.xkeycode2primary_keysym( ev );
1054 }
1055 private static int primaryUnicode2JavaKeycode(int uni) {
1056 return (uni > 0? sun.awt.ExtendedKeyCodes.getExtendedKeyCodeForChar(uni) : 0);
1057 //return (uni > 0? uni + 0x01000000 : 0);
1058 }
1059 void logIncomingKeyEvent(XKeyEvent ev) {
1060 if (keyEventLog.isLoggable(PlatformLogger.Level.FINE)) {
1061 keyEventLog.fine("--XWindow.java:handleKeyEvent:"+ev);
1062 }
1063 dumpKeysymArray(ev);
1064 if (keyEventLog.isLoggable(PlatformLogger.Level.FINE)) {
1065 keyEventLog.fine("XXXXXXXXXXXXXX javakeycode will be most probably:0x"+ Integer.toHexString(XKeysym.getJavaKeycodeOnly(ev)));
1066 }
1067 }
1068 public void handleKeyPress(XEvent xev) {
1069 super.handleKeyPress(xev);
1070 XKeyEvent ev = xev.get_xkey();
1071 if (eventLog.isLoggable(PlatformLogger.Level.FINE)) {
1072 eventLog.fine(ev.toString());
1073 }
1074 if (isEventDisabled(xev)) {
1075 return;
|