harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mloe...@apache.org
Subject svn commit: r440748 [10/25] - in /incubator/harmony/enhanced/classlib/trunk/modules: accessibility/src/main/java/javax/accessibility/ awt/ awt/make/ awt/src/main/java/common/java/awt/ awt/src/main/java/common/java/awt/datatransfer/ awt/src/main/java/co...
Date Wed, 06 Sep 2006 16:06:30 GMT
Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/nativebridge/linux/X11.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/nativebridge/linux/X11.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/nativebridge/linux/X11.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/nativebridge/linux/X11.java Wed Sep  6 09:06:15 2006
@@ -23,7 +23,7 @@
 import org.apache.harmony.awt.nativebridge.*;
 
 /**
- * This file has been generated by a program.
+ * This file is based on X11 header and has been generated by the nativebridge tool.
  *
  *
  */
@@ -1404,6 +1404,20 @@
         return new XWMHints(addr);
     }
 
+    public final int XGetRGBColormaps(long param_0, long param_1, PointerPointer param_2, Int32Pointer param_3, long param_4) {
+        long tmp_0 = param_2 == null ? 0 : param_2.longLockPointer();
+        long tmp_1 = param_3 == null ? 0 : param_3.longLockPointer();
+        int tmp_ret = XGetRGBColormaps(param_0, param_1, tmp_0, tmp_1, param_4);
+        if (param_2 != null) {
+            param_2.unlock();
+        }
+        if (param_3 != null) {
+            param_3.unlock();
+        }
+        return tmp_ret;
+    }
+    public final native int XGetRGBColormaps(long param_0, long param_1, long param_2, long param_3, long param_4);
+
     public final XVisualInfo XGetVisualInfo(long param_0, long param_1, XVisualInfo param_2, Int32Pointer param_3) {
         long tmp_0 = param_2 == null ? 0 : param_2.longLockPointer();
         long tmp_1 = param_3 == null ? 0 : param_3.longLockPointer();
@@ -4223,6 +4237,8 @@
     }
     public final native int XPutImage(long param_0, long param_1, long param_2, long param_3, int param_4, int param_5, int param_6, int param_7, int param_8, int param_9);
 
+    public final native int XmuLookupStandardColormap(long dpy, int screen, long visualid, int depth, long property, int replace, int retain);
+
     public final int XStoreName(long param_0, long param_1, String param_2) {
         Int8Pointer _param_2 = null == param_2? null :  nb.createInt8Pointer(param_2, false);
         long tmp_0 = _param_2 == null ? 0 : _param_2.longLockPointer();
@@ -4243,6 +4259,97 @@
     }
     public final native int XStoreName(long param_0, long param_1, long param_2);
 
