src/solaris/classes/sun/awt/X11/XWindow.java

Print this page


   1 /*
   2  * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 183 
 184         initGraphicsConfiguration();
 185 
 186         AwtGraphicsConfigData gData = getGraphicsConfigurationData();
 187         X11GraphicsConfig config = (X11GraphicsConfig) getGraphicsConfiguration();
 188         XVisualInfo visInfo = gData.get_awt_visInfo();
 189         params.putIfNull(EVENT_MASK, XConstants.KeyPressMask | XConstants.KeyReleaseMask
 190             | XConstants.FocusChangeMask | XConstants.ButtonPressMask | XConstants.ButtonReleaseMask
 191             | XConstants.EnterWindowMask | XConstants.LeaveWindowMask | XConstants.PointerMotionMask
 192             | XConstants.ButtonMotionMask | XConstants.ExposureMask | XConstants.StructureNotifyMask);
 193 
 194         if (target != null) {
 195             params.putIfNull(BOUNDS, new Rectangle(target.getBounds()));
 196         } else {
 197             params.putIfNull(BOUNDS, new Rectangle(0, 0, MIN_SIZE, MIN_SIZE));
 198         }
 199         params.putIfNull(BORDER_PIXEL, Long.valueOf(0));
 200         getColorModel(); // fix 4948833: this call forces the color map to be initialized
 201         params.putIfNull(COLORMAP, gData.get_awt_cmap());
 202         params.putIfNull(DEPTH, gData.get_awt_depth());
 203         params.putIfNull(VISUAL_CLASS, Integer.valueOf((int)XConstants.InputOutput));
 204         params.putIfNull(VISUAL, visInfo.get_visual());
 205         params.putIfNull(VALUE_MASK, XConstants.CWBorderPixel | XConstants.CWEventMask | XConstants.CWColormap);
 206         Long parentWindow = (Long)params.get(PARENT_WINDOW);
 207         if (parentWindow == null || parentWindow.longValue() == 0) {
 208             XToolkit.awtLock();
 209             try {
 210                 int screen = visInfo.get_screen();
 211                 if (screen != -1) {
 212                     params.add(PARENT_WINDOW, XlibWrapper.RootWindow(XToolkit.getDisplay(), screen));
 213                 } else {
 214                     params.add(PARENT_WINDOW, XToolkit.getDefaultRootWindow());
 215                 }
 216             } finally {
 217                 XToolkit.awtUnlock();
 218             }
 219         }
 220 
 221         paintArea = new XRepaintArea();
 222         if (target != null) {
 223             this.parent = getParentXWindowObject(target.getParent());


 333     public Component getEventSource() {
 334         return target;
 335     }
 336 
 337     public ColorModel getColorModel(int transparency) {
 338         return graphicsConfig.getColorModel (transparency);
 339     }
 340 
 341     public ColorModel getColorModel() {
 342         if (graphicsConfig != null) {
 343             return graphicsConfig.getColorModel ();
 344         }
 345         else {
 346             return XToolkit.getStaticColorModel();
 347         }
 348     }
 349 
 350     Graphics getGraphics(SurfaceData surfData, Color afore, Color aback, Font afont) {
 351         if (surfData == null) return null;
 352 
 353         Component target = (Component) this.target;
 354 
 355         /* Fix for bug 4746122. Color and Font shouldn't be null */
 356         Color bgColor = aback;
 357         if (bgColor == null) {
 358             bgColor = SystemColor.window;
 359         }
 360         Color fgColor = afore;
 361         if (fgColor == null) {
 362             fgColor = SystemColor.windowText;
 363         }
 364         Font font = afont;
 365         if (font == null) {
 366             font = XWindow.getDefaultFont();
 367         }
 368         return new SunGraphics2D(surfData, fgColor, bgColor, font);
 369     }
 370 
 371     public Graphics getGraphics() {
 372         return getGraphics(surfaceData,
 373                            target.getForeground(),


 531             XToolkit.awtUnlock();
 532         }
 533     }
 534 
 535     public void popup(int x, int y, int width, int height) {
 536         // TBD: grab the pointer
 537         xSetBounds(x, y, width, height);
 538     }
 539 
 540     public void handleExposeEvent(XEvent xev) {
 541         super.handleExposeEvent(xev);
 542         XExposeEvent xe = xev.get_xexpose();
 543         if (isEventDisabled(xev)) {
 544             return;
 545         }
 546         int x = xe.get_x();
 547         int y = xe.get_y();
 548         int w = xe.get_width();
 549         int h = xe.get_height();
 550 
 551         Component target = (Component)getEventSource();
 552         AWTAccessor.ComponentAccessor compAccessor = AWTAccessor.getComponentAccessor();
 553 
 554         if (!compAccessor.getIgnoreRepaint(target)
 555             && compAccessor.getWidth(target) != 0
 556             && compAccessor.getHeight(target) != 0)
 557         {
 558             postPaintEvent(target, x, y, w, h);
 559         }
 560     }
 561 
 562     public void postPaintEvent(Component target, int x, int y, int w, int h) {
 563         PaintEvent event = PaintEventDispatcher.getPaintEventDispatcher().
 564             createPaintEvent(target, x, y, w, h);
 565         if (event != null) {
 566             postEventToEventQueue(event);
 567         }
 568     }
 569 
 570     static int getModifiers(int state, int button, int keyCode) {
 571         return getModifiers(state, button, keyCode, 0,  false);


 723         }
 724 
 725         button = XConstants.buttons[lbutton - 1];
 726         // 4 and 5 buttons are usually considered assigned to a first wheel
 727         if (lbutton == XConstants.buttons[3] ||
 728             lbutton == XConstants.buttons[4]) {
 729             wheel_mouse = true;
 730         }
 731 
 732         // mapping extra buttons to numbers starting from 4.
 733         if ((button > XConstants.buttons[4]) && (!Toolkit.getDefaultToolkit().areExtraMouseButtonsEnabled())){
 734             return;
 735         }
 736 
 737         if (button > XConstants.buttons[4]){
 738             button -= 2;
 739         }
 740         modifiers = getModifiers(xbe.get_state(),button,0, type, wheel_mouse);
 741 
 742         if (!wheel_mouse) {
 743             MouseEvent me = new MouseEvent((Component)getEventSource(),
 744                                            type == XConstants.ButtonPress ? MouseEvent.MOUSE_PRESSED : MouseEvent.MOUSE_RELEASED,
 745                                            jWhen,modifiers, x, y,
 746                                            xbe.get_x_root(),
 747                                            xbe.get_y_root(),
 748                                            clickCount,popupTrigger,button);
 749 
 750             postEventToEventQueue(me);
 751 
 752             if ((type == XConstants.ButtonRelease) &&
 753                 ((mouseButtonClickAllowed & XlibUtil.getButtonMask(lbutton)) != 0) ) // No up-button in the drag-state
 754             {
 755                 postEventToEventQueue(me = new MouseEvent((Component)getEventSource(),
 756                                                      MouseEvent.MOUSE_CLICKED,
 757                                                      jWhen,
 758                                                      modifiers,
 759                                                      x, y,
 760                                                      xbe.get_x_root(),
 761                                                      xbe.get_y_root(),
 762                                                      clickCount,
 763                                                      false, button));
 764             }
 765 
 766         }
 767         else {
 768             if (xev.get_type() == XConstants.ButtonPress) {
 769                 MouseWheelEvent mwe = new MouseWheelEvent((Component)getEventSource(),MouseEvent.MOUSE_WHEEL, jWhen,
 770                                                           modifiers,
 771                                                           x, y,
 772                                                           xbe.get_x_root(),
 773                                                           xbe.get_y_root(),
 774                                                           1,false,MouseWheelEvent.WHEEL_UNIT_SCROLL,
 775                                                           3,button==4 ?  -1 : 1);
 776                 postEventToEventQueue(mwe);
 777             }
 778         }
 779 
 780         /* Update the state variable AFTER the CLICKED event post. */
 781         if (type == XConstants.ButtonRelease) {
 782             /* Exclude this mouse button from allowed list.*/
 783             mouseButtonClickAllowed &= ~ XlibUtil.getButtonMask(lbutton);
 784         }
 785     }
 786 
 787     public void handleMotionNotify(XEvent xev) {
 788         super.handleMotionNotify(xev);
 789         XMotionEvent xme = xev.get_xmotion();


 820         int x = xme.get_x();
 821         int y = xme.get_y();
 822         XWindow lastWindow = (lastWindowRef != null) ? ((XWindow)lastWindowRef.get()):(null);
 823 
 824         if (!(lastWindow == this &&
 825               (xme.get_time() - lastTime) < XToolkit.getMultiClickTime()  &&
 826               (Math.abs(lastX - x) < AWT_MULTICLICK_SMUDGE &&
 827                Math.abs(lastY - y) < AWT_MULTICLICK_SMUDGE))) {
 828           clickCount = 0;
 829           lastWindowRef = null;
 830           mouseButtonClickAllowed = 0;
 831           lastTime = 0;
 832           lastX = 0;
 833           lastY = 0;
 834         }
 835 
 836         long jWhen = XToolkit.nowMillisUTC_offset(xme.get_time());
 837         int modifiers = getModifiers(xme.get_state(), 0, 0);
 838         boolean popupTrigger = false;
 839 
 840         Component source = (Component)getEventSource();
 841 
 842         if (xme.get_window() != window) {
 843             Point localXY = toLocal(xme.get_x_root(), xme.get_y_root());
 844             x = localXY.x;
 845             y = localXY.y;
 846         }
 847         /* Fix for 5039416.
 848          * According to canvas.c we shouldn't post any MouseEvent if mouse is dragging and clickCount!=0.
 849          */
 850         if ((isDragging && clickCount == 0) || !isDragging) {
 851             MouseEvent mme = new MouseEvent(source, mouseEventType, jWhen,
 852                                             modifiers, x, y, xme.get_x_root(), xme.get_y_root(),
 853                                             clickCount, popupTrigger, MouseEvent.NOBUTTON);
 854             postEventToEventQueue(mme);
 855         }
 856     }
 857 
 858 
 859     // REMIND: need to implement looking for disabled events
 860     public native boolean x11inputMethodLookupString(long event, long [] keysymArray);


