1 /*
2 * Copyright (c) 2003, 2007, 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
1016
1017 /*
1018 * fix for 6239938 : Choice drop-down does not disappear when it loses
1019 * focus, on XToolkit
1020 * We are able to handle all _Key_ events received by Choice when
1021 * it is in opened state without sending it to EventQueue.
1022 * If Choice is in closed state we should behave like before: send
1023 * all events to EventQueue.
1024 * To be compatible with Motif we should handle all KeyEvents in
1025 * Choice if it is opened. KeyEvents should be sent into Java if Choice is not opened.
1026 */
1027 boolean prePostEvent(final AWTEvent e) {
1028 if (unfurled){
1029 // fix for 6253211: PIT: MouseWheel events not triggered for Choice drop down in XAWT
1030 if (e instanceof MouseWheelEvent){
1031 return super.prePostEvent(e);
1032 }
1033 //fix 6252982: PIT: Keyboard FocusTraversal not working when choice's drop-down is visible, on XToolkit
1034 if (e instanceof KeyEvent){
1035 // notify XWindow that this event had been already handled and no need to post it again
1036 EventQueue.invokeLater(new Runnable() {
1037 public void run() {
1038 if(target.isFocusable() &&
1039 getParentTopLevel().isFocusableWindow() )
1040 {
1041 handleJavaKeyEvent((KeyEvent)e);
1042 }
1043 }
1044 });
1045 return true;
1046 } else {
1047 if (e instanceof MouseEvent){
1048 // Fix for 6240046 : REG:Choice's Drop-down does not disappear when clicking somewhere, after popup menu is disposed
1049 // if user presses Right Mouse Button on opened (unfurled)
1050 // Choice then we mustn't open a popup menu. We could filter
1051 // Mouse Events and handle them in XChoicePeer if Choice
1052 // currently in opened state.
1053 MouseEvent me = (MouseEvent)e;
1054 int eventId = e.getID();
1055 // fix 6251983: PIT: MouseDragged events not triggered
1056 // fix 6251988: PIT: Choice consumes MouseReleased, MouseClicked events when clicking it with left button,
1057 if ((unfurledChoice.isMouseEventInside(me) ||
1058 (!firstPress && eventId == MouseEvent.MOUSE_DRAGGED)))
1059 {
1060 return handleMouseEventByChoice(me);
1061 }
1062 // MouseMoved events should be fired in Choice's comp if it's not opened
1063 // Shouldn't generate Moved Events. CR : 6251995
1064 if (eventId == MouseEvent.MOUSE_MOVED){
1066 }
1067 //fix for 6272965: PIT: Choice triggers MousePressed when pressing mouse outside comp while drop-down is active, XTkt
1068 if ( !firstPress && !( isMouseEventInChoice(me) ||
1069 unfurledChoice.isMouseEventInside(me)) &&
1070 ( eventId == MouseEvent.MOUSE_PRESSED ||
1071 eventId == MouseEvent.MOUSE_RELEASED ||
1072 eventId == MouseEvent.MOUSE_CLICKED )
1073 )
1074 {
1075 return handleMouseEventByChoice(me);
1076 }
1077 }
1078 }//else KeyEvent
1079 }//if unfurled
1080 return super.prePostEvent(e);
1081 }
1082
1083 //convenient method
1084 //do not generate this kind of Events
1085 public boolean handleMouseEventByChoice(final MouseEvent me){
1086 EventQueue.invokeLater(new Runnable() {
1087 public void run() {
1088 handleJavaMouseEvent(me);
1089 }
1090 });
1091 return true;
1092 }
1093
1094 /* Returns true if the MouseEvent coords
1095 * are inside of the Choice itself (it doesnt's depends on
1096 * if this choice opened or not).
1097 */
1098 private boolean isMouseEventInChoice(MouseEvent e) {
1099 int x = e.getX();
1100 int y = e.getY();
1101 Rectangle choiceRect = getBounds();
1102
1103 if (x < 0 || x > choiceRect.width ||
1104 y < 0 || y > choiceRect.height)
1105 {
1106 return false;
1107 }
1108 return true;
1109 }
1110 }
|
1 /*
2 * Copyright (c) 2003, 2013, 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
1016
1017 /*
1018 * fix for 6239938 : Choice drop-down does not disappear when it loses
1019 * focus, on XToolkit
1020 * We are able to handle all _Key_ events received by Choice when
1021 * it is in opened state without sending it to EventQueue.
1022 * If Choice is in closed state we should behave like before: send
1023 * all events to EventQueue.
1024 * To be compatible with Motif we should handle all KeyEvents in
1025 * Choice if it is opened. KeyEvents should be sent into Java if Choice is not opened.
1026 */
1027 boolean prePostEvent(final AWTEvent e) {
1028 if (unfurled){
1029 // fix for 6253211: PIT: MouseWheel events not triggered for Choice drop down in XAWT
1030 if (e instanceof MouseWheelEvent){
1031 return super.prePostEvent(e);
1032 }
1033 //fix 6252982: PIT: Keyboard FocusTraversal not working when choice's drop-down is visible, on XToolkit
1034 if (e instanceof KeyEvent){
1035 // notify XWindow that this event had been already handled and no need to post it again
1036 InvocationEvent ev = new InvocationEvent(target, new Runnable() {
1037 public void run() {
1038 if(target.isFocusable() &&
1039 getParentTopLevel().isFocusableWindow() )
1040 {
1041 handleJavaKeyEvent((KeyEvent)e);
1042 }
1043 }
1044 });
1045 postEvent(ev);
1046
1047 return true;
1048 } else {
1049 if (e instanceof MouseEvent){
1050 // Fix for 6240046 : REG:Choice's Drop-down does not disappear when clicking somewhere, after popup menu is disposed
1051 // if user presses Right Mouse Button on opened (unfurled)
1052 // Choice then we mustn't open a popup menu. We could filter
1053 // Mouse Events and handle them in XChoicePeer if Choice
1054 // currently in opened state.
1055 MouseEvent me = (MouseEvent)e;
1056 int eventId = e.getID();
1057 // fix 6251983: PIT: MouseDragged events not triggered
1058 // fix 6251988: PIT: Choice consumes MouseReleased, MouseClicked events when clicking it with left button,
1059 if ((unfurledChoice.isMouseEventInside(me) ||
1060 (!firstPress && eventId == MouseEvent.MOUSE_DRAGGED)))
1061 {
1062 return handleMouseEventByChoice(me);
1063 }
1064 // MouseMoved events should be fired in Choice's comp if it's not opened
1065 // Shouldn't generate Moved Events. CR : 6251995
1066 if (eventId == MouseEvent.MOUSE_MOVED){
1068 }
1069 //fix for 6272965: PIT: Choice triggers MousePressed when pressing mouse outside comp while drop-down is active, XTkt
1070 if ( !firstPress && !( isMouseEventInChoice(me) ||
1071 unfurledChoice.isMouseEventInside(me)) &&
1072 ( eventId == MouseEvent.MOUSE_PRESSED ||
1073 eventId == MouseEvent.MOUSE_RELEASED ||
1074 eventId == MouseEvent.MOUSE_CLICKED )
1075 )
1076 {
1077 return handleMouseEventByChoice(me);
1078 }
1079 }
1080 }//else KeyEvent
1081 }//if unfurled
1082 return super.prePostEvent(e);
1083 }
1084
1085 //convenient method
1086 //do not generate this kind of Events
1087 public boolean handleMouseEventByChoice(final MouseEvent me){
1088 InvocationEvent ev = new InvocationEvent(target, new Runnable() {
1089 public void run() {
1090 handleJavaMouseEvent(me);
1091 }
1092 });
1093 postEvent(ev);
1094
1095 return true;
1096 }
1097
1098 /* Returns true if the MouseEvent coords
1099 * are inside of the Choice itself (it doesnt's depends on
1100 * if this choice opened or not).
1101 */
1102 private boolean isMouseEventInChoice(MouseEvent e) {
1103 int x = e.getX();
1104 int y = e.getY();
1105 Rectangle choiceRect = getBounds();
1106
1107 if (x < 0 || x > choiceRect.width ||
1108 y < 0 || y > choiceRect.height)
1109 {
1110 return false;
1111 }
1112 return true;
1113 }
1114 }
|