Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteve Northover2001-09-11 18:32:43 +0000
committerSteve Northover2001-09-11 18:32:43 +0000
commit2e59efd73e90759ed48636b0f81f17f1c8202cfa (patch)
tree39700d23c09461736984dc90199929751f976e6a /bundles
parent79227b5a49c00b963ad602edd42ff8b19e607168 (diff)
downloadeclipse.platform.swt-2e59efd73e90759ed48636b0f81f17f1c8202cfa.tar.gz
eclipse.platform.swt-2e59efd73e90759ed48636b0f81f17f1c8202cfa.tar.xz
eclipse.platform.swt-2e59efd73e90759ed48636b0f81f17f1c8202cfa.zip
key event fixes
Diffstat (limited to 'bundles')
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Control.java113
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/MenuItem.java8
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Text.java18
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ToolItem.java2
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Widget.java38
5 files changed, 80 insertions, 99 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Control.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Control.java
index f7ba81dfc2..1373ae5d74 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Control.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Control.java
@@ -1165,7 +1165,11 @@ int processIMEFocusOut () {
int processKeyDown (int callData) {
XKeyEvent xEvent = new XKeyEvent ();
OS.memmove (xEvent, callData, XKeyEvent.sizeof);
- sendKeyEvent (SWT.KeyDown, xEvent);
+ if (xEvent.keycode != 0) {
+ sendKeyEvent (SWT.KeyDown, xEvent);
+ } else {
+ sendIMEKeyEvent (SWT.KeyDown, xEvent);
+ }
return 0;
}
int processKeyUp (int callData) {
@@ -1183,7 +1187,7 @@ int processMouseDown (int callData) {
display.hideToolTip ();
XButtonEvent xEvent = new XButtonEvent ();
OS.memmove (xEvent, callData, XButtonEvent.sizeof);
- sendMouseEvent (SWT.MouseDown, xEvent.button, xEvent.state, xEvent);
+ sendMouseEvent (SWT.MouseDown, xEvent.button, xEvent);
if (xEvent.button == 2 && hooks (SWT.DragDetect)) {
sendEvent (SWT.DragDetect);
}
@@ -1195,10 +1199,9 @@ int processMouseDown (int callData) {
int lastTime = display.lastTime, eventTime = xEvent.time;
int lastButton = display.lastButton, eventButton = xEvent.button;
if (lastButton == eventButton && lastTime != 0 && Math.abs (lastTime - eventTime) <= clickTime) {
- sendMouseEvent (SWT.MouseDoubleClick, eventButton, xEvent.state, xEvent);
+ sendMouseEvent (SWT.MouseDoubleClick, eventButton, xEvent);
}
- if (eventTime == 0) eventTime = 1;
- display.lastTime = eventTime;
+ display.lastTime = eventTime == 0 ? 1 : eventTime;
display.lastButton = eventButton;
return 0;
}
@@ -1218,7 +1221,7 @@ int processMouseMove (int callData) {
display.addMouseHoverTimeOut (handle);
XMotionEvent xEvent = new XMotionEvent ();
OS.memmove (xEvent, callData, XMotionEvent.sizeof);
- sendMouseEvent (SWT.MouseMove, 0, xEvent.state, xEvent);
+ sendMouseEvent (SWT.MouseMove, 0, xEvent);
return 0;
}
int processMouseExit (int callData) {
@@ -1249,7 +1252,7 @@ int processMouseUp (int callData) {
display.hideToolTip ();
XButtonEvent xEvent = new XButtonEvent ();
OS.memmove (xEvent, callData, XButtonEvent.sizeof);
- sendMouseEvent (SWT.MouseUp, xEvent.button, xEvent.state, xEvent);
+ sendMouseEvent (SWT.MouseUp, xEvent.button, xEvent);
return 0;
}
int processPaint (int callData) {
@@ -1647,52 +1650,21 @@ void sendHelpEvent (int callData) {
control = control.parent;
}
}
-byte [] sendKeyEvent (int type, XKeyEvent xEvent) {
-
- /* Look up the keysym and character(s) */
- byte [] buffer;
- boolean isVirtual = false;
- int [] keysym = new int [1];
- if (xEvent.keycode != 0) {
- buffer = new byte [1];
- isVirtual = OS.XLookupString (xEvent, buffer, buffer.length, keysym, null) == 0;
- } else {
- /*
- * Bug in Motif. On Linux only, XmImMbLookupString() does not return
- * XBufferOverflow as the status if the buffer is too small. The fix is
- * to pass a bigger buffer.
- */
- buffer = new byte [512];
- int [] status = new int [1];
- int size = OS.XmImMbLookupString (handle, xEvent, buffer, buffer.length, keysym, status);
- if (status [0] == OS.XBufferOverflow) {
- buffer = new byte [size];
- size = OS.XmImMbLookupString (handle, xEvent, buffer, size, keysym, status);
- }
- if (size == 0) return null;
- }
-
+byte [] sendIMEKeyEvent (int type, XKeyEvent xEvent) {
/*
- * Bug in MOTIF. On Solaris only, XK_F11 and XK_F12 are not
- * translated correctly by XLookupString(). They are mapped
- * to 0x1005FF10 and 0x1005FF11 respectively. The fix is to
- * look for these values explicitly and correct them.
+ * Bug in Motif. On Linux only, XmImMbLookupString () does not return
+ * XBufferOverflow as the status if the buffer is too small. The fix
+ * is to pass a large buffer.
*/
- if (OS.IsSunOS) {
- if ((keysym [0] == 0x1005FF10) || (keysym [0] == 0x1005FF11)) {
- if (keysym [0] == 0x1005FF10) keysym [0] = OS.XK_F11;
- if (keysym [0] == 0x1005FF11) keysym [0] = OS.XK_F12;
- }
+ byte [] buffer = new byte [512];
+ int [] status = new int [1], unused = new int [1];
+ int length = OS.XmImMbLookupString (handle, xEvent, buffer, buffer.length, unused, status);
+ if (status [0] == OS.XBufferOverflow) {
+ buffer = new byte [length];
+ length = OS.XmImMbLookupString (handle, xEvent, buffer, length, unused, status);
}
+ if (length == 0) return null;
- /*
- * Bug in MOTIF. On Solaris only, their is garbage in the
- * high 16-bits for Keysyms such as XK_Down. Since Keysyms
- * must be 16-bits to fit into a Character, mask away the
- * high 16-bits on all platforms.
- */
- keysym [0] &= 0xFFFF;
-
/* Convert from MBCS to UNICODE and send the event */
/* Use the character encoding for the default locale */
char [] result = Converter.mbcsToWcs (null, buffer);
@@ -1702,30 +1674,24 @@ byte [] sendKeyEvent (int type, XKeyEvent xEvent) {
Event event = new Event ();
event.time = xEvent.time;
event.character = result [index];
- if (isVirtual) event.keyCode = Display.translateKey (keysym [0]);
- if ((xEvent.state & OS.Mod1Mask) != 0) event.stateMask |= SWT.ALT;
- if ((xEvent.state & OS.ShiftMask) != 0) event.stateMask |= SWT.SHIFT;
- if ((xEvent.state & OS.ControlMask) != 0) event.stateMask |= SWT.CONTROL;
- if ((xEvent.state & OS.Button1Mask) != 0) event.stateMask |= SWT.BUTTON1;
- if ((xEvent.state & OS.Button2Mask) != 0) event.stateMask |= SWT.BUTTON2;
- if ((xEvent.state & OS.Button3Mask) != 0) event.stateMask |= SWT.BUTTON3;
+ setInputState (event, xEvent);
postEvent (type, event);
index++;
}
-
return buffer;
}
-void sendMouseEvent (int type, int button, int mask, XWindowEvent xEvent) {
+void sendKeyEvent (int type, XKeyEvent xEvent) {
+ Event event = new Event ();
+ event.time = xEvent.time;
+ setKeyState (event, xEvent);
+ postEvent (type, event);
+}
+void sendMouseEvent (int type, int button, XInputEvent xEvent) {
Event event = new Event ();
event.time = xEvent.time;
event.button = button;
event.x = xEvent.x; event.y = xEvent.y;
- if ((mask & OS.Mod1Mask) != 0) event.stateMask |= SWT.ALT;
- if ((mask & OS.ShiftMask) != 0) event.stateMask |= SWT.SHIFT;
- if ((mask & OS.ControlMask) != 0) event.stateMask |= SWT.CONTROL;
- if ((mask & OS.Button1Mask) != 0) event.stateMask |= SWT.BUTTON1;
- if ((mask & OS.Button2Mask) != 0) event.stateMask |= SWT.BUTTON2;
- if ((mask & OS.Button3Mask) != 0) event.stateMask |= SWT.BUTTON3;
+ setInputState (event, xEvent);
postEvent (type, event);
}
/**
@@ -2032,24 +1998,6 @@ void setGrabCursor (int cursor) {
XDisplay xChangeActivePointerGrab: eventMask cursor: aCursor time: CurrentTime.
*/
}
-void setKeyState (Event event, XKeyEvent xEvent) {
- if (xEvent.keycode != 0) {
- event.time = xEvent.time;
- byte [] buffer1 = new byte [1];
- int [] keysym = new int [1];
- if (OS.XLookupString (xEvent, buffer1, buffer1.length, keysym, null) == 0) {
- event.keyCode = Display.translateKey (keysym [0] & 0xFFFF);
- } else {
- event.character = (char) buffer1 [0];
- }
- if ((xEvent.state & OS.Mod1Mask) != 0) event.stateMask |= SWT.ALT;
- if ((xEvent.state & OS.ShiftMask) != 0) event.stateMask |= SWT.SHIFT;
- if ((xEvent.state & OS.ControlMask) != 0) event.stateMask |= SWT.CONTROL;
- if ((xEvent.state & OS.Button1Mask) != 0) event.stateMask |= SWT.BUTTON1;
- if ((xEvent.state & OS.Button2Mask) != 0) event.stateMask |= SWT.BUTTON2;
- if ((xEvent.state & OS.Button3Mask) != 0) event.stateMask |= SWT.BUTTON3;
- }
-}
/**
* Sets the layout data associated with the receiver to the argument.
*
@@ -2428,6 +2376,7 @@ boolean translateTraversal (int key, XKeyEvent xEvent) {
Event event = new Event();
event.doit = doit;
event.detail = detail;
+ event.time = xEvent.time;
setKeyState (event, xEvent);
sendEvent (SWT.Traverse, event);
doit = event.doit;
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/MenuItem.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/MenuItem.java
index 94e897b889..6581d10281 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/MenuItem.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/MenuItem.java
@@ -499,12 +499,8 @@ int processSelection (int callData) {
case OS.ButtonRelease:
case OS.KeyPress:
case OS.KeyRelease:
- if ((xEvent.state & OS.Mod1Mask) != 0) event.stateMask |= SWT.ALT;
- if ((xEvent.state & OS.ShiftMask) != 0) event.stateMask |= SWT.SHIFT;
- if ((xEvent.state & OS.ControlMask) != 0) event.stateMask |= SWT.CONTROL;
- if ((xEvent.state & OS.Button1Mask) != 0) event.stateMask |= SWT.BUTTON1;
- if ((xEvent.state & OS.Button2Mask) != 0) event.stateMask |= SWT.BUTTON2;
- if ((xEvent.state & OS.Button3Mask) != 0) event.stateMask |= SWT.BUTTON3;
+ setInputState (event, xEvent);
+ break;
}
}
postEvent (SWT.Selection, event);
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Text.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Text.java
index 4e517795a2..aad8525747 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Text.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Text.java
@@ -914,6 +914,7 @@ int processVerify (int callData) {
if (textVerify.event != 0) {
XKeyEvent xEvent = new XKeyEvent ();
OS.memmove (xEvent, textVerify.event, XKeyEvent.sizeof);
+ event.time = xEvent.time;
setKeyState (event, xEvent);
}
event.start = textVerify.startPos;
@@ -1019,22 +1020,20 @@ public void removeVerifyListener (VerifyListener listener) {
if (eventTable == null) return;
eventTable.unhook (SWT.Verify, listener);
}
-byte [] sendKeyEvent (int type, XKeyEvent xEvent) {
- byte [] mbcs = super.sendKeyEvent (type, xEvent);
-
+byte [] sendIMEKeyEvent (int type, XKeyEvent xEvent) {
/*
- * Bug in Motif. On Solaris and Linux, XmImMbLookupString() clears
+ * Bug in Motif. On Solaris and Linux, XmImMbLookupString () clears
* the characters from the IME. This causes tht characters to be
* stolen from the text widget. The fix is to detect that the IME
- * has been cleared and use XmTextInsert() to insert the stolen
+ * has been cleared and use XmTextInsert () to insert the stolen
* characters. This problem does not happen on AIX.
*/
+ byte [] mbcs = super.sendIMEKeyEvent (type, xEvent);
if (mbcs == null || xEvent.keycode != 0) return null;
+ int [] unused = new int [1];
byte [] buffer = new byte [2];
- int [] keysym = new int [1];
- int [] status = new int [1];
- int size = OS.XmImMbLookupString (handle, xEvent, buffer, buffer.length, keysym, status);
- if (size != 0) return null;
+ int length = OS.XmImMbLookupString (handle, xEvent, buffer, buffer.length, unused, unused);
+ if (length != 0) return null;
int [] start = new int [1], end = new int [1];
OS.XmTextGetSelectionPosition (handle, start, end);
if (start [0] == end [0]) {
@@ -1047,7 +1046,6 @@ byte [] sendKeyEvent (int type, XKeyEvent xEvent) {
int position = start [0] + mbcs.length - 1;
OS.XmTextSetInsertionPosition (handle, position);
display.setWarnings (warnings);
-
return mbcs;
}
/**
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ToolItem.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ToolItem.java
index b61b578b9f..0b4aba90e7 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ToolItem.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ToolItem.java
@@ -786,7 +786,7 @@ int processMouseMove (int callData) {
*/
// OS.memmove (callData, xEvent, XButtonEvent.sizeof);
// parent.processMouseMove (callData);
- parent.sendMouseEvent (SWT.MouseMove, 0, xEvent.state, xEvent);
+ parent.sendMouseEvent (SWT.MouseMove, 0, xEvent);
return 0;
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Widget.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Widget.java
index 9f73c729b5..6a4772825f 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Widget.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Widget.java
@@ -715,6 +715,44 @@ void sendEvent (int eventType) {
if (eventTable == null) return;
sendEvent (eventType, new Event ());
}
+void setInputState (Event event, XInputEvent xEvent) {
+ if ((xEvent.state & OS.Mod1Mask) != 0) event.stateMask |= SWT.ALT;
+ if ((xEvent.state & OS.ShiftMask) != 0) event.stateMask |= SWT.SHIFT;
+ if ((xEvent.state & OS.ControlMask) != 0) event.stateMask |= SWT.CONTROL;
+ if ((xEvent.state & OS.Button1Mask) != 0) event.stateMask |= SWT.BUTTON1;
+ if ((xEvent.state & OS.Button2Mask) != 0) event.stateMask |= SWT.BUTTON2;
+ if ((xEvent.state & OS.Button3Mask) != 0) event.stateMask |= SWT.BUTTON3;
+}
+void setKeyState (Event event, XKeyEvent xEvent) {
+ if (xEvent.keycode != 0) {
+ byte [] buffer1 = new byte [1];
+ int [] keysym = new int [1];
+ if (OS.XLookupString (xEvent, buffer1, buffer1.length, keysym, null) == 0) {
+ /*
+ * Bug in MOTIF. On Solaris only, XK_F11 and XK_F12 are not
+ * translated correctly by XLookupString(). They are mapped
+ * to 0x1005FF10 and 0x1005FF11 respectively. The fix is to
+ * look for these values explicitly and correct them.
+ */
+ if (OS.IsSunOS) {
+ if ((keysym [0] == 0x1005FF10) || (keysym [0] == 0x1005FF11)) {
+ if (keysym [0] == 0x1005FF10) keysym [0] = OS.XK_F11;
+ if (keysym [0] == 0x1005FF11) keysym [0] = OS.XK_F12;
+ }
+ }
+ /*
+ * Bug in MOTIF. On Solaris only, their is garbage in the
+ * high 16-bits for Keysyms such as XK_Down. Since Keysyms
+ * must be 16-bits to fit into a Character, mask away the
+ * high 16-bits on all platforms.
+ */
+ event.keyCode = Display.translateKey (keysym [0] & 0xFFFF);
+ } else {
+ event.character = (char) buffer1 [0];
+ }
+ }
+ setInputState (event, xEvent);
+}
void sendEvent (int eventType, Event event) {
if (eventTable == null) return;
event.type = eventType;

Back to the top