1094         int unicodeKey = 0;
1095         keysym[0] = XConstants.NoSymbol;
1096 
1097         if (keyEventLog.isLoggable(PlatformLogger.Level.FINE)) {
1098             logIncomingKeyEvent( ev );
1099         }
1100         if ( //TODO check if there's an active input method instance
1101              // without calling a native method. Is it necessary though?
1102             haveCurrentX11InputMethodInstance()) {
1103             if (x11inputMethodLookupString(ev.pData, keysym)) {
1104                 if (keyEventLog.isLoggable(PlatformLogger.Level.FINE)) {
1105                     keyEventLog.fine("--XWindow.java XIM did process event; return; dec keysym processed:"+(keysym[0])+
1106                                    "; hex keysym processed:"+Long.toHexString(keysym[0])
1107                                    );
1108                 }
1109                 return;
1110             }else {
1111                 unicodeKey = keysymToUnicode( keysym[0], ev.get_state() );
1112                 if (keyEventLog.isLoggable(PlatformLogger.Level.FINE)) {
1113                     keyEventLog.fine("--XWindow.java XIM did NOT process event, hex keysym:"+Long.toHexString(keysym[0])+"\n"+
1114                                      "                                         unicode key:"+Integer.toHexString((int)unicodeKey));
1115                 }
1116             }
1117         }else  {
1118             // No input method instance found. For example, there's a Java Input Method.
1119             // Produce do-it-yourself keysym and perhaps unicode character.
1120             keysym[0] = xkeycodeToKeysym(ev);
1121             unicodeKey = keysymToUnicode( keysym[0], ev.get_state() );
1122             if (keyEventLog.isLoggable(PlatformLogger.Level.FINE)) {
1123                 keyEventLog.fine("--XWindow.java XIM is absent;             hex keysym:"+Long.toHexString(keysym[0])+"\n"+
1124                                  "                                         unicode key:"+Integer.toHexString((int)unicodeKey));
1125             }
1126         }
1127         // Keysym should be converted to Unicode, if possible and necessary,
1128         // and Java KeyEvent keycode should be calculated.
1129         // For press we should post pressed & typed Java events.
1130         //
1131         // Press event might be not processed to this time because
1132         //  (1) either XIM could not handle it or
1133         //  (2) it was Latin 1:1 mapping.
1134         //
1135         // Preserve modifiers to get Java key code for dead keys
1136         boolean isDeadKey = isDeadKey(keysym[0]);
1137         XKeysym.Keysym2JavaKeycode jkc = isDeadKey ? XKeysym.getJavaKeycode(keysym[0])
1138                 : XKeysym.getJavaKeycode(ev);
1139         if( jkc == null ) {
1140             jkc = new XKeysym.Keysym2JavaKeycode(java.awt.event.KeyEvent.VK_UNDEFINED, java.awt.event.KeyEvent.KEY_LOCATION_UNKNOWN);
1141         }
1142 
1143         // Take the first keysym from a keysym array associated with the XKeyevent
1144         // and convert it to Unicode. Then, even if a Java keycode for the keystroke


