555 Component target = getEventSource();
556 ComponentAccessor compAccessor = AWTAccessor.getComponentAccessor();
557
558 if (!compAccessor.getIgnoreRepaint(target)
559 && compAccessor.getWidth(target) != 0
560 && compAccessor.getHeight(target) != 0)
561 {
562 postPaintEvent(target, x, y, w, h);
563 }
564 }
565
566 public void postPaintEvent(Component target, int x, int y, int w, int h) {
567 PaintEvent event = PaintEventDispatcher.getPaintEventDispatcher().
568 createPaintEvent(target, x, y, w, h);
569 if (event != null) {
570 postEventToEventQueue(event);
571 }
572 }
573
574 static int getModifiers(int state, int button, int keyCode) {
575 int modifiers = 0;
576
577 if (((state & XConstants.ShiftMask) != 0) ^ (keyCode == KeyEvent.VK_SHIFT)) {
578 modifiers |= InputEvent.SHIFT_DOWN_MASK;
579 }
580 if (((state & XConstants.ControlMask) != 0) ^ (keyCode == KeyEvent.VK_CONTROL)) {
581 modifiers |= InputEvent.CTRL_DOWN_MASK;
582 }
583 if (((state & XToolkit.metaMask) != 0) ^ (keyCode == KeyEvent.VK_META)) {
584 modifiers |= InputEvent.META_DOWN_MASK;
585 }
586 if (((state & XToolkit.altMask) != 0) ^ (keyCode == KeyEvent.VK_ALT)) {
587 modifiers |= InputEvent.ALT_DOWN_MASK;
588 }
589 if (((state & XToolkit.modeSwitchMask) != 0) ^ (keyCode == KeyEvent.VK_ALT_GRAPH)) {
590 modifiers |= InputEvent.ALT_GRAPH_DOWN_MASK;
591 }
592 //InputEvent.BUTTON_DOWN_MASK array is starting from BUTTON1_DOWN_MASK on index == 0.
593 // button currently reflects a real button number and starts from 1. (except NOBUTTON which is zero )
594
595 /* this is an attempt to refactor button IDs in : MouseEvent, InputEvent, XlibWrapper and XWindow.*/
596
597 //reflects a button number similar to MouseEvent.BUTTON1, 2, 3 etc.
598 for (int i = 0; i < XConstants.buttons.length; i ++){
599 //modifier should be added if :
600 // 1) current button is now still in PRESSED state (means that user just pressed mouse but not released yet) or
601 // 2) if Xsystem reports that "state" represents that button was just released. This only happens on RELEASE with 1,2,3 buttons.
602 // ONLY one of these conditions should be TRUE to add that modifier.
603 if (((state & XlibUtil.getButtonMask(i + 1)) != 0) != (button == XConstants.buttons[i])){
604 //exclude wheel buttons from adding their numbers as modifiers
605 if (!isWheel(XConstants.buttons[i])) {
606 modifiers |= InputEvent.getMaskForButton(i+1);
607 }
608 }
609 }
610 return modifiers;
611 }
612
613 static boolean isWheel(int button) {
614 // 4 and 5 buttons are usually considered assigned to a first wheel
615 return button == XConstants.buttons[3] || button == XConstants.buttons[4];
616 }
617
618 static int getXModifiers(AWTKeyStroke stroke) {
619 int mods = stroke.getModifiers();
620 int res = 0;
621 if ((mods & (InputEvent.SHIFT_DOWN_MASK | InputEvent.SHIFT_MASK)) != 0) {
622 res |= XConstants.ShiftMask;
623 }
624 if ((mods & (InputEvent.CTRL_DOWN_MASK | InputEvent.CTRL_MASK)) != 0) {
625 res |= XConstants.ControlMask;
698 }
699 lastTime = when;
700
701
702 /*
703 Check for popup trigger !!
704 */
705 popupTrigger = (lbutton == 3);
706 }
707
708 button = XConstants.buttons[lbutton - 1];
709
710 // mapping extra buttons to numbers starting from 4.
711 if ((button > XConstants.buttons[4]) && (!Toolkit.getDefaultToolkit().areExtraMouseButtonsEnabled())){
712 return;
713 }
714
715 if (button > XConstants.buttons[4]){
716 button -= 2;
717 }
718 modifiers = getModifiers(xbe.get_state(),button,0);
719
720 if (!isWheel(lbutton)) {
721 MouseEvent me = new MouseEvent(getEventSource(),
722 type == XConstants.ButtonPress ? MouseEvent.MOUSE_PRESSED : MouseEvent.MOUSE_RELEASED,
723 jWhen,modifiers, x, y,
724 xbe.get_x_root(),
725 xbe.get_y_root(),
726 clickCount,popupTrigger,button);
727
728 postEventToEventQueue(me);
729
730 if ((type == XConstants.ButtonRelease) &&
731 ((mouseButtonClickAllowed & XlibUtil.getButtonMask(lbutton)) != 0) ) // No up-button in the drag-state
732 {
733 postEventToEventQueue(me = new MouseEvent(getEventSource(),
734 MouseEvent.MOUSE_CLICKED,
735 jWhen,
736 modifiers,
737 x, y,
738 xbe.get_x_root(),
739 xbe.get_y_root(),
740 clickCount,
741 false, button));
742 }
743
744 }
745 else {
746 if (xev.get_type() == XConstants.ButtonPress) {
747 MouseWheelEvent mwe = new MouseWheelEvent(getEventSource(),MouseEvent.MOUSE_WHEEL, jWhen,
748 modifiers,
749 x, y,
750 xbe.get_x_root(),
751 xbe.get_y_root(),
752 1,false,MouseWheelEvent.WHEEL_UNIT_SCROLL,
753 3,button==4 ? -1 : 1);
754 postEventToEventQueue(mwe);
755 }
756 }
757
758 /* Update the state variable AFTER the CLICKED event post. */
759 if (type == XConstants.ButtonRelease) {
760 /* Exclude this mouse button from allowed list.*/
761 mouseButtonClickAllowed &= ~ XlibUtil.getButtonMask(lbutton);
762 }
763 }
764
765 public void handleMotionNotify(XEvent xev) {
|
555 Component target = getEventSource();
556 ComponentAccessor compAccessor = AWTAccessor.getComponentAccessor();
557
558 if (!compAccessor.getIgnoreRepaint(target)
559 && compAccessor.getWidth(target) != 0
560 && compAccessor.getHeight(target) != 0)
561 {
562 postPaintEvent(target, x, y, w, h);
563 }
564 }
565
566 public void postPaintEvent(Component target, int x, int y, int w, int h) {
567 PaintEvent event = PaintEventDispatcher.getPaintEventDispatcher().
568 createPaintEvent(target, x, y, w, h);
569 if (event != null) {
570 postEventToEventQueue(event);
571 }
572 }
573
574 static int getModifiers(int state, int button, int keyCode) {
575 return getModifiers(state, button, keyCode, false);
576 }
577
578 static int getWheelModifiers(int state, int button) {
579 return getModifiers(state, button, 0, true);
580 }
581
582 private static int getModifiers(int state, int button, int keyCode, boolean isWheelMouse) {
583 int modifiers = 0;
584
585 if (((state & XConstants.ShiftMask) != 0) ^ (keyCode == KeyEvent.VK_SHIFT)) {
586 modifiers |= InputEvent.SHIFT_DOWN_MASK;
587 }
588 if (((state & XConstants.ControlMask) != 0) ^ (keyCode == KeyEvent.VK_CONTROL)) {
589 modifiers |= InputEvent.CTRL_DOWN_MASK;
590 }
591 if (((state & XToolkit.metaMask) != 0) ^ (keyCode == KeyEvent.VK_META)) {
592 modifiers |= InputEvent.META_DOWN_MASK;
593 }
594 if (((state & XToolkit.altMask) != 0) ^ (keyCode == KeyEvent.VK_ALT)) {
595 modifiers |= InputEvent.ALT_DOWN_MASK;
596 }
597 if (((state & XToolkit.modeSwitchMask) != 0) ^ (keyCode == KeyEvent.VK_ALT_GRAPH)) {
598 modifiers |= InputEvent.ALT_GRAPH_DOWN_MASK;
599 }
600 //InputEvent.BUTTON_DOWN_MASK array is starting from BUTTON1_DOWN_MASK on index == 0.
601 // button currently reflects a real button number and starts from 1. (except NOBUTTON which is zero )
602
603 /* this is an attempt to refactor button IDs in : MouseEvent, InputEvent, XlibWrapper and XWindow.*/
604
605 //reflects a button number similar to MouseEvent.BUTTON1, 2, 3 etc.
606 for (int i = 0; i < XConstants.buttons.length; i ++){
607 //modifier should be added if :
608 // 1) current button is now still in PRESSED state (means that user just pressed mouse but not released yet) or
609 // 2) if Xsystem reports that "state" represents that button was just released. This only happens on RELEASE with 1,2,3 buttons.
610 // ONLY one of these conditions should be TRUE to add that modifier.
611 if (((state & XlibUtil.getButtonMask(i + 1)) != 0) != (button == XConstants.buttons[i])){
612 //exclude wheel buttons from adding their numbers as modifiers
613 if (!isWheelMouse || !isWheel(XConstants.buttons[i])) {
614 modifiers |= InputEvent.getMaskForButton(i+1);
615 }
616 }
617 }
618 return modifiers;
619 }
620
621 static boolean isWheel(int button) {
622 // 4 and 5 buttons are usually considered assigned to a first wheel
623 return button == XConstants.buttons[3] || button == XConstants.buttons[4];
624 }
625
626 static int getXModifiers(AWTKeyStroke stroke) {
627 int mods = stroke.getModifiers();
628 int res = 0;
629 if ((mods & (InputEvent.SHIFT_DOWN_MASK | InputEvent.SHIFT_MASK)) != 0) {
630 res |= XConstants.ShiftMask;
631 }
632 if ((mods & (InputEvent.CTRL_DOWN_MASK | InputEvent.CTRL_MASK)) != 0) {
633 res |= XConstants.ControlMask;
706 }
707 lastTime = when;
708
709
710 /*
711 Check for popup trigger !!
712 */
713 popupTrigger = (lbutton == 3);
714 }
715
716 button = XConstants.buttons[lbutton - 1];
717
718 // mapping extra buttons to numbers starting from 4.
719 if ((button > XConstants.buttons[4]) && (!Toolkit.getDefaultToolkit().areExtraMouseButtonsEnabled())){
720 return;
721 }
722
723 if (button > XConstants.buttons[4]){
724 button -= 2;
725 }
726
727 if (!isWheel(lbutton)) {
728 modifiers = getModifiers(xbe.get_state(), button, 0);
729 MouseEvent me = new MouseEvent(getEventSource(),
730 type == XConstants.ButtonPress ? MouseEvent.MOUSE_PRESSED : MouseEvent.MOUSE_RELEASED,
731 jWhen,modifiers, x, y,
732 xbe.get_x_root(),
733 xbe.get_y_root(),
734 clickCount,popupTrigger,button);
735
736 postEventToEventQueue(me);
737
738 if ((type == XConstants.ButtonRelease) &&
739 ((mouseButtonClickAllowed & XlibUtil.getButtonMask(lbutton)) != 0) ) // No up-button in the drag-state
740 {
741 postEventToEventQueue(me = new MouseEvent(getEventSource(),
742 MouseEvent.MOUSE_CLICKED,
743 jWhen,
744 modifiers,
745 x, y,
746 xbe.get_x_root(),
747 xbe.get_y_root(),
748 clickCount,
749 false, button));
750 }
751
752 }
753 else {
754 modifiers = getWheelModifiers(xbe.get_state(), button);
755 if (xev.get_type() == XConstants.ButtonPress) {
756 MouseWheelEvent mwe = new MouseWheelEvent(getEventSource(),MouseEvent.MOUSE_WHEEL, jWhen,
757 modifiers,
758 x, y,
759 xbe.get_x_root(),
760 xbe.get_y_root(),
761 1,false,MouseWheelEvent.WHEEL_UNIT_SCROLL,
762 3,button==4 ? -1 : 1);
763 postEventToEventQueue(mwe);
764 }
765 }
766
767 /* Update the state variable AFTER the CLICKED event post. */
768 if (type == XConstants.ButtonRelease) {
769 /* Exclude this mouse button from allowed list.*/
770 mouseButtonClickAllowed &= ~ XlibUtil.getButtonMask(lbutton);
771 }
772 }
773
774 public void handleMotionNotify(XEvent xev) {
|