2002/08/24 22:50:45
[org.ibex.core.git] / src / org / xwt / plat / POSIX.cc
index 52d86d9..919fc58 100644 (file)
@@ -467,44 +467,6 @@ void org::xwt::plat::POSIX$X11Surface::dispatchEvent(gnu::gcj::RawData* ev) {
     } else if (e->type == FocusIn) { Focused(1);
     } else if (e->type == FocusOut) { Focused(0);
     
-    } else if (e->type == SelectionNotify) {
-        XSelectionEvent* xsn = (XSelectionEvent*)(e);
-        if (xsn->property == None) org::xwt::plat::POSIX::clipboard = JvNewStringLatin1("", 0);
-        else {
-            Atom returntype;
-            int returnformat;
-            unsigned long numitems;
-            unsigned char* ret;
-            unsigned long bytes_after;
-            XGetWindowProperty(display, xsn->requestor, xsn->property, 0, 4096,
-                               True, AnyPropertyType, &returntype, &returnformat,
-                               &numitems, &bytes_after, &ret);
-            org::xwt::plat::POSIX::clipboard =
-                (returntype == None ? JvNewStringLatin1("", 0) : JvNewStringLatin1((char*)ret, strlen((char*)ret)));
-        }
-        org::xwt::plat::POSIX::waiting_for_selection_event->release();
-        
-    } else if (e->type == SelectionRequest) {
-        XSelectionRequestEvent* xsr = (XSelectionRequestEvent*)(e);
-        XSelectionEvent xsn;
-        xsn.type = SelectionNotify;
-        xsn.serial = xsr->serial;
-        xsn.send_event = True;
-        xsn.display = display;
-        xsn.requestor = xsr->requestor;
-        xsn.selection = xsr->selection;
-        xsn.target = xsr->target;
-        xsn.property = xsr->property;
-        xsn.time = xsr->time;
-        
-        int len = min(1024, JvGetStringUTFLength(org::xwt::plat::POSIX::clipboard));
-        char buf[len + 1];
-        JvGetStringUTFRegion(org::xwt::plat::POSIX::clipboard, 0, len, buf);
-        buf[len] = '\0';
-        
-        XChangeProperty(display, xsr->requestor, xsr->property, xsr->target, 8, PropModeReplace, (unsigned char*)buf, len + 1);
-        XSendEvent(display, xsr->requestor, True, 0, (XEvent*)(&xsn));
-        
     } else if (e->type == KeyPress || e->type == KeyRelease) {
         XKeyEvent *xbe = (XKeyEvent*)(e);
         
@@ -578,7 +540,6 @@ void org::xwt::plat::POSIX$X11Surface::dispatchEvent(gnu::gcj::RawData* ev) {
             case XK_Shift_R: s = "shift"; break;
             case XK_Control_L: s = "control"; break;
             case XK_Control_R: s = "control"; break;
-            case XK_Caps_Lock: s = "caps_lock"; break;
             case XK_Meta_L: s = "alt"; break;
             case XK_Meta_R: s = "alt"; break;
             case XK_Alt_L: s = "alt"; break;
@@ -587,8 +548,9 @@ void org::xwt::plat::POSIX$X11Surface::dispatchEvent(gnu::gcj::RawData* ev) {
             }
         }
         
-        if (e->type == KeyPress) KeyPressed(JvNewStringLatin1(s));
-        if (e->type == KeyRelease) KeyReleased(JvNewStringLatin1(s));
+        jstring s2 = JvNewStringLatin1(s);
+        if (e->type == KeyPress) KeyPressed((xbe->state & LockMask) ? s2->toUpperCase() : s2);
+        if (e->type == KeyRelease) KeyReleased(s2);
         
     } else if (e->type == ButtonPress) {
         XButtonEvent* xbe = (XButtonEvent*)(e);
@@ -686,13 +648,58 @@ void org::xwt::plat::POSIX::spawnChildProcess(JArray<jstring>* cmd) {
     }
 }
 
+static void dispatchSelectionEvent(XEvent* e) {
+    if (e->type == SelectionNotify) {
+        XSelectionEvent* xsn = (XSelectionEvent*)(e);
+        if (xsn->property == None) org::xwt::plat::POSIX::clipboard = JvNewStringLatin1("", 0);
+        else {
+            Atom returntype;
+            int returnformat;
+            unsigned long numitems;
+            unsigned char* ret;
+            unsigned long bytes_after;
+            XGetWindowProperty(display, xsn->requestor, xsn->property, 0, 4096,
+                               True, AnyPropertyType, &returntype, &returnformat,
+                               &numitems, &bytes_after, &ret);
+            org::xwt::plat::POSIX::clipboard =
+                (returntype == None ? JvNewStringLatin1("", 0) : JvNewStringLatin1((char*)ret, strlen((char*)ret)));
+        }
+        org::xwt::plat::POSIX::waiting_for_selection_event->release();
+        
+    } else if (e->type == SelectionRequest) {
+        XSelectionRequestEvent* xsr = (XSelectionRequestEvent*)(e);
+        XSelectionEvent xsn;
+        xsn.type = SelectionNotify;
+        xsn.serial = xsr->serial;
+        xsn.send_event = True;
+        xsn.display = display;
+        xsn.requestor = xsr->requestor;
+        xsn.selection = xsr->selection;
+        xsn.target = xsr->target;
+        xsn.property = xsr->property;
+        xsn.time = xsr->time;
+        
+        int len = min(1024, JvGetStringUTFLength(org::xwt::plat::POSIX::clipboard));
+        char buf[len + 1];
+        JvGetStringUTFRegion(org::xwt::plat::POSIX::clipboard, 0, len, buf);
+        buf[len] = '\0';
+        
+        XChangeProperty(display, xsr->requestor, xsr->property, xsr->target, 8, PropModeReplace, (unsigned char*)buf, len + 1);
+        XSendEvent(display, xsr->requestor, True, 0, (XEvent*)(&xsn));
+    }        
+}
+
 void org::xwt::plat::POSIX::eventThread() {
     XEvent e;
     while(true) {
         XNextEvent(display, &e);
-        org::xwt::plat::POSIX$X11Surface* surface =
-            (org::xwt::plat::POSIX$X11Surface*)windowToSurfaceMap->get(new java::lang::Long(((XAnyEvent*)&e)->window));
-        if (surface != NULL) surface->dispatchEvent((gnu::gcj::RawData*)&e);
+        if (e.type == SelectionNotify || e.type == SelectionRequest) {
+            dispatchSelectionEvent(&e);
+        } else {
+            org::xwt::plat::POSIX$X11Surface* surface =
+                (org::xwt::plat::POSIX$X11Surface*)windowToSurfaceMap->get(new java::lang::Long(((XAnyEvent*)&e)->window));
+            if (surface != NULL) surface->dispatchEvent((gnu::gcj::RawData*)&e);
+        }
     }
 }