1449                 return pt;
1450             } finally {
1451                 XToolkit.awtUnlock();
1452             }
1453         }
1454     }
1455 
1456 
1457     static void setBData(KeyEvent e, byte[] data) {
1458         AWTAccessor.getAWTEventAccessor().setBData(e, data);
1459     }
1460 
1461     public void postKeyEvent(int id, long when, int keyCode, int keyChar,
1462         int keyLocation, int state, long event, int eventSize, long rawCode,
1463         int unicodeFromPrimaryKeysym, int extendedKeyCode)
1464 
1465     {
1466         long jWhen = XToolkit.nowMillisUTC_offset(when);
1467         int modifiers = getModifiers(state, 0, keyCode);
1468 
1469         KeyEvent ke = new KeyEvent((Component)getEventSource(), id, jWhen,
1470                                    modifiers, keyCode, (char)keyChar, keyLocation);
1471         if (event != 0) {
1472             byte[] data = Native.toBytes(event, eventSize);
1473             setBData(ke, data);
1474         }
1475 
1476         AWTAccessor.KeyEventAccessor kea = AWTAccessor.getKeyEventAccessor();
1477         kea.setRawCode(ke, rawCode);
1478         kea.setPrimaryLevelUnicode(ke, (long)unicodeFromPrimaryKeysym);
1479         kea.setExtendedKeyCode(ke, (long)extendedKeyCode);
1480         postEventToEventQueue(ke);
1481     }
1482 
1483     static native int getAWTKeyCodeForKeySym(int keysym);
1484     static native int getKeySymForAWTKeyCode(int keycode);
1485 
1486     /* These two methods are actually applicable to toplevel windows only.
1487      * However, the functionality is required by both the XWindowPeer and
1488      * XWarningWindow, both of which have the XWindow as a common ancestor.
1489      * See XWM.setMotifDecor() for details.


   1 /*
   2  * Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 183 
 184         initGraphicsConfiguration();
 185 
 186         AwtGraphicsConfigData gData = getGraphicsConfigurationData();
 187         X11GraphicsConfig config = (X11GraphicsConfig) getGraphicsConfiguration();
 188         XVisualInfo visInfo = gData.get_awt_visInfo();
 189         params.putIfNull(EVENT_MASK, XConstants.KeyPressMask | XConstants.KeyReleaseMask
 190             | XConstants.FocusChangeMask | XConstants.ButtonPressMask | XConstants.ButtonReleaseMask
 191             | XConstants.EnterWindowMask | XConstants.LeaveWindowMask | XConstants.PointerMotionMask
 192             | XConstants.ButtonMotionMask | XConstants.ExposureMask | XConstants.StructureNotifyMask);
 193 
 194         if (target != null) {
 195             params.putIfNull(BOUNDS, new Rectangle(target.getBounds()));
 196         } else {
 197             params.putIfNull(BOUNDS, new Rectangle(0, 0, MIN_SIZE, MIN_SIZE));
 198         }
 199         params.putIfNull(BORDER_PIXEL, Long.valueOf(0));
 200         getColorModel(); // fix 4948833: this call forces the color map to be initialized
 201         params.putIfNull(COLORMAP, gData.get_awt_cmap());
 202         params.putIfNull(DEPTH, gData.get_awt_depth());
 203         params.putIfNull(VISUAL_CLASS, Integer.valueOf(XConstants.InputOutput));
 204         params.putIfNull(VISUAL, visInfo.get_visual());
 205         params.putIfNull(VALUE_MASK, XConstants.CWBorderPixel | XConstants.CWEventMask | XConstants.CWColormap);
 206         Long parentWindow = (Long)params.get(PARENT_WINDOW);
 207         if (parentWindow == null || parentWindow.longValue() == 0) {
 208             XToolkit.awtLock();
 209             try {
 210                 int screen = visInfo.get_screen();
 211                 if (screen != -1) {
 212                     params.add(PARENT_WINDOW, XlibWrapper.RootWindow(XToolkit.getDisplay(), screen));
 213                 } else {
 214                     params.add(PARENT_WINDOW, XToolkit.getDefaultRootWindow());
 215                 }
 216             } finally {
 217                 XToolkit.awtUnlock();
 218             }
 219         }
 220 
 221         paintArea = new XRepaintArea();
 222         if (target != null) {
 223             this.parent = getParentXWindowObject(target.getParent());


 333     public Component getEventSource() {
 334         return target;
 335     }
 336 
 337     public ColorModel getColorModel(int transparency) {
 338         return graphicsConfig.getColorModel (transparency);
 339     }
 340 
 341     public ColorModel getColorModel() {
 342         if (graphicsConfig != null) {
 343             return graphicsConfig.getColorModel ();
 344         }
 345         else {
 346             return XToolkit.getStaticColorModel();
 347         }
 348     }
 349 
 350     Graphics getGraphics(SurfaceData surfData, Color afore, Color aback, Font afont) {
 351         if (surfData == null) return null;
 352 
 353         Component target = this.target;
 354 
 355         /* Fix for bug 4746122. Color and Font shouldn't be null */
 356         Color bgColor = aback;
 357         if (bgColor == null) {
 358             bgColor = SystemColor.window;
 359         }
 360         Color fgColor = afore;
 361         if (fgColor == null) {
 362             fgColor = SystemColor.windowText;
 363         }
 364         Font font = afont;
 365         if (font == null) {
 366             font = XWindow.getDefaultFont();
 367         }
 368         return new SunGraphics2D(surfData, fgColor, bgColor, font);
 369     }
 370 
 371     public Graphics getGraphics() {
 372         return getGraphics(surfaceData,
 373                            target.getForeground(),


 531             XToolkit.awtUnlock();
 532         }
 533     }
 534 
 535     public void popup(int x, int y, int width, int height) {
 536         // TBD: grab the pointer
 537         xSetBounds(x, y, width, height);
 538     }
 539 
 540     public void handleExposeEvent(XEvent xev) {
 541         super.handleExposeEvent(xev);
 542         XExposeEvent xe = xev.get_xexpose();
 543         if (isEventDisabled(xev)) {
 544             return;
 545         }
 546         int x = xe.get_x();
 547         int y = xe.get_y();
 548         int w = xe.get_width();
 549         int h = xe.get_height();
 550 
 551         Component target = getEventSource();
 552         AWTAccessor.ComponentAccessor compAccessor = AWTAccessor.getComponentAccessor();
 553 
 554         if (!compAccessor.getIgnoreRepaint(target)
 555             && compAccessor.getWidth(target) != 0
 556             && compAccessor.getHeight(target) != 0)
 557         {
 558             postPaintEvent(target, x, y, w, h);
 559         }
 560     }
 561 
 562     public void postPaintEvent(Component target, int x, int y, int w, int h) {
 563         PaintEvent event = PaintEventDispatcher.getPaintEventDispatcher().
 564             createPaintEvent(target, x, y, w, h);
 565         if (event != null) {
 566             postEventToEventQueue(event);
 567         }
 568     }
 569 
 570     static int getModifiers(int state, int button, int keyCode) {
 571         return getModifiers(state, button, keyCode, 0,  false);


 723         }
 724 
 725         button = XConstants.buttons[lbutton - 1];
 726         // 4 and 5 buttons are usually considered assigned to a first wheel
 727         if (lbutton == XConstants.buttons[3] ||
 728             lbutton == XConstants.buttons[4]) {
 729             wheel_mouse = true;
 730         }
 731 
 732         // mapping extra buttons to numbers starting from 4.
 733         if ((button > XConstants.buttons[4]) && (!Toolkit.getDefaultToolkit().areExtraMouseButtonsEnabled())){
 734             return;
 735         }
 736 
 737         if (button > XConstants.buttons[4]){
 738             button -= 2;
 739         }
 740         modifiers = getModifiers(xbe.get_state(),button,0, type, wheel_mouse);
 741 
 742         if (!wheel_mouse) {
 743             MouseEvent me = new MouseEvent(getEventSource(),
 744                                            type == XConstants.ButtonPress ? MouseEvent.MOUSE_PRESSED : MouseEvent.MOUSE_RELEASED,
 745                                            jWhen,modifiers, x, y,
 746                                            xbe.get_x_root(),
 747                                            xbe.get_y_root(),
 748                                            clickCount,popupTrigger,button);
 749 
 750             postEventToEventQueue(me);
 751 
 752             if ((type == XConstants.ButtonRelease) &&
 753                 ((mouseButtonClickAllowed & XlibUtil.getButtonMask(lbutton)) != 0) ) // No up-button in the drag-state
 754             {
 755                 postEventToEventQueue(me = new MouseEvent(getEventSource(),
 756                                                      MouseEvent.MOUSE_CLICKED,
 757                                                      jWhen,
 758                                                      modifiers,
 759                                                      x, y,
 760                                                      xbe.get_x_root(),
 761                                                      xbe.get_y_root(),
 762                                                      clickCount,
 763                                                      false, button));
 764             }
 765 
 766         }
 767         else {
 768             if (xev.get_type() == XConstants.ButtonPress) {
 769                 MouseWheelEvent mwe = new MouseWheelEvent(getEventSource(),MouseEvent.MOUSE_WHEEL, jWhen,
 770                                                           modifiers,
 771                                                           x, y,
 772                                                           xbe.get_x_root(),
 773                                                           xbe.get_y_root(),
 774                                                           1,false,MouseWheelEvent.WHEEL_UNIT_SCROLL,
 775                                                           3,button==4 ?  -1 : 1);
 776                 postEventToEventQueue(mwe);
 777             }
 778         }
 779 
 780         /* Update the state variable AFTER the CLICKED event post. */
 781         if (type == XConstants.ButtonRelease) {
 782             /* Exclude this mouse button from allowed list.*/
 783             mouseButtonClickAllowed &= ~ XlibUtil.getButtonMask(lbutton);
 784         }
 785     }
 786 
 787     public void handleMotionNotify(XEvent xev) {
 788         super.handleMotionNotify(xev);
 789         XMotionEvent xme = xev.get_xmotion();


 820         int x = xme.get_x();
 821         int y = xme.get_y();
 822         XWindow lastWindow = (lastWindowRef != null) ? ((XWindow)lastWindowRef.get()):(null);
 823 
 824         if (!(lastWindow == this &&
 825               (xme.get_time() - lastTime) < XToolkit.getMultiClickTime()  &&
 826               (Math.abs(lastX - x) < AWT_MULTICLICK_SMUDGE &&
 827                Math.abs(lastY - y) < AWT_MULTICLICK_SMUDGE))) {
 828           clickCount = 0;
 829           lastWindowRef = null;
 830           mouseButtonClickAllowed = 0;
 831           lastTime = 0;
 832           lastX = 0;
 833           lastY = 0;
 834         }
 835 
 836         long jWhen = XToolkit.nowMillisUTC_offset(xme.get_time());
 837         int modifiers = getModifiers(xme.get_state(), 0, 0);
 838         boolean popupTrigger = false;
 839 
 840         Component source = getEventSource();
 841 
 842         if (xme.get_window() != window) {
 843             Point localXY = toLocal(xme.get_x_root(), xme.get_y_root());
 844             x = localXY.x;
 845             y = localXY.y;
 846         }
 847         /* Fix for 5039416.
 848          * According to canvas.c we shouldn't post any MouseEvent if mouse is dragging and clickCount!=0.
 849          */
 850         if ((isDragging && clickCount == 0) || !isDragging) {
 851             MouseEvent mme = new MouseEvent(source, mouseEventType, jWhen,
 852                                             modifiers, x, y, xme.get_x_root(), xme.get_y_root(),
 853                                             clickCount, popupTrigger, MouseEvent.NOBUTTON);
 854             postEventToEventQueue(mme);
 855         }
 856     }
 857 
 858 
 859     // REMIND: need to implement looking for disabled events
 860     public native boolean x11inputMethodLookupString(long event, long [] keysymArray);