+    public final native long XAllocStandardColormap();
+
+
+    public static class XStandardColormap extends CommonStructWrapper {
+
+        public static final int sizeof = NativeBridge.is64 ? 80 : 40;
+
+        XStandardColormap(boolean direct) {
+            super(sizeof, direct);
+        }
+        XStandardColormap(VoidPointer base) {
+            super(base);
+        }
+        XStandardColormap(long addr) {
+            super(addr);
+        }
+        public final void set_colormap(long val) {
+            byteBase.setCLong(0, val);
+        }
+        public final long get_colormap() {
+            return byteBase.getCLong(0);
+        }
+        public final void set_red_max(long val) {
+            byteBase.setCLong(NativeBridge.is64 ? 8 : 4, val);
+        }
+        public final long get_red_max() {
+            return byteBase.getCLong(NativeBridge.is64 ? 8 : 4);
+        }
+        public final void set_red_mult(long val) {
+            byteBase.setCLong(NativeBridge.is64 ? 16 : 8, val);
+        }
+        public final long get_red_mult() {
+            return byteBase.getCLong(NativeBridge.is64 ? 16 : 8);
+        }
+        public final void set_green_max(long val) {
+            byteBase.setCLong(NativeBridge.is64 ? 24 : 12, val);
+        }
+        public final long get_green_max() {
+            return byteBase.getCLong(NativeBridge.is64 ? 24 : 12);
+        }
+        public final void set_green_mult(long val) {
+            byteBase.setCLong(NativeBridge.is64 ? 32 : 16, val);
+        }
+        public final long get_green_mult() {
+            return byteBase.getCLong(NativeBridge.is64 ? 32 : 16);
+        }
+        public final void set_blue_max(long val) {
+            byteBase.setCLong(NativeBridge.is64 ? 40 : 20, val);
+        }
+        public final long get_blue_max() {
+            return byteBase.getCLong(NativeBridge.is64 ? 40 : 20);
+        }
+        public final void set_blue_mult(long val) {
+            byteBase.setCLong(NativeBridge.is64 ? 48 : 24, val);
+        }
+        public final long get_blue_mult() {
+            return byteBase.getCLong(NativeBridge.is64 ? 48 : 24);
+        }
+        public final void set_base_pixel(long val) {
+            byteBase.setCLong(NativeBridge.is64 ? 56 : 28, val);
+        }
+        public final long get_base_pixel() {
+            return byteBase.getCLong(NativeBridge.is64 ? 56 : 28);
+        }
+        public final void set_visualid(long val) {
+            byteBase.setCLong(NativeBridge.is64 ? 64 : 32, val);
+        }
+        public final long get_visualid() {
+            return byteBase.getCLong(NativeBridge.is64 ? 64 : 32);
+        }
+        public final void set_killid(long val) {
+            byteBase.setCLong(NativeBridge.is64 ? 72 : 36, val);
+        }
+        public final long get_killid() {
+            return byteBase.getCLong(NativeBridge.is64 ? 72 : 36);
+        }
+        public int size() {
+            return sizeof;
+        }
+    }
+
+    public final XStandardColormap createXStandardColormap(boolean direct) {
+        return new XStandardColormap(direct);
+    }
+    public final XStandardColormap createXStandardColormap(VoidPointer base) {
+        return new XStandardColormap(base);
+    }
+    public final XStandardColormap createXStandardColormap(long addr) {
+        return new XStandardColormap(addr);
+    }
+
     public final int XSetClipRectangles(long param_0, long param_1, int param_2, int param_3, X11.XRectangle param_4, int param_5, int param_6) {
         long tmp_0 = param_4 == null ? 0 : param_4.longLockPointer();
         int tmp_ret = XSetClipRectangles(param_0, param_1, param_2, param_3, tmp_0, param_5, param_6);
@@ -4987,6 +5094,16 @@
     public final native int XFreeGC(long param_0, long param_1);
 
     public final native int XBitmapPad(long param_0);
+
+    public final long XCreateColormap(long param_0, long param_1, X11.Visual param_2, int param_3) {
+        long tmp_0 = param_2 == null ? 0 : param_2.longLockPointer();
+        long tmp_ret = XCreateColormap(param_0, param_1, tmp_0, param_3);
+        if (param_2 != null) {
+            param_2.unlock();
+        }
+        return tmp_ret;
+    }
+    public final native long XCreateColormap(long param_0, long param_1, long param_2, int param_3);
 
     public final int XGetPointerMapping(long param_0, Int8Pointer param_1, int param_2) {
         long tmp_0 = param_1 == null ? 0 : param_1.longLockPointer();

Added: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/wtk/linux/LinuxEvent.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/wtk/linux/LinuxEvent.java?view=auto&rev=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/wtk/linux/LinuxEvent.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/wtk/linux/LinuxEvent.java Wed Sep  6 09:06:15 2006
@@ -0,0 +1,632 @@
+/*
+ *  Copyright 2005 - 2006 The Apache Software Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+/**
+ * @author Michael Danilov
+ * @version $Revision$
+ */
+package org.apache.harmony.awt.wtk.linux;
+
+import java.awt.Frame;
+import java.awt.Insets;
+import java.awt.Point;
+import java.awt.Rectangle;
+import java.awt.event.FocusEvent;
+import java.awt.event.InputEvent;
+import java.awt.event.KeyEvent;
+import java.awt.event.MouseEvent;
+import java.awt.event.PaintEvent;
+import java.awt.event.WindowEvent;
+
+import org.apache.harmony.awt.gl.MultiRectArea;
+import org.apache.harmony.awt.nativebridge.CLongPointer;
+import org.apache.harmony.awt.nativebridge.Int32Pointer;
+import org.apache.harmony.awt.nativebridge.NativeBridge;
+import org.apache.harmony.awt.nativebridge.PointerPointer;
+import org.apache.harmony.awt.nativebridge.linux.X11;
+import org.apache.harmony.awt.nativebridge.linux.X11Defs;
+import org.apache.harmony.awt.wtk.NativeEvent;
+
+/**
+ * Information about X11 events can be found at http://www.xfree86.org/current/manindex3.html
+ */
+
+public final class LinuxEvent extends NativeEvent {
+    private static final X11 x11 = X11.getInstance();
+    private static final NativeBridge bridge = NativeBridge.getInstance();
+    private final LinuxWindowFactory factory;
+
+    private static final int MOUSE_BUTTONS_MASK =
+        (X11Defs.Button1Mask | X11Defs.Button2Mask | X11Defs.Button3Mask);
+
+    private static long utcOffset = X11Defs.CurrentTime;
+
+    private final LinuxEventQueue nativeQueue;
+    /** Clip area of paint event */
+    private MultiRectArea clipRects;
+
+    /** X event type */
+    private int nativeEventId;
+    /** Invisible auxlitary window for receiving service events */
+    private final long javaWindowId;
+
+    private Insets insets = new Insets(0, 0, 0, 0);
+
+
+    public static long getUTCOffset() {
+        return utcOffset;
+    }
+
+    LinuxEvent(LinuxWindowFactory factory, 
+               LinuxEventQueue nativeQueue,
+                          X11.XEvent event) {
+        this.javaWindowId = factory.getJavaWindow();
+        this.nativeQueue = nativeQueue;
+        this.factory = factory;
+        setEvent(event);
+    }
+
+    public MultiRectArea getClipRects() {
+        return new MultiRectArea(clipRects);
+    }
+
+    public Rectangle getClipBounds() {
+        return clipRects.getBounds();
+    }
+
+    public Insets getInsets() {
+        return insets;
+    }
+
+    public boolean getTrigger() {
+        return ((eventId == MouseEvent.MOUSE_PRESSED)
+                && (mouseButton == MouseEvent.BUTTON3));
+    }
+
+    private void setEvent(X11.XEvent event) {
+
+        windowId = event.get_xany().get_window();
+        nativeEventId = event.get_type();
+        eventId = ID_PLATFORM;
+
+        if (windowId == javaWindowId) {
+            return;
+        }
+        if (!factory.validWindowId(windowId) &&
+                   windowId != factory.getRootWindow()) {
+            return;
+        }
+
+        switch (nativeEventId) {
+        case X11Defs.KeyPress:
+        case X11Defs.KeyRelease:
+            X11.XKeyEvent keyEvent = event.get_xkey();
+            validateUTCOffset(keyEvent.get_time());
+            processKeyEvent(keyEvent);
+            break;
+        case X11Defs.ButtonPress:
+        case X11Defs.ButtonRelease:
+            X11.XButtonEvent buttonEvent = event.get_xbutton();
+            validateUTCOffset(buttonEvent.get_time());
+            processButtonEvent(buttonEvent);
+            break;
+        case X11Defs.MotionNotify:
+            X11.XMotionEvent motionEvent = event.get_xmotion();
+            validateUTCOffset(motionEvent.get_time());
+            processMotionEvent(motionEvent);
+            break;
+        case X11Defs.FocusIn:
+        case X11Defs.FocusOut:
+            X11.XFocusChangeEvent focusChangeEvent = event.get_xfocus();
+            processFocusChangeEvent(focusChangeEvent);
+            break;
+        case X11Defs.Expose:
+            X11.XExposeEvent exposeEvent = event.get_xexpose();
+            processExposeEvent(exposeEvent);
+            break;
+        case X11Defs.ConfigureNotify:
+            X11.XConfigureEvent configureEvent = event.get_xconfigure();
+            processConfigureEvent(configureEvent);
+            break;
+        case X11Defs.DestroyNotify:
+            X11.XDestroyWindowEvent destroyWindowEvent = event.get_xdestroywindow();
+            processDestroyWindowEvent(destroyWindowEvent);
+            break;
+        case X11Defs.ClientMessage:
+            X11.XClientMessageEvent clientMessageEvent = event.get_xclient();
+            processClientMessageEvent(clientMessageEvent);
+            break;
+        case X11Defs.PropertyNotify:
+            X11.XPropertyEvent propertyEvent = event.get_xproperty();
+            validateUTCOffset(propertyEvent.get_time());
+            processPropertyEvent(propertyEvent);
+            break;
+        case X11Defs.EnterNotify:
+        case X11Defs.LeaveNotify:
+            X11.XCrossingEvent crossingEvent = event.get_xcrossing();
+            validateUTCOffset(crossingEvent.get_time());
+            processCrossingEvent(crossingEvent);
+            break;
+        case X11Defs.ReparentNotify:
+            X11.XReparentEvent reparentEvent = event.get_xreparent();
+            processReparentEvent(reparentEvent);
+            break;
+        default:
+            eventId = ID_PLATFORM;
+         /*//Other events may be useful in future
+        case X11Defs.UnmapNotify:
+            X11.XUnmapEvent unmapEvent = x11.new XUnmapEvent(event
+                    .get_xunmap_ptr());
+            processUnmapEvent(unmapEvent);
+            break;
+        case X11Defs.MapNotify:
+            X11.XMapEvent mapEvent = x11.new XMapEvent(event.get_xmap_ptr());
+            processMapEvent(mapEvent);
+            break;
+         case X11Defs.GraphicsExpose:
+         X11.XGraphicsExposeEvent graphicsExposeEvent = x11.new XGraphicsExposeEvent(event.get_xgraphicsexpose());
+         processGraphicsExposeEvent(graphicsExposeEvent);
+         break;
+         case X11Defs.NoExpose:
+         X11.XNoExposeEvent noExposeEvent = x11.new XNoExposeEvent(event.get_xnoexpose());
+         processNoExposeEventEvent(noExposeEvent);
+         break;
+         case X11Defs.VisibilityNotify:
+         X11.XVisibilityEvent visibilityEvent = x11.new XVisibilityEvent(event.get_xvisibility());
+         processVisibilityEvent(visibilityEvent);
+         break;
+         case X11Defs.MapRequest:
+         X11.XMapRequestEvent mapRequestEvent = x11.new XMapRequestEvent(event.get_xmaprequest());
+         processMapRequestEvent(mapRequestEvent);
+         break;
+         case X11Defs.ConfigureRequest:
+         X11.XConfigureRequestEvent configureRequestEvent = x11.new XConfigureRequestEvent(event.get_xconfigurerequest());
+         processConfigureRequestEvent(configureRequestEvent);
+         break;
+         case X11Defs.GravityNotify:
+         X11.XGravityEvent gravityEvent = x11.new XGravityEvent(event.get_xgravity());
+         processGravityEvent(gravityEvent);
+         break;
+         case X11Defs.ResizeRequest:
+         X11.XResizeRequestEvent resizeRequestEvent = x11.new XResizeRequestEvent(event.get_xresizerequest());
+         processResizeRequestEvent(resizeRequestEvent);
+         break;
+         case X11Defs.CirculateNotify:
+         X11.XCirculateEvent circulateEvent = x11.new XCirculateEvent(event.get_xcirculate());
+         processCirculateEvent(circulateEvent);
+         break;
+         case X11Defs.CirculateRequest:
+         X11.XCirculateRequestEvent circulateRequestEvent = x11.new XCirculateRequestEvent(event.get_xcirculaterequest());
+         processCirculateRequestEvent(circulateRequestEvent);
+         break;
+         case X11Defs.SelectionClear:
+         X11.XSelectionClearEvent selectionClearEvent = x11.new XSelectionClearEvent(event.get_xselectionclear());
+         processSelectionClearEvent(selectionClearEvent);
+         break;
+         case X11Defs.SelectionRequest:
+         X11.XSelectionRequestEvent selectionRequestEvent = x11.new XSelectionRequestEvent(event.get_xselectionrequest());
+         processSelectionRequestEvent(selectionRequestEvent);
+         break;
+         case X11Defs.SelectionNotify:
+         X11.XSelectionEvent selectionEvent = x11.new XSelectionEvent(event.get_xselection());
+         processSelectionEvent(selectionEvent);
+         break;
+         case X11Defs.ColormapNotify:
+         X11.XColormapEvent colormapEvent = x11.new XColormapEvent(event.get_xcolormap());
+         processColormapEvent(colormapEvent);
+         break;
+         case X11Defs.MappingNotify:
+         X11.XMappingEvent mappingEvent = x11.new XMappingEvent(event.get_xmapping());
+         processMappingEvent(mappingEvent);
+         break;
+         case X11Defs.KeymapNotify:
+         X11.XKeymapEvent keymapEvent = x11.new XKeymapEvent(event.get_xkeymap());
+         processKeymapEvent(keymapEvent);
+         break;
+         default:
+         //>X11Defs.LASTEvent => undefined event
+         //<2 => error or reply (XErrorEvent xerror);*/
+        }
+    }
+
+    private void processReparentEvent(X11.XReparentEvent reparentEvent) {
+        processInsetsChange(null);
+    }
+
+    private void processKeyEvent(X11.XKeyEvent event) {
+        eventId = (nativeEventId == X11Defs.KeyPress) ?
+                KeyEvent.KEY_PRESSED :
+                KeyEvent.KEY_RELEASED;
+
+        time = event.get_time() + utcOffset;
+        translateModifiers(event.get_state());
+
+        keyInfo = KeyCodeTranslator.translateEvent(event);
+        forwardToContent();
+    }
+
+    private void processButtonEvent(X11.XButtonEvent event) {
+        int button = event.get_button();
+
+        if (button > X11Defs.Button3) {
+            eventId = MouseEvent.MOUSE_WHEEL;
+            wheelRotation = (button == X11Defs.Button4) ? -1 : 1;
+        } else {
+            eventId = (nativeEventId == X11Defs.ButtonPress) ?
+                    MouseEvent.MOUSE_PRESSED : MouseEvent.MOUSE_RELEASED;
+            mouseButton = button - X11Defs.Button1 + MouseEvent.BUTTON1;
+        }
+
+        time = event.get_time() + utcOffset;
+        localPos = new Point(event.get_x(), event.get_y());
+        screenPos = new Point(event.get_x_root(), event.get_y_root());
+        translateButtonModifiers(event.get_state());
+        if (!updateGrabState(event)) {
+            eventId = ID_MOUSE_GRAB_CANCELED;
+        }
+    }
+
+    private void processMotionEvent(X11.XMotionEvent event) {
+        LinuxWindow win = (LinuxWindow) factory.getWindowById(windowId);
+
+        localPos = new Point(event.get_x(), event.get_y());
+        if (!localPos.equals(win.queryPointer())) {
+            return;
+        }
+        screenPos = new Point(event.get_x_root(), event.get_y_root());
+        if ((event.get_state() & MOUSE_BUTTONS_MASK) > 0) {
+            eventId = MouseEvent.MOUSE_DRAGGED;
+        } else {
+            eventId = MouseEvent.MOUSE_MOVED;
+        }
+        time = event.get_time() + utcOffset;
+        translateModifiers(event.get_state());
+    }
+
+    private void processCrossingEvent(X11.XCrossingEvent event) {
+        eventId = (nativeEventId == X11Defs.EnterNotify) ?
+                MouseEvent.MOUSE_ENTERED : MouseEvent.MOUSE_EXITED;
+        localPos = new Point(event.get_x(), event.get_y());
+        screenPos = new Point(event.get_x_root(), event.get_y_root());
+        time = event.get_time() + utcOffset;
+        translateModifiers(event.get_state());
+    }
+
+    private void processFocusChangeEvent(X11.XFocusChangeEvent event) {
+        int detail = event.get_detail();
+        //ignore events sent to windows other than source or destination
+        if (detail == X11Defs.NotifyNonlinearVirtual
+                || detail == X11Defs.NotifyVirtual) {
+            return;
+        }
+        boolean gainedFocus = (nativeEventId == X11Defs.FocusIn);
+        WindowManager wm = factory.wm;
+        long focusedWindow = wm.getFocusedWindow();
+        long serverFocusedWindow = wm.getInputFocus();
+        long newFocusedWindow = gainedFocus ? event.get_window() :
+            serverFocusedWindow;
+        forwardToContent();
+        eventId = gainedFocus ? FocusEvent.FOCUS_GAINED
+                : FocusEvent.FOCUS_LOST;
+
+        otherWindowId = gainedFocus ? focusedWindow : newFocusedWindow;
+        //have to check if this window belongs to our Java application
+        if (!factory.validWindowId(otherWindowId)) {
+            otherWindowId = 0;
+            //if lost focus to window in some other app, clear focusedWindow:
+            if (!gainedFocus) {
+                wm.setFocusedWindow(0);
+            }
+        } else {
+            otherWindowId = getContentId(otherWindowId);
+        }
+        if (gainedFocus) {
+            wm.setFocusedWindow(newFocusedWindow);
+        }
+    }
+
+    private void processExposeEvent(X11.XExposeEvent event) {
+        MultiRectArea clip = nativeQueue.getAccumulatedClip(windowId);
+
+        clip.add(new Rectangle(event.get_x(), event.get_y(),
+                event.get_width(), event.get_height()));
+
+        if (event.get_count() != 0) {
+            eventId = ID_PLATFORM;
+        } else {
+            eventId = PaintEvent.PAINT;
+
+            clipRects = clip;
+            nativeQueue.resetAccumulatedClip(windowId);
+        }
+    }
+
+    private void processConfigureEvent(X11.XConfigureEvent event) {
+        LinuxWindow win = (LinuxWindow)factory.getWindowById(windowId);
+        boolean child = win.isChild();
+        boolean isSynthetic = event.get_send_event() != 0;
+
+        windowRect = new Rectangle(event.get_x(), event.get_y(),
+                event.get_width(), event.get_height());
+
+        //in real configure events new position is reported relative to parent
+        //so have to translate it for top-level(managed by WM)windows
+        //to get root-related coords
+        if (!child && !isSynthetic) {
+            Int32Pointer x = bridge.createInt32Pointer(1, false);
+            Int32Pointer y = bridge.createInt32Pointer(1, false);
+            CLongPointer childWindow = bridge.createCLongPointer(1, false);
+
+            long parentId = win.getParentID();
+            x11.XTranslateCoordinates(win.getDisplay(), parentId,
+                                      factory.getRootWindow(),
+                                      windowRect.x, windowRect.y,
+                                      x, y, childWindow);
+            windowRect.setLocation(x.get(0), y.get(0));
+        }
+
+        boolean isContent = (win instanceof ContentWindow);
+
+        if (!isContent && child && !windowRect.equals(win.getBounds())) {
+            eventId = ID_PLATFORM;
+            return;
+        }
+
+        eventId = ID_BOUNDS_CHANGED;
+        Rectangle oldRect = win.onBoundsChange(windowRect);
+        if (isContent) {
+            ContentWindow content = (ContentWindow) win;
+            windowRect.setLocation(content.getBounds().getLocation());
+        }
+        if (windowRect.equals(oldRect)) {
+            eventId = /*insetsChanged ? ID_INSETS_CHANGED : */ID_PLATFORM;
+        }
+
+        LinuxWindow content = win.getContentWindow();
+        if (content != null) {
+            if (win.resized) {
+                Insets ins = win.getInsets();
+                int dw = ins.left + ins.right;
+                int dh = ins.top + ins.bottom;
+                x11.XResizeWindow(win.getDisplay(), content.getId(),
+                        windowRect.width + dw, windowRect.height + dh);
+                x11.XFlush(win.getDisplay());
+            }
+            if (isSynthetic && win.moved) {
+                windowId = content.getId();
+                windowRect.setBounds(content.getBounds());
+            }
+
+        }
+    }
+
+    private void processDestroyWindowEvent(X11.XDestroyWindowEvent event) {
+        eventId = WindowEvent.WINDOW_CLOSED;
+        factory.onWindowDispose(windowId);
+    }
+
+    private void processPropertyEvent(X11.XPropertyEvent event) {
+        long atom = event.get_atom();
+        if (atom == factory.wm.NET_WM_STATE) {
+            processWindowStateEvent();
+        }  else if (atom == factory.wm.NET_FRAME_EXTENTS ||
+                atom == factory.wm.KDE_NET_WM_FRAME_STRUT) {
+            processFrameExtentsEvent(atom);
+        }
+    }
+
+    /**
+     * @param property - could be NET_FRAME_EXTENTS or KDE_NET_WM_FRAME_STRUT
+     */
+    private void processFrameExtentsEvent(long property) {
+        insets = factory.wm.getNativeInsets(windowId, property);
+    }
+
+    /**
+     *
+     */
+    private void processInsetsChange(Insets newInsets) {
+        LinuxWindow win = (LinuxWindow) factory.getWindowById(windowId);
+        if ((win == null) || win.isChild() || win.isUndecorated()) {
+            return;
+        }
+        eventId = ID_INSETS_CHANGED;
+
+        if (newInsets != null) {
+            win.setInsets(newInsets);
+        } else {
+            insets = win.updateInsets();
+        }
+        forwardToContent();
+
+    }
+
+    private void processWindowStateEvent() {
+        CLongPointer actualTypeReturn = bridge.createCLongPointer(1, false);
+        Int32Pointer actualFormatReturn = bridge.createInt32Pointer(1, false);
+        CLongPointer nitemsReturn = bridge.createCLongPointer(1, false);
+        CLongPointer bytesAfterReturn = bridge.createCLongPointer(1, false);
+        PointerPointer propReturn = bridge.createPointerPointer(1, false);
+
+        x11.XGetWindowProperty(factory.getDisplay(), windowId,
+                factory.wm.NET_WM_STATE, 0, Integer.MAX_VALUE, X11Defs.FALSE,
+                X11Defs.AnyPropertyType, actualTypeReturn, actualFormatReturn,
+                nitemsReturn, bytesAfterReturn, propReturn);
+
+        int count = (int)nitemsReturn.get(0);
+        if (count == 0) {
+            return;
+        }
+        if (actualFormatReturn.get(0) == 32) {
+            CLongPointer types = bridge.createCLongPointer(propReturn.get(0));
+            deriveNewWindowState(count, types);
+        } else {
+            throw new RuntimeException(
+                "Only 32-bit format is supported for window state operations.");
+        }
+    }
+
+    private void deriveNewWindowState(int typesCount, CLongPointer types) {
+        LinuxWindow win = (LinuxWindow) factory.getWindowById(windowId);
+        int oldState = win.getState();
+        int newState = 0;
+        boolean oldAlwaysOnTop = win.alwaysOnTop;
+        boolean newAlwaysOnTop = false;
+
+        for (int i=0; i<typesCount; i++) {
+            long type = types.get(i);
+            if (type == factory.wm.NET_WM_STATE_MAXIMIZED_HORZ) {
+                newState |= Frame.MAXIMIZED_HORIZ;
+            } else if (type == factory.wm.NET_WM_STATE_MAXIMIZED_VERT) {
+                newState |= Frame.MAXIMIZED_VERT;
+            } else if (type == factory.wm.NET_WM_STATE_HIDDEN) {
+                newState |= Frame.ICONIFIED;
+            } else if (type == factory.wm.NET_WM_STATE_ABOVE) {
+                newAlwaysOnTop = true;
+            }
+        }
+
+        win.setMaximized((newState & Frame.MAXIMIZED_BOTH) == Frame.MAXIMIZED_BOTH);
+        win.setIconified((newState & Frame.ICONIFIED) == Frame.ICONIFIED);
+        if (newState != oldState) {
+            windowState = newState;
+            eventId = WindowEvent.WINDOW_STATE_CHANGED;
+        }
+        if (oldAlwaysOnTop != oldAlwaysOnTop) {
+            win.alwaysOnTop = newAlwaysOnTop;
+        }
+        forwardToContent();
+    }
+
+    private void processClientMessageEvent(X11.XClientMessageEvent event) {
+        if (event.get_message_type() == factory.wm.WM_PROTOCOLS) {
+            CLongPointer data = event.get_l();
+            long protocol = data.get(0);
+            if (protocol == factory.wm.WM_DELETE_WINDOW) {
+                LinuxWindow lw = (LinuxWindow)factory.getWindowById(windowId);
+                LinuxWindow cw = lw.getContentWindow();
+                if (lw.isInputAllowed()) {
+                    eventId = WindowEvent.WINDOW_CLOSING;
+                    if (cw != null) {
+                        // forward closing event to the content window:
+                        windowId = cw.getId();
+                    }
+                }
+            }
+            // TODO: Process other Window Manager's events here
+        }
+    }
+
+    private void translateButtonModifiers(int state) {
+        translateModifiers(state);
+
+        if (mouseButton == MouseEvent.BUTTON1) {
+            modifiers |= InputEvent.BUTTON1_DOWN_MASK;
+        }
+        if (mouseButton == MouseEvent.BUTTON2) {
+            modifiers |= InputEvent.BUTTON2_DOWN_MASK;
+        }
+        if (mouseButton == MouseEvent.BUTTON3) {
+            modifiers |= InputEvent.BUTTON3_DOWN_MASK;
+        }
+    }
+
+    private void translateModifiers(int state) {
+        if ((state & X11Defs.Mod1Mask) > 0) {
+            modifiers |= InputEvent.ALT_DOWN_MASK;
+        }
+        if ((state & X11Defs.Mod5Mask) > 0) {
+            modifiers |= InputEvent.ALT_GRAPH_DOWN_MASK;
+        }
+        if ((state & X11Defs.ControlMask) > 0) {
+            modifiers |= InputEvent.CTRL_DOWN_MASK;
+        }
+        if ((state & X11Defs.ShiftMask) > 0) {
+            modifiers |= InputEvent.SHIFT_DOWN_MASK;
+        }
+        if ((state & X11Defs.Button1Mask) > 0) {
+            modifiers |= InputEvent.BUTTON1_DOWN_MASK;
+        }
+        if ((state & X11Defs.Button2Mask) > 0) {
+            modifiers |= InputEvent.BUTTON2_DOWN_MASK;
+        }
+        if ((state & X11Defs.Button3Mask) > 0) {
+            modifiers |= InputEvent.BUTTON3_DOWN_MASK;
+        }
+    }
+
+    private boolean updateGrabState(X11.XButtonEvent event) {
+        int mouseState = (event.get_state() & MOUSE_BUTTONS_MASK);
+
+        switch (event.get_type()) {
+        case X11Defs.ButtonPress:
+            // Only one mouse button is pressed
+            if (mouseState == X11Defs.Button1Mask ||
+                    mouseState == X11Defs.Button2Mask ||
+                    mouseState == X11Defs.Button3Mask) {
+
+                if (!LinuxWindow.startAutoGrab(event.get_window(), event.get_x(), event.get_y())) {
+                    return false;
+                }
+            }
+            break;
+        case X11Defs.ButtonRelease:
+            // All mouse buttons were actually released
+            if (mouseState == 0) {
+                LinuxWindow.endAutoGrab();
+            }
+            break;
+        }
+
+        return true;
+    }
+
+    private void validateUTCOffset(long time) {
+        if (utcOffset == X11Defs.CurrentTime) {
+            utcOffset = System.currentTimeMillis() - time;
+        }
+    }
+
+    public String getCompositionString() {
+        return new String();
+    }
+
+    public int getCompCursorPos() {
+        return 0;
+    }
+
+    private long getContentId(long winId) {
+        if (factory.validWindowId(winId)) {
+            LinuxWindow win = (LinuxWindow) factory
+                    .getWindowById(winId);
+            LinuxWindow content = win.getContentWindow();
+            if (content != null) {
+                long contentId = content.getId();
+                if (factory.validWindowId(contentId)) {
+                    return contentId;
+                }
+            }
+        }
+        return winId;
+    }
+
+    private void forwardToContent() {
+        windowId = getContentId(windowId);
+    }
+    
+       public String toString() {
+               return "window=0x" + Long.toHexString(windowId) + ", event=" + eventId;
+       }
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/wtk/linux/LinuxEventQueue.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/wtk/linux/LinuxEventQueue.java?view=auto&rev=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/wtk/linux/LinuxEventQueue.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/wtk/linux/LinuxEventQueue.java Wed Sep  6 09:06:15 2006
@@ -0,0 +1,183 @@
+/*
+ *  Copyright 2005 - 2006 The Apache Software Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+/** 
+ * @author Pavel Dolgov
+ * @version $Revision$
+ */
+package org.apache.harmony.awt.wtk.linux;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+
+import org.apache.harmony.awt.gl.MultiRectArea;
+import org.apache.harmony.awt.nativebridge.CLongPointer;
+import org.apache.harmony.awt.nativebridge.linux.X11;
+import org.apache.harmony.awt.nativebridge.linux.X11Defs;
+import org.apache.harmony.awt.wtk.NativeEvent;
+import org.apache.harmony.awt.wtk.NativeEventQueue;
+import org.apache.harmony.misc.accessors.ObjectAccessor;
+import org.apache.harmony.misc.accessors.AccessorFactory;
+
+public final class LinuxEventQueue extends NativeEventQueue {
+    
+    public interface Preprocessor {
+        public boolean preprocess(X11.XEvent event);
+    }
+
+    private static final X11 x11 = X11.getInstance();
+    private static final ObjectAccessor objAccessor = 
+            AccessorFactory.getObjectAccessor();
+
+    final LinuxWindowFactory factory;
+    final long display;
+    
+    private final long performTaskAtom;
+
+    private final LinkedList preprocessors = new LinkedList();
+    private final X11.XEvent curEvent;
+    /** Pending areas to be painted: Window ID (long) --&gt; MultiRectArea */
+    private final HashMap accumulatedClipRegions = new HashMap();
+
+    LinuxEventQueue(LinuxWindowFactory factory) {
+        this.factory = factory;
+        display = factory.getDisplay();
+        curEvent = x11.createXEvent(false);
+        performTaskAtom = x11.XInternAtom(display, 
+                "org.apache.harmony.awt.wtk.perform_task", 0);
+    }
+    
+    public boolean waitEvent() {
+        do {
+            x11.XNextEvent(display, curEvent);
+        } while (preprocessEvent(curEvent));
+
+        return true;
+    }
+
+    public void awake() {
+        X11.XEvent event = x11.createXEvent(false);
+
+        event.set_type(X11Defs.MapNotify);
+        event.get_xany().set_window(getJavaWindow());
+        x11.XSendEvent(display, getJavaWindow(), 0, X11Defs.StructureNotifyMask, event);
+        x11.XFlush(display);
+    }
+
+    public long getJavaWindow() {
+        return factory.getJavaWindow();
+    }
+
+    public void dispatchEvent() {
+        enqueue(curEvent);
+    }
+    
+    public void addPreprocessor(Preprocessor preprocessor) {
+        preprocessors.add(preprocessor);
+    }
+    
+    private void enqueue(X11.XEvent xevent) {
+        LinuxEvent event = new LinuxEvent(factory, this, xevent);
+        int eventId = event.getEventId();
+        if (eventId != NativeEvent.ID_PLATFORM) {
+            addEvent(event);
+        }
+    }
+
+    private boolean preprocessEvent(X11.XEvent event) {
+        for (Iterator i = preprocessors.iterator(); i.hasNext(); ) {
+            if (((Preprocessor) i.next()).preprocess(event)) {
+                return true;
+            }
+        }
+        if (event.get_type() == X11Defs.ClientMessage) {
+            return preprocessClientEvent(event.get_xclient());
+        }
+        return false;
+    }
+
+    MultiRectArea getAccumulatedClip(long windowId) {
+        Long id = new Long(windowId);
+        MultiRectArea clip = (MultiRectArea)accumulatedClipRegions.get(id);
+        if (clip == null) {
+            clip = new MultiRectArea();
+            accumulatedClipRegions.put(id, clip);
+        }
+        return clip;
+    }
+
+    void resetAccumulatedClip(long windowId) {
+        accumulatedClipRegions.remove(new Long(windowId));
+    }
+
+    public void performTask(Task task) {
+        X11.XEvent e = createPerformTaskEvent(task, true);
+        synchronized (task) {
+            x11.XSendEvent(display, getJavaWindow(), 0, 0, e);
+            x11.XFlush(display);
+            try {
+               task.wait();
+            } catch (InterruptedException ex) {
+                throw new RuntimeException(ex);
+            }
+        }
+    }
+    
+    public void performLater(Task task) {
+        X11.XEvent e = createPerformTaskEvent(task, true);
+        x11.XSendEvent(display, getJavaWindow(), 0, 0, e);
+        x11.XFlush(display);
+    }
+    
+    X11.XEvent createPerformTaskEvent(Task task, boolean wait) {
+        X11.XEvent e = x11.createXEvent(false);
+        long ref = objAccessor.getGlobalReference(task);
+        e.set_type(X11Defs.ClientMessage);
+        X11.XClientMessageEvent xclient = e.get_xclient();
+        xclient.set_message_type(performTaskAtom);
+        CLongPointer data = xclient.get_l();
+        data.set(0, (ref & 0xFFFFFFFF));
+        data.set(1, (ref >> 32));
+        data.set(2, wait ? 1 : 0);
+        return e;
+    }
+
+    private boolean preprocessClientEvent(X11.XClientMessageEvent xclient) {
+        if (xclient.get_message_type() == performTaskAtom) {
+            performTask(xclient);
+            return true;
+        } 
+        return false;
+    }
+
+       private void performTask(X11.XClientMessageEvent xclient) {
+        CLongPointer data = xclient.get_l();
+        
+        long ref = (data.get(0) & 0xFFFFFFFF) | (data.get(1) << 32);
+        boolean wait = (data.get(2) != 0);
+               
+        Task t = (Task)objAccessor.getObjectFromReference(ref);
+        if (wait) {
+            synchronized(t) {
+                t.perform();
+                t.notify();
+            }
+        } else {
+            t.perform();
+        }
+        objAccessor.releaseGlobalReference(ref);
+       }
+}

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/wtk/linux/LinuxSystemProperties.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/wtk/linux/LinuxSystemProperties.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/wtk/linux/LinuxSystemProperties.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/wtk/linux/LinuxSystemProperties.java Wed Sep  6 09:06:15 2006
@@ -21,6 +21,9 @@
 
 import java.awt.Font;
 import java.awt.SystemColor;
+import java.awt.font.TextAttribute;
+import java.awt.im.InputMethodHighlight;
+import java.util.Map;
 
 import org.apache.harmony.awt.wtk.SystemProperties;
 
@@ -42,10 +45,8 @@
         // Grey-blue
         case SystemColor.ACTIVE_CAPTION:
             return 0xff336699;
-        // Grey
         case SystemColor.ACTIVE_CAPTION_BORDER:
             return 0xffcccccc;
-        // White
         case SystemColor.ACTIVE_CAPTION_TEXT:
             return 0xffffffff;
         // Light grey
@@ -81,7 +82,6 @@
         // Almost white
         case SystemColor.INFO:
             return 0xffeeeeee;
-        // Almost black
         case SystemColor.INFO_TEXT:
             return 0xff222222;
         // Light grey
@@ -126,5 +126,26 @@
         // Default font parameters are described 
         // in java.awt.Font specification
         return new Font("Dialog", Font.PLAIN, 12);
+    }
+
+    public void init(Map desktopProperties) {
+    }
+
+    public void mapInputMethodHighlight(InputMethodHighlight highlight, Map map) {
+        TextAttribute key = TextAttribute.SWAP_COLORS;
+        if (highlight.isSelected()) {
+            map.put(key, TextAttribute.SWAP_COLORS_ON);
+            return;
+        }
+        switch(highlight.getState()) {
+        case InputMethodHighlight.RAW_TEXT:
+            key = TextAttribute.WEIGHT;
+            map.put(key, TextAttribute.WEIGHT_BOLD);
+            break;
+        case InputMethodHighlight.CONVERTED_TEXT:
+            key = TextAttribute.INPUT_METHOD_UNDERLINE;
+            map.put(key, TextAttribute.UNDERLINE_LOW_ONE_PIXEL);
+            break;
+        }
     }
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/wtk/linux/LinuxWTK.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/wtk/linux/LinuxWTK.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/wtk/linux/LinuxWTK.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/wtk/linux/LinuxWTK.java Wed Sep  6 09:06:15 2006
@@ -39,7 +39,7 @@
      * @see org.apache.harmony.awt.wtk.WTK#getNativeEventQueue()
      */
     public NativeEventQueue getNativeEventQueue() {
-        return windowFactory;
+        return eventQueue;
     }
 
     /**
@@ -82,8 +82,14 @@
         }
         return robot;
     }
+    
+    public NativeIM getNativeIM() {
+        // TODO implement
+        return null;
+    }
 
     private final LinuxWindowFactory windowFactory = new LinuxWindowFactory();
+    private final LinuxEventQueue eventQueue = new LinuxEventQueue(windowFactory);
     private final GraphicsFactory graphicsFactory = new org.apache.harmony.awt.gl.linux.LinuxGraphics2DFactory();
     private final LinuxCursorFactory cursorFactory = new LinuxCursorFactory(windowFactory);
     private final NativeMouseInfo mouseInfo = new LinuxMouseInfo(windowFactory);

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/wtk/linux/LinuxWindow.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/wtk/linux/LinuxWindow.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/wtk/linux/LinuxWindow.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/wtk/linux/LinuxWindow.java Wed Sep  6 09:06:15 2006
@@ -33,6 +33,7 @@
 import org.apache.harmony.awt.gl.MultiRectArea;
 import org.apache.harmony.awt.gl.Utils;
 import org.apache.harmony.awt.gl.linux.XVolatileImage;
+import org.apache.harmony.awt.gl.linux.XGraphicsConfiguration;
 import org.apache.harmony.awt.nativebridge.CLongPointer;
 import org.apache.harmony.awt.nativebridge.Int32Pointer;
 import org.apache.harmony.awt.nativebridge.NativeBridge;
@@ -148,10 +149,31 @@
         if (child) {
             windowRect = new Rectangle(p.x, p.y, p.w, p.h);
         }
+
+        XGraphicsConfiguration xgcfg =
+                (XGraphicsConfiguration) GraphicsEnvironment.
+                getLocalGraphicsEnvironment().getDefaultScreenDevice().
+                getDefaultConfiguration();
+
+        X11.XSetWindowAttributes setAttrs = x11.createXSetWindowAttributes(false);
+        setAttrs.set_colormap(xgcfg.getXColormap());
+
+        windowID = x11.XCreateWindow(
+                display, parentID,
+                p.x, p.y, p.w, p.h, 0,
+                xgcfg.getDepth(),
+                X11Defs.InputOutput,
+                xgcfg.getVisual(),
+                (long) (X11Defs.CWColormap),
+                setAttrs
+        );
+
+        /*
         windowID = x11.XCreateWindow(display, parentID, p.x, p.y, p.w, p.h, 0,
                                      X11Defs.CopyFromParent,
                                      X11Defs.InputOutput,
                                      X11Defs.CopyFromParent, 0, 0);
+                                     */
         String title = (p.name != null) ? p.name : "";
         x11.XSetStandardProperties(display, windowID, title, title, 0,
                 null, 0, null);
@@ -883,5 +905,8 @@
 
     public MultiRectArea getObscuredRegion(Rectangle part) {
         return null;
+    }
+
+    public void setIMStyle() {
     }
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/wtk/linux/LinuxWindowFactory.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/wtk/linux/LinuxWindowFactory.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/wtk/linux/LinuxWindowFactory.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/wtk/linux/LinuxWindowFactory.java Wed Sep  6 09:06:15 2006
@@ -22,10 +22,9 @@
 import java.awt.Dimension;
 import java.awt.Frame;
 import java.awt.Point;
-import java.awt.event.WindowEvent;
+import java.util.Collections;
 import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedList;
+import java.util.Map;
 
 import org.apache.harmony.awt.nativebridge.CLongPointer;
 import org.apache.harmony.awt.nativebridge.Int32Pointer;
@@ -34,42 +33,23 @@
 import org.apache.harmony.awt.nativebridge.linux.X11;
 import org.apache.harmony.awt.nativebridge.linux.X11Defs;
 import org.apache.harmony.awt.wtk.CreationParams;
-import org.apache.harmony.awt.wtk.NativeEvent;
-import org.apache.harmony.awt.wtk.NativeEventListener;
-import org.apache.harmony.awt.wtk.NativeEventQueue;
 import org.apache.harmony.awt.wtk.NativeWindow;
 import org.apache.harmony.awt.wtk.WindowFactory;
 
 
-public final class LinuxWindowFactory implements WindowFactory, NativeEventQueue {
+public final class LinuxWindowFactory implements WindowFactory {
 
     private static final X11 x11 = X11.getInstance();
     private static final NativeBridge bridge = NativeBridge.getInstance();
 
     private final XServerConnection xConnection = new XServerConnection(x11);
-
     private final long display = xConnection.getDisplay();
-
     private final int screen = xConnection.getScreen();
-
     final WindowManager wm;
 
-    private final LinuxEventDecoder eventDecoder;
-
-    private NativeEventListener listener;
-
     private final long javaWindow;
-
     private final LinuxWindowMap allWindows = new LinuxWindowMap();
 
-    private X11.XEvent curEvent;
-
-    private LinkedList preprocessors = new LinkedList();
-
-    public void addPreprocessor(Preprocessor preprocessor) {
-        preprocessors.add(preprocessor);
-    }
-
     /**
      * Returns current root window id.
      * @return root window id
@@ -95,14 +75,10 @@
     }
 
     public LinuxWindowFactory() {
-        curEvent = x11.createXEvent(false);
         javaWindow = x11.XCreateSimpleWindow(display, x11.XDefaultRootWindow(display),
                 0, 0, 1, 1, 0, 0, 0);
         x11.XSelectInput(display, javaWindow, X11Defs.StructureNotifyMask);
-        eventDecoder = new LinuxEventDecoder(javaWindow, this);
 
-        // select input for root window
-        // we need to have notification about selection owner change
         long rootWindow = getRootWindow();
         X11.XWindowAttributes attributes = x11.createXWindowAttributes(false);
         x11.XGetWindowAttributes(display, rootWindow, attributes);
@@ -112,66 +88,8 @@
             attributes.get_your_event_mask() | X11Defs.StructureNotifyMask);
 
         wm = new WindowManager(this);
-
-    }
-
-//  NativeEventQueue interface begin
-    public boolean waitEvent() {
-        if (eventDecoder.exposeEvent == null) {
-            do {
-                x11.XNextEvent(display, curEvent);
-            } while (preprocessEvent(curEvent));
-        }
-
-        return true; //X server doesn't provide the last event
-    }
-
-    public boolean isEmpty() {
-        return (x11.XPending(display) == 0);
-    }
-
-    public void awake() {
-        X11.XEvent event = x11.createXEvent(false);
-
-        event.set_type(X11Defs.MapNotify);
-        event.get_xany().set_window(javaWindow);
-        x11.XSendEvent(display, javaWindow, 0, X11Defs.StructureNotifyMask, event);
-        x11.XFlush(display);
-
-        listener.onAwake();
     }
 
-    public long dispatchEventToListener() {
-        listener.onEventBegin();
-
-        if (eventDecoder.exposeEvent == null) {
-            eventDecoder.setEvent(curEvent);
-        } else {
-            eventDecoder.setEvent(eventDecoder.exposeEvent);
-            eventDecoder.exposeEvent = null;
-        }
-
-        try {
-            if ((eventDecoder.getEventId() != NativeEvent.ID_PLATFORM) &&
-                (eventDecoder.getEventId() != NativeEvent.ID_JAVA_EVENT))
-            {
-                listener.onEvent(eventDecoder);
-                if (eventDecoder.getEventId() == WindowEvent.WINDOW_CLOSED) {
-                    allWindows.remove(eventDecoder.getWindowId());
-                }
-            }
-            return 0; //Everything is always fine
-        } finally {
-            listener.onEventEnd();
-            listener.onEventNestingEnd();
-        }
-    }
-
-    public void setNativeEventListener(NativeEventListener l) {
-        listener = l;
-    }
-//NativeEventQueue interface end
-
     public NativeWindow createWindow(CreationParams p) {
         LinuxWindow lw = new LinuxWindow(this, p);
         allWindows.put(lw);
@@ -190,10 +108,6 @@
     }
 
     public NativeWindow getWindowById(long id) {
-        if (!validWindowId(id)) {
-            throw new RuntimeException("GetWindowById: invalid Window ID " + id);
-        }
-
         return allWindows.get(id);
     }
 
@@ -205,10 +119,6 @@
         allWindows.remove(windowID);
     }
 
-    //Dummy-Gummy
-    public void onModalLoopBegin() {}
-    public void onModalLoopEnd() {}
-
     public String getAtomName(long atom) {
         long atomNamePtr = x11.XGetAtomName(display, atom);
         Int8Pointer rawName = bridge.createInt8Pointer(atomNamePtr);
@@ -299,22 +209,6 @@
         return javaWindow;
     }
 
-    private boolean preprocessEvent(X11.XEvent event) {
-        for (Iterator i = preprocessors.iterator(); i.hasNext(); ) {
-            if (((Preprocessor) i.next()).preprocess(event)) {
-                return true;
-            }
-        }
-
-        return false;
-    }
-
-    public interface Preprocessor {
-
-        public boolean preprocess(X11.XEvent event);
-
-    }
-
 }
 
 class XServerConnection {
@@ -349,7 +243,7 @@
 }
 
 final class LinuxWindowMap {
-    private final HashMap map = new HashMap();
+    private final Map map = Collections.synchronizedMap(new HashMap());
 
     LinuxWindow get(long id) {
         return (LinuxWindow)map.get(new Long(id));

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/wtk/linux/XTestRobot.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/wtk/linux/XTestRobot.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/wtk/linux/XTestRobot.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/wtk/linux/XTestRobot.java Wed Sep  6 09:06:15 2006
@@ -91,7 +91,12 @@
         Rectangle rect = new Rectangle(x, y, 1, 1);
         X11.XImage ximg = getScreenImage(rect);
         long pixel = ximg.get_f().get_pixel(ximg, 0, 0);
-        return getColor(ximg, pixel);
+        // this only works if window containing (x, y)
+        // point uses default color map:
+        // ideally we should find window at (x,y)
+        // and take its own color map
+        long cmap = x11.XDefaultColormap(dpy, screen);
+        return getColor(cmap, pixel);
     }
 
     /**
@@ -172,27 +177,14 @@
         return x11.createXImage(ptr);
     }
 
-    private Color getColor(X11.XImage ximg, long pixel) {
-        long redMask = ximg.get_red_mask();
-        long greenMask = ximg.get_green_mask();
-        long blueMask = ximg.get_blue_mask();
-        int r = getColorComp(pixel, redMask, getMaskShift(redMask));
-        int g = getColorComp(pixel, greenMask, getMaskShift(greenMask));
-        int b = getColorComp(pixel, blueMask, getMaskShift(blueMask));
+    private Color getColor(long cmap, long pixel) {
+        X11.XColor xcolor = x11.createXColor(false);
+        xcolor.set_pixel(pixel);
+        x11.XQueryColor(dpy, cmap, xcolor);
+        int r = xcolor.get_red() & 0xFF;
+        int g = xcolor.get_green() & 0xFF;
+        int b = xcolor.get_blue() & 0xFF;
         return new Color(r, g, b);
-    }
-
-    private int getMaskShift(long mask) {
-        int i = 0;
-        while ((mask != 0) && ((mask & 1) == 0)) {
-            mask >>= 1;
-            i++;
-        }
-        return i;
-    }
-
-    private int getColorComp(long pixel, long mask, int shift) {
-        return (int) ((pixel >> shift) & (mask >> shift) & 0xFF);
     }
 
     private int getBool(boolean b) {

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/datatransfer/windows/WinClipboard.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/datatransfer/windows/WinClipboard.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/datatransfer/windows/WinClipboard.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/datatransfer/windows/WinClipboard.java Wed Sep  6 09:06:15 2006
@@ -14,7 +14,7 @@
  *  limitations under the License.
  */
 /**
- * @author Michael Danilov
+ * @author Michael Danilov, Pavel Dolgov
  * @version $Revision$
  */
 package org.apache.harmony.awt.datatransfer.windows;
@@ -24,354 +24,75 @@
 import java.awt.datatransfer.Transferable;
 import java.awt.datatransfer.UnsupportedFlavorException;
 import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.LinkedList;
 
 import org.apache.harmony.awt.ContextStorage;
-import org.apache.harmony.awt.datatransfer.ClipboardEntry;
-import org.apache.harmony.awt.datatransfer.FlavorInfo;
+import org.apache.harmony.awt.datatransfer.DataProxy;
+import org.apache.harmony.awt.datatransfer.DataSnapshot;
+import org.apache.harmony.awt.datatransfer.DataSource;
 import org.apache.harmony.awt.datatransfer.NativeClipboard;
-import org.apache.harmony.awt.datatransfer.SystemTransferable;
-import org.apache.harmony.awt.nativebridge.windows.Win32;
-import org.apache.harmony.awt.nativebridge.windows.WindowsDefs;
+import org.apache.harmony.awt.nativebridge.windows.WinDataTransfer;
 import org.apache.harmony.awt.wtk.windows.WinEventQueue;
-import org.apache.harmony.misc.accessors.AccessorFactory;
-import org.apache.harmony.misc.accessors.ArrayAccessor;
-import org.apache.harmony.misc.accessors.LockedArray;
-import org.apache.harmony.misc.accessors.MemoryAccessor;
 
 public final class WinClipboard extends NativeClipboard
         implements WinEventQueue.Preprocessor {
 
-    private static final Win32 win32 = Win32.getInstance();
-    private static final MemoryAccessor memAccess = AccessorFactory.getMemoryAccessor();
-    private static final ArrayAccessor memArrAccess = AccessorFactory.getArrayAccessor();
-
-    private final Requestor requestor;
-    private final Owner owner;
-    private final Viewer viewer;
-
-    private SystemTransferable contentsStub;
-
+    private final WinEventQueue winEventQueue;
+    
     public WinClipboard() {
         super("System");
-
-        requestor = new Requestor();
-        owner = new Owner();
-        viewer = new Viewer();
-
-        ((WinEventQueue) ContextStorage.getNativeEventQueue()).addPreprocessor(this);
-
-        updateContents();
+        winEventQueue = ((WinEventQueue) ContextStorage.getNativeEventQueue());
+        winEventQueue.addPreprocessor(this);
     }
 
     public void onShutdown() {
-        if (win32.GetClipboardOwner() == javaWindow) {
-            owner.renderAllFormats();
-        }
-        viewer.unregister();
     }
 
     public void onRestart() {
-        viewer.register();
-        updateContents();
     }
 
     public void setContents(Transferable contents, ClipboardOwner owner) {
-        awtSynchronizer.lock();
-        try {
-            super.setContents(contents, owner);
-
-            this.owner.acquire();
-        } finally {
-            awtSynchronizer.unlock();
-        }
-    }
-
-    public Object getData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
-        awtSynchronizer.lock();
-        try {
-            if (owner.isOwner) {
-                return super.getData(flavor);
-            } else {
-                FlavorInfo info = (FlavorInfo) contentsStub.infoMap.get(flavor);
-
-                if (info == null) {
-                    throw new UnsupportedFlavorException(flavor);
-                }
-                if (info.data == null) {
-                    if (info.translated) {
-                        throw new RuntimeException("Data translation failed.");
-                    } else {
-                        if (info.rawData == null) {
-                            if (info.read) {
-                                throw new IOException("Can't read data.");
-                            } else {
-                                info.read = true;
-                                info.rawData = requestor.getData((int) info.format);
-                                if (info.rawData == null) {
-                                    throw new IOException("Can't read data.");
-                                }
-                            }
-                        }
-                        info.translated = true;
-                        info.data = translationManager.translateNative2Java(flavor, info);
-                    }
-                }
-
-                if (info.data != null) {
-                    return info.data;
-                }
-                throw new RuntimeException(
-                        "Data translation failed. Can't find proper clipboard translator.");
-            }
-        } finally {
-            awtSynchronizer.unlock();
-        }
-    }
-
-    public Transferable getContents(Object requestor) {
-        awtSynchronizer.lock();
-        try {
-            if (owner.isOwner || contentsStub.flavors.isEmpty()) {
-                return super.getContents(requestor);
-            } else {
-                HashSet requestedFormats = new HashSet();
-                HashMap dataMap = new HashMap();
-
-                for (Iterator i = contentsStub.flavors.iterator(); i.hasNext(); ) {
-                    FlavorInfo info = (FlavorInfo) contentsStub.infoMap.get(i.next());
-                    Long format = new Long(info.format);
-
-                    if (requestedFormats.contains(format)) {
-                        info.rawData = (byte[]) dataMap.get(format);
-                    } else {
-                        requestedFormats.add(format);
-                        info.rawData = this.requestor.getData((int) info.format);
-                        dataMap.put(format, info.rawData);
-                    }
-                }
-
-                return contentsStub;
-            }
-        } finally {
-            awtSynchronizer.unlock();
-        }
-    }
-
-    public boolean preprocess(long hwnd, int msg, long wParam, long lParam, long[] result) {
-        awtSynchronizer.lock();
-        try {
-            if (hwnd != javaWindow) {
-                return false;
-            }
-
-            switch (msg) {
-            case WindowsDefs.WM_CHANGECBCHAIN:
-                viewer.onChainChange(msg, wParam, lParam);
-                result[0] = 0;
-                return true;
-            case WindowsDefs.WM_DRAWCLIPBOARD:
-                viewer.onDraw(msg, wParam, lParam);
-                return false;           // to not miss AWT events by sleeping
-            case WindowsDefs.WM_RENDERFORMAT:
-                owner.renderFormat((int) wParam);
-                result[0] = 0;
-                return true;
-            default:
-                return false;
-            }
-        } finally {
-            awtSynchronizer.unlock();
-        }
-    }
-
-    private void updateContents() {
-        awtSynchronizer.lock();
-        try {
-            LinkedList formats = requestor.getFormatsList();
-            contentsStub = translationManager.createTransferableStub(formats);
-
-            super.setContents(contentsStub, null);
-        } finally {
-            awtSynchronizer.unlock();
-        }
-    }
-
-    private void openClipboard() {
-        long timeout = System.currentTimeMillis() + OPS_TIMEOUT;
-
-        while (win32.OpenClipboard(javaWindow) == 0) {
-            if (System.currentTimeMillis() > timeout) {
-                throw new IllegalStateException("Can't open clipboard.");
-            }
-            Thread.yield();
-        }
-    }
-
-    private class Requestor {
-
-        LinkedList getFormatsList() {
-            LinkedList formats = new LinkedList();
+        DataSource dc = new DataSource(contents);
+        final DataSnapshot snapshot = new DataSnapshot(dc);
 
-            openClipboard();
-            try {
-                for (int i = win32.EnumClipboardFormats(0);
-                        i != 0; i = win32.EnumClipboardFormats(i))
-                {
-                    formats.add(new Long(i));
-                }
-            } finally {
-                win32.CloseClipboard();
+        WinEventQueue.Task task = new WinEventQueue.Task() {
+            public void perform() {
+                WinDataTransfer.setClipboardContents(snapshot);
             }
-
-            return formats;
-        }
-
-        byte[] getData(int format) {
-            byte[] data = null;
-
-            openClipboard();
-            try {
-                long globalHandler = win32.GetClipboardData(format);
-                long dataLength = win32.GlobalSize(globalHandler);
-
-                if ((dataLength > 0) && (((int) dataLength) == dataLength)) {
-                    long globalPtr = win32.GlobalLock(globalHandler);
-                    LockedArray arr = null;
-
-                    try {
-                        data = new byte[(int) dataLength];
-                        arr = memArrAccess.lockArrayShort(data);
-
-                        if (globalPtr == 0) {
-                            throw new RuntimeException(
-                                    "Cannot allocate global memory (" + dataLength + " bytes)");
-                        }
-
-                        memAccess.memcpy(arr.getAddress(), globalPtr, dataLength);
-                    } finally {
-                        win32.GlobalUnlock(globalHandler);
-                        arr.release();
-                    }
-                }
-            } finally {
-                win32.CloseClipboard();
-            }
-
-            return data;
-        }
-
+        };
+        winEventQueue.performTask(task);
+        // TODO: fire flavor change events
     }
 
-    private class Viewer {
-
-        private long nextHWND;
-
-        Viewer() {
-            register();
-        }
-
-        void onDraw(int msg, long wParam, long lParam) {
-            if (win32.GetClipboardOwner() != javaWindow) {
-                owner.isOwner = false;
-                updateContents();
-            }
-            win32.SendMessageW(nextHWND, msg, wParam, lParam);
-        }
-
-        void onChainChange(int msg, long wParam, long lParam) {
-            if (wParam == nextHWND) {
-                nextHWND = lParam;
-            } else if (nextHWND != 0) {
-                win32.SendMessageW(nextHWND, msg, wParam, lParam);
-            }
-        }
-
-        void register() {
-            owner.isOwner = false;
-            nextHWND = win32.SetClipboardViewer(javaWindow);
-        }
-
-        void unregister() {
-            owner.isOwner = false;
-            win32.ChangeClipboardChain(javaWindow, nextHWND);
-        }
-
+    public Object getData(DataFlavor flavor)
+            throws UnsupportedFlavorException, IOException {
+        return getContents(this).getTransferData(flavor);
     }
 
-    private class Owner {
-
-        boolean isOwner;
-
-        private final HashMap contentMap = new HashMap();
-        private final ArrayList formats = new ArrayList();
-
-        void acquire() {
-            LinkedList entries = translationManager.translateJava2Native(contents);
-
-            isOwner = true;
-            openClipboard();
-            try {
-                win32.EmptyClipboard();
-                contentMap.clear();
-                formats.clear();
-
-                for (Iterator i = entries.iterator(); i.hasNext();) {
-                    ClipboardEntry entry = (ClipboardEntry) i.next();
-                    Integer format = new Integer((int) entry.format);
-
-                    formats.add(format);
-                    contentMap.put(format, entry.data);
-                    win32.SetClipboardData((int) entry.format, 0);
-                }
-            } finally {
-                win32.CloseClipboard();
-            }
-        }
-
-        void renderFormat(int format) {
-            // Initiated by native system so must not open clipboard it's already opened
-            byte[] data = (byte[]) contentMap.get(new Integer(format));
-
-            if (data == null) {
-                return;
-            }
-
-            int size = data.length;
-            long globalHandler = win32.GlobalAlloc(WindowsDefs.GMEM_MOVEABLE, size);
-            long globalPtr = win32.GlobalLock(globalHandler);
-            LockedArray arr = memArrAccess.lockArrayShort(data);
-
-            if (globalPtr == 0) {
-                return;
-            }
-
-            memAccess.memcpy(globalPtr, arr.getAddress(), size);
-            arr.release();
-            win32.GlobalUnlock(globalHandler);
-            win32.SetClipboardData(format, globalHandler);
-        }
-
-        void renderAllFormats() {
-            openClipboard();
-            try {
-                if (win32.GetClipboardOwner() != javaWindow) {
-                    return;
-                }
-                win32.EmptyClipboard();
-
-                for (Iterator i = formats.iterator(); i.hasNext();) {
-                    renderFormat(((Integer) i.next()).intValue());
-                }
-            } finally {
-                win32.CloseClipboard();
-            }
-        }
-
+    public Transferable getContents(Object requestor) {
+        WinEventQueue.Task task = new WinEventQueue.Task() {
+            public void perform() {
+                WinDataTransfer.IDataObject dataObject = 
+                        WinDataTransfer.getClipboardContents();
+                DataSnapshot snapshot = new DataSnapshot(dataObject);
+                dataObject.release();
+                returnValue = new DataProxy(snapshot);
+            }
+        };
+        winEventQueue.performTask(task);
+        return (DataProxy)task.returnValue;
+    }
+    
+    public DataFlavor[] getAvailableDataFlavors() {
+        Transferable t = getContents(this);
+        return (t != null) ? 
+                t.getTransferDataFlavors() : new DataFlavor[0];
+    }
+
+    public boolean preprocess(long hwnd, int msg, 
+                              long wParam, long lParam, 
+                              long[] result) {
+        // TODO: track changes in Windows clipboard
+        return false;
     }
 
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/datatransfer/windows/WinDTK.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/datatransfer/windows/WinDTK.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/datatransfer/windows/WinDTK.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/datatransfer/windows/WinDTK.java Wed Sep  6 09:06:15 2006
@@ -14,29 +14,94 @@
  *  limitations under the License.
  */
 /**
- * @author Michael Danilov
+ * @author Michael Danilov, Pavel Dolgov
  * @version $Revision$
  */
 package org.apache.harmony.awt.datatransfer.windows;
 
-import org.apache.harmony.awt.datatransfer.*;
-
-public final class WinDTK extends DTK {
+import java.awt.dnd.DragGestureEvent;
+import java.awt.dnd.DropTargetContext;
+import java.awt.dnd.peer.DragSourceContextPeer;
+import java.awt.dnd.peer.DropTargetContextPeer;
+
+import org.apache.harmony.awt.datatransfer.DTK;
+import org.apache.harmony.awt.datatransfer.NativeClipboard;
+import org.apache.harmony.awt.nativebridge.windows.Callback;
+import org.apache.harmony.awt.nativebridge.windows.Win32;
+import org.apache.harmony.awt.nativebridge.windows.WinDataTransfer;
+import org.apache.harmony.awt.nativebridge.windows.WindowsDefs;
+import org.apache.harmony.awt.wtk.NativeEventQueue.Task;
+import org.apache.harmony.awt.wtk.windows.WindowProcHandler;
+import org.apache.harmony.misc.accessors.AccessorFactory;
+import org.apache.harmony.misc.accessors.ObjectAccessor;
+
+public final class WinDTK extends DTK implements Callback.Handler {
+    
+    private static final Win32 win32 = Win32.getInstance();
+    private static final ObjectAccessor objAccessor = 
+        AccessorFactory.getObjectAccessor();
+    
+    private static final int WM_TASK = WindowsDefs.WM_USER + 1;
+    
+    private long dataTransferWindow;
+    private long windowProc;
+    private static final String windowClass = 
+        "org.apache.harmony.awt.datatransfer.window";
 
     protected NativeClipboard newNativeClipboard() {
         return new WinClipboard();
     }
 
-    protected NativeTextDescriptor newTextDescriptor() {
-        return new WinTextDescriptor();
+    protected NativeClipboard newNativeSelection() {
+        return null;
     }
 
-    protected NativeTranslationManager newTranslationManager() {
-        return new WinTranslationManager();
+    public void initDragAndDrop() {
+        WinDataTransfer.init();
+        
+        if (windowProc != 0) {
+            return;
+        }
+        windowProc = Callback.registerCallbackDataTransfer(this);
+        WindowProcHandler.registerWindowClass(windowClass, windowProc);
+        dataTransferWindow = win32.CreateWindowExW(0, windowClass,
+                windowClass, 0, 0, 0, 0, 0, // style, x, y, w, h 
+                WindowsDefs.HWND_MESSAGE, 0, 0, null);
+    }
+    
+    public void runEventLoop() {
+        Win32.MSG msg = win32.createMSG(false);
+        while (win32.GetMessageW(msg, 0, 0, 0) != 0) {
+            win32.DispatchMessageW(msg);
+        }
     }
 
-    protected NativeClipboard newNativeSelection() {
-        return null;
+    public DropTargetContextPeer createDropTargetContextPeer(
+            DropTargetContext context) {
+        return new WinDropTarget(this, context);
     }
 
+    public DragSourceContextPeer createDragSourceContextPeer(
+            DragGestureEvent dge) {
+        return new WinDragSource();
+    }
+    
+    public String getDefaultCharset() {
+        return "utf-16le";
+    }
+
+    public long windowProc(long hwnd, int msg, long wParam, long lParam) {
+        if (hwnd == dataTransferWindow && msg == WM_TASK) {
+            Task t = (Task)objAccessor.getObjectFromReference(lParam);
+            t.perform();
+            return 0;
+        }
+        return win32.DefWindowProcW(hwnd, msg, wParam, lParam);
+    }
+
+    public void performTask(Task task) {
+        long ref = objAccessor.getGlobalReference(task);
+        win32.SendMessageW(dataTransferWindow, WM_TASK, 0, ref);
+        objAccessor.releaseGlobalReference(ref);
+    }
 }

Added: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/datatransfer/windows/WinDragSource.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/datatransfer/windows/WinDragSource.java?view=auto&rev=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/datatransfer/windows/WinDragSource.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/datatransfer/windows/WinDragSource.java Wed Sep  6 09:06:15 2006
@@ -0,0 +1,247 @@
+/*
+ *  Copyright 2005 - 2006 The Apache Software Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+/** 
+ * @author Pavel Dolgov
+ * @version $Revision$
+ */
+package org.apache.harmony.awt.datatransfer.windows;
+
+import java.awt.Cursor;
+import java.awt.EventQueue;
+import java.awt.Image;
+import java.awt.Point;
+import java.awt.dnd.DnDConstants;
+import java.awt.dnd.DragSourceContext;
+import java.awt.dnd.InvalidDnDOperationException;
+import java.awt.dnd.peer.DragSourceContextPeer;
+import java.awt.event.InputEvent;
+
+import org.apache.harmony.awt.ContextStorage;
+import org.apache.harmony.awt.datatransfer.DataSnapshot;
+import org.apache.harmony.awt.datatransfer.DataSource;
+import org.apache.harmony.awt.datatransfer.DragSourceEventProxy;
+import org.apache.harmony.awt.nativebridge.windows.Win32;
+import org.apache.harmony.awt.nativebridge.windows.WinDataTransfer;
+import org.apache.harmony.awt.nativebridge.windows.WindowsDefs;
+import org.apache.harmony.awt.wtk.windows.WinEventQueue;
+
+/**
+ * Starts drag operation and handles callbacks from OLE.
+ * The callbacks simply do EventQueue.invokeLater(new DragSourceEventProxy(...))
+ */
+public class WinDragSource implements DragSourceContextPeer {
+
+    private static final Win32 win32 = Win32.getInstance();
+
+    private Cursor cursor;
+    private DragSourceContext context;
+
+    private final WinEventQueue winEventQueue;
+    
+    private int userAction;
+    private int targetActions;
+    private Point mouseLocation;
+    
+    public WinDragSource() {
+        winEventQueue = (WinEventQueue)ContextStorage.getNativeEventQueue();
+    }
+
+    public void startDrag(DragSourceContext dsc, Cursor c, Image di, Point ioff)
+            throws InvalidDnDOperationException {
+
+        synchronized (this) {
+            context = dsc;
+            cursor = c;
+        }
+        mouseLocation = getCurrentMouseLocation();
+        userAction = 0;
+        targetActions = 0;
+        
+        DataSource dataSource = new DataSource(context.getTransferable());
+        final DataSnapshot snapshot = new DataSnapshot(dataSource);
+        final int srcActions = getWinActions(context.getSourceActions());
+
+        WinEventQueue.Task task = new WinEventQueue.Task() {
+            public void perform() {
+                WinDataTransfer.startDrag(snapshot, 
+                        WinDragSource.this, srcActions);
+            }
+        };
+        winEventQueue.performLater(task);
+    }
+
+    public Cursor getCursor() {
+        synchronized (this) {
+            return cursor;
+        }
+    }
+
+    public void setCursor(Cursor c) throws InvalidDnDOperationException {
+        synchronized (this) {
+            cursor = c;
+        }
+        
+        // TODO: implement native cursor update,
+        // and in native method WinDragSource::GiveFeedback() 
+        // change return value to S_OK to suppress default OLE cursors
+    }
+
+    public void transferablesFlavorsChanged() {
+        // TODO: call this method from IAdviseSink::OnDataChange()
+    }
+
+    static int getDndActions(int winActions) {
+        int dndActions = 0;
+        if ((winActions & WindowsDefs.DROPEFFECT_COPY) != 0) {
+            dndActions |= DnDConstants.ACTION_COPY;
+        }
+        if ((winActions & WindowsDefs.DROPEFFECT_MOVE) != 0) {
+            dndActions |= DnDConstants.ACTION_MOVE;
+        }
+        if ((winActions & WindowsDefs.DROPEFFECT_LINK) != 0) {
+            dndActions |= DnDConstants.ACTION_LINK;
+        }
+        return dndActions;
+    }
+    
+    static int getWinActions(int dndActions) {
+        int winActions = 0;
+        if ((dndActions & DnDConstants.ACTION_COPY) != 0) {
+            winActions |= WindowsDefs.DROPEFFECT_COPY;
+        }
+        if ((dndActions & DnDConstants.ACTION_MOVE) != 0) {
+            winActions |= WindowsDefs.DROPEFFECT_MOVE;
+        }
+        if ((dndActions & DnDConstants.ACTION_LINK) != 0) {
+            winActions |= WindowsDefs.DROPEFFECT_LINK;
+        }
+        return winActions;
+    }
+    
+    /**
+     * Called from native method WinDragSource::GiveFeedback()
+     * @param winActions - drop actions acceptable for drop target
+     * @param scroll - scrolling is asked by drop target
+     */
+    public void giveFeedback(int winActions, boolean scroll) {
+        int dndActions = getDndActions(winActions);
+        updateLocationAndActions(dndActions);
+    }
+    
+    /**
+     * Called from native method WinDragSource::QueryContinueDrag()
+     */
+    public void continueDrag() {
+        updateLocationAndActions(targetActions);
+    }
+    
+    /**
+     * Called from native method WinDataTransfer::startDrag()
+     * after drag operation is finished
+     * @param winAction - drop action taken
+     * @param success - drop was completed successfully
+     */
+    public void endDrag(int winAction, boolean success) {
+        int dndAction = getDndActions(winAction);
+        DragSourceEventProxy r = new DragSourceEventProxy(
+                context,
+                DragSourceEventProxy.DRAG_DROP_END,
+                dndAction, success,
+                mouseLocation, getCurrentModifiers());
+        EventQueue.invokeLater(r);
+    }
+    
+    private void updateLocationAndActions(int newTargetActions) {
+        Point newLocation = getCurrentMouseLocation();
+        int modifiers = getCurrentModifiers();
+        int newUserAction = getUserAction(modifiers, newTargetActions);
+
+        if (!newLocation.equals(mouseLocation)) {
+            mouseLocation.setLocation(newLocation);
+            if (newTargetActions != 0) {
+                DragSourceEventProxy r = new DragSourceEventProxy(
+                        context,
+                        DragSourceEventProxy.DRAG_MOUSE_MOVED,
+                        newUserAction, newTargetActions, 
+                        mouseLocation, modifiers);
+                EventQueue.invokeLater(r);
+            }
+        }
+        
+        if (newUserAction != userAction || newTargetActions != targetActions) {
+            int type = 0;
+            if (targetActions == 0 && newTargetActions != 0) {
+                type = DragSourceEventProxy.DRAG_ENTER;
+            } else if (targetActions != 0 && newTargetActions == 0) {
+                type = DragSourceEventProxy.DRAG_EXIT;
+            } else {
+                type = DragSourceEventProxy.DRAG_ACTION_CHANGED;
+            }
+            userAction = newUserAction;
+            targetActions = newTargetActions;
+            if (type != 0) {
+                DragSourceEventProxy r = new DragSourceEventProxy(
+                        context,
+                        type, newUserAction, newTargetActions, 
+                        mouseLocation, modifiers);
+                EventQueue.invokeLater(r);
+            }
+        }
+    }
+    
+    private static Point getCurrentMouseLocation() {
+        Win32.POINT lpPoint = win32.createPOINT(false);
+        win32.GetCursorPos(lpPoint);
+        return new Point(lpPoint.get_x(), lpPoint.get_y());
+    }
+    
+    private static int getCurrentModifiers() {
+        int modifiers = 0;
+        modifiers |= ((win32.GetKeyState(WindowsDefs.VK_SHIFT) & 0x80) != 0) ?
+                InputEvent.SHIFT_DOWN_MASK : 0;
+        modifiers |= ((win32.GetKeyState(WindowsDefs.VK_CONTROL) & 0x80) != 0) ?
+                InputEvent.CTRL_DOWN_MASK : 0;
+        modifiers |= ((win32.GetKeyState(WindowsDefs.VK_MENU) & 0x80) != 0) ?
+                InputEvent.ALT_DOWN_MASK : 0;
+        modifiers |= ((win32.GetKeyState(WindowsDefs.VK_LBUTTON) & 0x80) != 0) ?
+                InputEvent.BUTTON1_DOWN_MASK : 0;
+        modifiers |= ((win32.GetKeyState(WindowsDefs.VK_MBUTTON) & 0x80) != 0) ?
+                InputEvent.BUTTON2_DOWN_MASK : 0;
+        modifiers |= ((win32.GetKeyState(WindowsDefs.VK_RBUTTON) & 0x80) != 0) ?
+                InputEvent.BUTTON3_DOWN_MASK : 0;
+        return modifiers;
+    }
+    
+    private static int getUserAction(int modifiers, int targetActions) {
+        if ((modifiers & InputEvent.CTRL_DOWN_MASK) != 0) {
+            return ((modifiers & InputEvent.SHIFT_DOWN_MASK) != 0) ?
+                    DnDConstants.ACTION_LINK : DnDConstants.ACTION_COPY;
+        }
+        if ((modifiers & InputEvent.SHIFT_DOWN_MASK) != 0) {
+            return DnDConstants.ACTION_MOVE;
+        }
+        if ((targetActions & DnDConstants.ACTION_MOVE) != 0) {
+            return DnDConstants.ACTION_MOVE;
+        }
+        if ((targetActions & DnDConstants.ACTION_COPY) != 0) {
+            return DnDConstants.ACTION_COPY;
+        }
+        if ((targetActions & DnDConstants.ACTION_LINK) != 0) {
+            return DnDConstants.ACTION_LINK;
+        }
+        return DnDConstants.ACTION_NONE;
+    }
+}



Mime
View raw message