1094         int unicodeKey = 0;
1095         keysym[0] = XConstants.NoSymbol;
1096 
1097         if (keyEventLog.isLoggable(PlatformLogger.Level.FINE)) {
1098             logIncomingKeyEvent( ev );
1099         }
1100         if ( //TODO check if there's an active input method instance
1101              // without calling a native method. Is it necessary though?
1102             haveCurrentX11InputMethodInstance()) {
1103             if (x11inputMethodLookupString(ev.pData, keysym)) {
1104                 if (keyEventLog.isLoggable(PlatformLogger.Level.FINE)) {
1105                     keyEventLog.fine("--XWindow.java XIM did process event; return; dec keysym processed:"+(keysym[0])+
1106                                    "; hex keysym processed:"+Long.toHexString(keysym[0])
1107                                    );
1108                 }
1109                 return;
1110             }else {
1111                 unicodeKey = keysymToUnicode( keysym[0], ev.get_state() );
1112                 if (keyEventLog.isLoggable(PlatformLogger.Level.FINE)) {
1113                     keyEventLog.fine("--XWindow.java XIM did NOT process event, hex keysym:"+Long.toHexString(keysym[0])+"\n"+
1114                                      "                                         unicode key:"+Integer.toHexString(unicodeKey));
1115                 }
1116             }
1117         }else  {
1118             // No input method instance found. For example, there's a Java Input Method.
1119             // Produce do-it-yourself keysym and perhaps unicode character.
1120             keysym[0] = xkeycodeToKeysym(ev);
1121             unicodeKey = keysymToUnicode( keysym[0], ev.get_state() );
1122             if (keyEventLog.isLoggable(PlatformLogger.Level.FINE)) {
1123                 keyEventLog.fine("--XWindow.java XIM is absent;             hex keysym:"+Long.toHexString(keysym[0])+"\n"+
1124                                  "                                         unicode key:"+Integer.toHexString(unicodeKey));
1125             }
1126         }
1127         // Keysym should be converted to Unicode, if possible and necessary,
1128         // and Java KeyEvent keycode should be calculated.
1129         // For press we should post pressed & typed Java events.
1130         //
1131         // Press event might be not processed to this time because
1132         //  (1) either XIM could not handle it or
1133         //  (2) it was Latin 1:1 mapping.
1134         //
1135         // Preserve modifiers to get Java key code for dead keys
1136         boolean isDeadKey = isDeadKey(keysym[0]);
1137         XKeysym.Keysym2JavaKeycode jkc = isDeadKey ? XKeysym.getJavaKeycode(keysym[0])
1138                 : XKeysym.getJavaKeycode(ev);
1139         if( jkc == null ) {
1140             jkc = new XKeysym.Keysym2JavaKeycode(java.awt.event.KeyEvent.VK_UNDEFINED, java.awt.event.KeyEvent.KEY_LOCATION_UNKNOWN);
1141         }
1142 
1143         // Take the first keysym from a keysym array associated with the XKeyevent
1144         // and convert it to Unicode. Then, even if a Java keycode for the keystroke


1449                 return pt;
1450             } finally {
1451                 XToolkit.awtUnlock();
1452             }
1453         }
1454     }
1455 
1456 
1457     static void setBData(KeyEvent e, byte[] data) {
1458         AWTAccessor.getAWTEventAccessor().setBData(e, data);
1459     }
1460 
1461     public void postKeyEvent(int id, long when, int keyCode, int keyChar,
1462         int keyLocation, int state, long event, int eventSize, long rawCode,
1463         int unicodeFromPrimaryKeysym, int extendedKeyCode)
1464 
1465     {
1466         long jWhen = XToolkit.nowMillisUTC_offset(when);
1467         int modifiers = getModifiers(state, 0, keyCode);
1468 
1469         KeyEvent ke = new KeyEvent(getEventSource(), id, jWhen,
1470                                    modifiers, keyCode, (char)keyChar, keyLocation);
1471         if (event != 0) {
1472             byte[] data = Native.toBytes(event, eventSize);
1473             setBData(ke, data);
1474         }
1475 
1476         AWTAccessor.KeyEventAccessor kea = AWTAccessor.getKeyEventAccessor();
1477         kea.setRawCode(ke, rawCode);
1478         kea.setPrimaryLevelUnicode(ke, (long)unicodeFromPrimaryKeysym);
1479         kea.setExtendedKeyCode(ke, (long)extendedKeyCode);
1480         postEventToEventQueue(ke);
1481     }
1482 
1483     static native int getAWTKeyCodeForKeySym(int keysym);
1484     static native int getKeySymForAWTKeyCode(int keycode);
1485 
1486     /* These two methods are actually applicable to toplevel windows only.
1487      * However, the functionality is required by both the XWindowPeer and
1488      * XWarningWindow, both of which have the XWindow as a common ancestor.
1489      * See XWM.setMotifDecor() for details.