harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mloe...@apache.org
Subject svn commit: r440748 [13/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
Added: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/nativebridge/windows/WinDataTransfer.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/nativebridge/windows/WinDataTransfer.java?view=auto&rev=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/nativebridge/windows/WinDataTransfer.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/nativebridge/windows/WinDataTransfer.java Wed Sep  6 09:06:15 2006
@@ -0,0 +1,168 @@
+/*
+ *  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.nativebridge.windows;
+
+import java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.SystemFlavorMap;
+
+import org.apache.harmony.awt.datatransfer.DataProvider;
+import org.apache.harmony.awt.datatransfer.DataSnapshot;
+import org.apache.harmony.awt.datatransfer.RawBitmap;
+import org.apache.harmony.awt.datatransfer.windows.WinDragSource;
+import org.apache.harmony.awt.datatransfer.windows.WinDropTarget;
+
+/**
+ * Native support for data transfer on Windows
+ */
+public final class WinDataTransfer {
+    
+    static {
+        System.loadLibrary("Win32Wrapper");
+    }
+
+    /**
+     * Wrapper for OLE interface IDataObject
+     */
+    public static class IDataObject implements DataProvider {
+        
+        /**
+         * pointer to IDataObject interface
+         */
+        public final long pointer;
+        
+        public IDataObject(long p) {
+            if (p == 0) {
+                throw new RuntimeException(
+                        "Cannot get data from OLE clipboard");
+            }
+            pointer = p;
+        }
+        
+        public String getText() {
+            return getDataObjectText(pointer);
+        }
+        
+        public String[] getFileList() {
+            return getDataObjectFileList(pointer);
+        }
+        
+        public String getURL() {
+            return getDataObjectURL(pointer);
+        }
+
+        public String getHTML() {
+            return getDataObjectHTML(pointer);
+        }
+        
+        public RawBitmap getRawBitmap() {
+            int header[] = new int[7];
+            Object buffer = getDataObjectImage(pointer, header);
+            if (buffer == null) {
+                return null;
+            }
+            return new RawBitmap(header, buffer);
+        }
+        
+        public String[] getNativeFormats() {
+            return getDataObjectFormats(pointer);
+        }
+
+        public boolean isNativeFormatAtailable(String nativeFormat) {
+            return isDataObjectFormatAvailable(pointer, nativeFormat);
+        }
+        
+        public byte[] getSerializedObject(Class clazz) {
+            String nativeFormat = SystemFlavorMap.encodeDataFlavor(
+                    new DataFlavor(clazz, null));
+            return getDataObjectSerialized(pointer, nativeFormat);
+        }
+
+        public boolean equals(Object obj) {
+            if (obj instanceof IDataObject) {
+                return pointer == ((IDataObject)obj).pointer;
+            }
+            return false;
+        }
+        
+        public int hashCode() {
+            return (int)pointer;
+        }
+
+        public void release() {
+        }
+    }
+
+    public static native void init();
+
+    private static native String getDataObjectText(long pointer);
+
+    private static native String[] getDataObjectFileList(long pointer);
+
+    private static native String getDataObjectURL(long pointer);
+
+    private static native String getDataObjectHTML(long pointer);
+
+    /**
+     * Get bitmap bits and dimension from data object 
+     * @param pointer - pointer to IDataObject interface
+     * @param header - array of output values, representing bitmap 
+     * parameters in the format:
+     *  { width, height, stride, bitCount, redMask, greenMask, blueMask }
+     *  
+     * @return bitmap bits in form of int[], short[] or byte[],
+     * or null in case of failure
+     */
+    private static native Object getDataObjectImage(long pointer, int[] header);
+
+    private static native byte[] getDataObjectSerialized(
+                                                long pointer,
+                                                String nativeFormat);
+
+    public static native String getSystemDefaultCharset();
+
+    private static native String[] getDataObjectFormats(long pointer);
+
+    private static native boolean isDataObjectFormatAvailable(
+                                                long pointer,
+                                                String nativeFormat);
+
+    private static native long getOleClipboardDataObject();
+
+    private static native void releaseDataObject(long pointer);
+
+    public static IDataObject getClipboardContents() {
+        long pointer = getOleClipboardDataObject();
+        return pointer != 0 ? new IDataObject(pointer) : null;
+    }
+
+    public static native void setClipboardContents(DataSnapshot snapshot);
+
+    /**
+     * Perform OLE drag-and-drop, wait until the operation is complete.
+     */
+    public static native void startDrag(DataSnapshot snapshot,
+                                       WinDragSource dragSource,
+                                       int sourceActions);
+    
+    public static native long registerDropTarget(long hwnd, 
+                                                 WinDropTarget target);
+    
+    public static native void revokeDropTarget(long hwnd, long target);
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/theme/windows/WinFileDialog.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/theme/windows/WinFileDialog.java?view=auto&rev=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/theme/windows/WinFileDialog.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/theme/windows/WinFileDialog.java Wed Sep  6 09:06:15 2006
@@ -0,0 +1,315 @@
+/*
+ *  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 Dmitry A. Durnev
+ * @version $Revision$
+ */
+package org.apache.harmony.awt.theme.windows;
+
+import java.awt.AWTEvent;
+import java.awt.EventQueue;
+import java.awt.FileDialog;
+import java.awt.Toolkit;
+import java.awt.Window;
+import java.awt.event.ComponentEvent;
+import java.io.File;
+import java.io.FilenameFilter;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.harmony.awt.ComponentInternals;
+import org.apache.harmony.awt.nativebridge.Int16Pointer;
+import org.apache.harmony.awt.nativebridge.NativeBridge;
+import org.apache.harmony.awt.nativebridge.PointerPointer;
+import org.apache.harmony.awt.nativebridge.VoidPointer;
+import org.apache.harmony.awt.nativebridge.windows.Callback;
+import org.apache.harmony.awt.nativebridge.windows.Win32;
+import org.apache.harmony.awt.nativebridge.windows.WindowsConsts;
+import org.apache.harmony.awt.nativebridge.windows.Callback.Handler;
+
+
+public class WinFileDialog extends WinStyle {
+    
+    // windows defs from CommDlg.h
+    private static final int CDN_FIRST = -601;
+    private static final int CDN_INCLUDEITEM = CDN_FIRST - 0x0007;
+    
+    private static class OFNHookHandler implements Handler {
+        
+        public long windowProc(long hwnd, int msg, long wParam, long lParam) {
+            FileDialog fd = (FileDialog) thread2fd.get(Thread.currentThread());
+            if (fd == null) {
+                return 0l;
+            }
+            FilenameFilter ff = fd.getFilenameFilter();
+            
+            if (msg == WM_INITDIALOG) {
+                WinFileDialog.getInstance(fd).hwnd = win32.GetParent(hwnd);
+            }
+            if (msg != WM_NOTIFY) {
+                return 0l;
+            }            
+            if (win32.createNMHDR(lParam).get_code() != CDN_INCLUDEITEM) {
+                return 0l;
+            }
+            
+            if (ff == null) {
+                return 1l;
+            }
+            Win32.OFNOTIFYEXW ofnotify = win32.createOFNOTIFYEXW(lParam);
+            Win32.IShellFolder psf = getIShellFolder(ofnotify.get_psf());
+            
+            int flags = (WindowsConsts.SHGDN_FORPARSING);            
+            Win32.ITEMIDLIST item = win32.createITEMIDLIST(ofnotify.get_pidl());
+            String fullName = getDisplayNameOf(item, psf, flags);
+            File file = new File(fullName);
+            String fName = file.getName();
+            boolean res = true;
+            if (!"".equals(fName)) {
+                res = ff.accept(file.getParentFile(), fName);
+            }            
+            return (res ? 1 : 0);
+        }
+        
+        private Win32.IShellFolder getIShellFolder(VoidPointer ptr) {
+            PointerPointer ptrPtr = nb.createPointerPointer(ptr, false);
+            return win32.createIShellFolder(ptrPtr.getAddress(0));
+        }
+        
+        private String getDisplayNameOf(Win32.ITEMIDLIST item, 
+                                        Win32.IShellFolder parent,
+                                        int flags) {
+            
+            Win32.STRRET strret = win32.createSTRRET(false);
+            parent.GetDisplayNameOf(item, flags, strret);
+            int bufLen = 2048;            
+            Int16Pointer bufPtr = nb.createInt16Pointer(bufLen, false);
+            win32.StrRetToBufW(strret, null, bufPtr, bufLen);
+            return bufPtr.getString();
+        }
+        
+    }
+    
+    private static Win32 win32 = Win32.getInstance();
+    private static NativeBridge nb = NativeBridge.getInstance();
+    private static ComponentInternals ci = ComponentInternals.
+    getComponentInternals();
+    private static Map thread2fd = new HashMap();
+    private static Map fd2win = new HashMap();
+    private static OFNHookHandler handler = new OFNHookHandler();
+    private static long ofnHookPtr = Callback.registerCallbackOFN(handler);
+    private final FileDialog fileDialog;
+    private final boolean modal;
+    private final Win32.OPENFILENAMEW ofn;
+    private long hwnd;
+    
+    public static WinFileDialog getInstance(FileDialog fd) {
+        return (WinFileDialog) fd2win.get(fd);
+    }
+    
+    public WinFileDialog(FileDialog fd) {
+        fileDialog = fd;
+        fd2win.put(fd, this);
+        modal = fd.isModal();
+        ofn = win32.createOPENFILENAMEW(false);
+        ofn.set_lStructSize(ofn.size());        
+    }
+    
+    private void show(int mode) {
+        synchronized (handler) {
+            if (!fileDialog.isDisplayable()) {
+                // make displayable together with owner
+                fileDialog.addNotify();
+            }
+            ci.setVisibleFlag(fileDialog, true);
+            postEvent(new ComponentEvent(fileDialog, 
+                                         ComponentEvent.COMPONENT_SHOWN));
+            initOFN();
+            boolean ok = false;
+            Thread thread = Thread.currentThread();
+            thread2fd.put(thread, fileDialog);
+
+            switch (mode) {
+            case FileDialog.LOAD:
+                ok = (win32.GetOpenFileNameW(ofn) != 0);
+                break;
+            case FileDialog.SAVE:
+                ok = (win32.GetSaveFileNameW(ofn) != 0);
+                break;
+            default:
+                return;
+
+            }
+            setValues(ok);
+            thread2fd.remove(thread);
+            fd2win.remove(fileDialog);
+            ci.setVisibleFlag(fileDialog, false);
+            postEvent(new ComponentEvent(fileDialog,
+                    ComponentEvent.COMPONENT_HIDDEN));
+        }
+    }
+
+    private void setValues(boolean ok) {
+        String error = null;
+        if (ok) {
+            String fullName = ofn.get_lpstrFile().getString();
+            File file = new File(fullName);
+            fileDialog.setFile(ofn.get_lpstrFileTitle().getString());
+            fileDialog.setDirectory(file.getParent() + File.separator);
+
+        } else {
+            fileDialog.setFile(null);
+            fileDialog.setDirectory(null);
+            int code = win32.CommDlgExtendedError();
+            if (code != 0) {
+                error = getExtendedError(code);
+            }
+        }
+        if (error != null) {
+            System.err.println("file dialog " + error + " error!");
+        }
+    }
+
+    private void initOFN() {        
+        setOwner(fileDialog.getOwner());
+        
+        setFile(fileDialog.getFile());
+        setDir(fileDialog.getDirectory());        
+        setTitle(fileDialog.getTitle());
+        setFilter("All Files (*.*)\0*.*\0");
+        
+        ofn.set_Flags(OFN_ENABLEHOOK | OFN_ENABLEINCLUDENOTIFY | OFN_EXPLORER |
+                      OFN_ENABLESIZING);
+        ofn.set_lpfnHook(ofnHookPtr);
+    }
+
+    private void setOwner(Window w) {
+        if ((w == null) || !w.isDisplayable()) {
+            return;
+        }
+        // this also makes file dialog modal:
+        ofn.set_hwndOwner(ci.getNativeWindow(w).getId());
+    }
+
+    private void setFilter(String filter) {
+        if (filter == null) {
+            return;
+        }
+        ofn.set_lpstrFilter(nb.createInt16Pointer(filter, false));
+    }
+
+    private void setTitle(String title) {
+        if (title == null) {
+            return;
+        }
+        ofn.set_lpstrTitle(nb.createInt16Pointer(title, false));
+    }
+
+    private void setDir(String dirName) {
+        if (dirName == null) {
+            dirName = System.getProperty("user.dir");
+        }
+        ofn.set_lpstrInitialDir(nb.createInt16Pointer(dirName, false));
+    }
+
+    private void setFile(String fileName) {
+        int bufSize = 255;
+        Int16Pointer bufferPtr = nb.createInt16Pointer(bufSize, false);
+        if (fileName != null) {
+            bufferPtr.setString(fileName);
+        }
+        ofn.set_nMaxFileTitle(bufSize);
+        ofn.set_lpstrFileTitle(nb.createInt16Pointer(bufSize, false));
+        ofn.set_lpstrFile(bufferPtr);
+        ofn.set_nMaxFile(bufSize); // mandatory!
+    }
+    
+    public boolean show() {        
+        if (modal) {
+            if (EventQueue.isDispatchThread()) {
+                // need to continue dispatching events
+                // so start inner modal loop:
+                new Thread() {
+                    public void run() {
+                        show(fileDialog.getMode());
+                        ci.endModalLoop(fileDialog);
+                    }
+                }.start();
+                ci.runModalLoop(fileDialog);
+            } else {
+                // just block the calling thread:
+                show(fileDialog.getMode());
+            }
+        } else {
+            // start new thread here and
+            // return immediately(return value is useless)
+            new Thread() {
+                public void run() {
+                    show(fileDialog.getMode());
+                }
+            }.start();
+        }
+        
+        return false; // don't call super(Dialog).show()
+    }
+
+    private String getExtendedError(int code) {
+        switch (code) {
+        case CDERR_GENERALCODES:
+            return "general";
+        case CDERR_STRUCTSIZE:
+            return "structure size";
+        case CDERR_INITIALIZATION:
+            return "init";
+        case CDERR_NOTEMPLATE:
+            return "no template";
+        case CDERR_NOHINSTANCE:
+            return "no hInstance";
+        case CDERR_LOADSTRFAILURE:
+            return "load string failure";
+        case CDERR_FINDRESFAILURE:
+            return "find resource failure";
+        case CDERR_LOADRESFAILURE:
+            return "load resource failure";
+        case CDERR_LOCKRESFAILURE:
+            return "lock resource failure";
+        case CDERR_MEMALLOCFAILURE:
+            return "mem alloc failure";
+        case CDERR_MEMLOCKFAILURE:
+            return "mem lock failure";
+        case CDERR_NOHOOK:
+            return "no hook";
+        }
+        return "unknown";
+    }
+    
+    private void postEvent(AWTEvent e) {
+        Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(e);
+    }
+    
+    public long close() {
+        ci.setVisibleFlag(fileDialog, false);
+        fd2win.remove(fileDialog);
+        // should post IDABORT, but it doesn't work for some reason
+        // so use IDCANCEL as a workaround
+        long res = win32.PostMessageW(hwnd, WM_COMMAND, IDCANCEL, 0);
+        
+        if (res == 0) {
+            System.err.println("error:" + win32.GetLastError());
+        }
+        return res;
+    }
+}

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/theme/windows/WinTheme.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/theme/windows/WinTheme.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/theme/windows/WinTheme.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/theme/windows/WinTheme.java Wed Sep  6 09:06:15 2006
@@ -19,6 +19,7 @@
  */
 package org.apache.harmony.awt.theme.windows;
 
+import java.awt.FileDialog;
 import java.awt.Graphics;
 import java.awt.Rectangle;
 
@@ -87,4 +88,19 @@
         WinTextComponent.drawBackground(g, s, this);
     }
 
+    public boolean showFileDialog(FileDialog fd) {
+        WinFileDialog dlg = WinFileDialog.getInstance(fd);
+        if (dlg == null) {
+            dlg = new WinFileDialog(fd);
+        }                
+        return dlg.show();
+    }
+
+    public boolean hideFileDialog(FileDialog fd) {
+        WinFileDialog dlg = WinFileDialog.getInstance(fd);
+        if (dlg != null) {
+            dlg.close();
+        }
+        return false;
+    }
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/wtk/windows/WinCursor.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/wtk/windows/WinCursor.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/wtk/windows/WinCursor.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/wtk/windows/WinCursor.java Wed Sep  6 09:06:15 2006
@@ -24,24 +24,32 @@
 public class WinCursor implements NativeCursor {
     final long hCursor;
 
+    final WinEventQueue eventQueue;
+
   /*is this a system cursor?(such cursors are shared and can't be destroyed
           by user*/
     final boolean system;
 
-    WinCursor(final long handle, final boolean system) {
+    WinCursor(WinEventQueue eventQueue, final long handle, final boolean system) {
         hCursor = handle;
         this.system = system;
+        this.eventQueue = eventQueue;
     }
 
-    WinCursor(final long handle) {
-        this(handle, true); //create system(predefined) cursors by default
+    WinCursor(WinEventQueue eventQueue, final long handle) {
+        this(eventQueue, handle, true); //create system(predefined) cursors by default
     }
 
     /**
      * @see org.apache.harmony.awt.wtk.NativeCursor#setCursor()
      */
     public void setCursor(long winID) {
-        WinEventQueue.win32.SetCursor(hCursor);
+        WinEventQueue.Task task = new WinEventQueue.Task() {
+            public void perform() {
+                WinEventQueue.win32.SetCursor(hCursor);
+            }
+        };
+        eventQueue.performTask(task);
     }
 
     /**

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/wtk/windows/WinCursorFactory.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/wtk/windows/WinCursorFactory.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/wtk/windows/WinCursorFactory.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/wtk/windows/WinCursorFactory.java Wed Sep  6 09:06:15 2006
@@ -31,39 +31,45 @@
 /**
  * Implementation of CursorFactory for Windows platform.
  */
-public class WinCursorFactory extends CursorFactory implements WindowsDefs {
+public class WinCursorFactory extends CursorFactory {
 
     static final Win32 win32 = Win32.getInstance();
 
+    final WinEventQueue eventQueue;
+
     /**
      * Java to native type translation table:
      * native id for LoadCursor(commented native id for LoadImage(from winuser.h)),
      * commented Java cursor type
      */
     static final long [] predefined = {
-            IDC_ARROW/*OCR_NORMAL*/, /*DEFAULT_CURSOR*/
-            IDC_CROSS/*OCR_CROSS*/, /*CROSSHAIR_CURSOR*/
-            IDC_IBEAM/*OCR_IBEAM*/, /*TEXT_CURSOR*/
-            IDC_WAIT /*OCR_WAIT*/, /*WAIT_CURSOR*/
-            IDC_SIZENESW/*OCR_SIZENESW*/, /*SW_RESIZE_CURSOR*/
-            IDC_SIZENWSE/*OCR_SIZENWSE*/, /*SE_RESIZE_CURSOR*/
-            IDC_SIZENWSE/*OCR_SIZENWSE*/, /*NW_RESIZE_CURSOR*/
-            IDC_SIZENESW/*OCR_SIZENESW*/, /*NE_RESIZE_CURSOR*/
-            IDC_SIZENS/*OCR_SIZENS*/, /*N_RESIZE_CURSOR*/
-            IDC_SIZENS/*OCR_SIZENS*/, /*S_RESIZE_CURSOR*/
-            IDC_SIZEWE/*OCR_SIZEWE*/, /*W_RESIZE_CURSOR*/
-            IDC_SIZEWE/*OCR_SIZEWE*/, /*E_RESIZE_CURSOR*/
-            IDC_HAND/*OCR_HAND*/, /*HAND_CURSOR*/
-            IDC_SIZEALL/*OCR_SIZEALL*/, /*MOVE_CURSOR*/
+            WindowsDefs.IDC_ARROW/*OCR_NORMAL*/, /*DEFAULT_CURSOR*/
+            WindowsDefs.IDC_CROSS/*OCR_CROSS*/, /*CROSSHAIR_CURSOR*/
+            WindowsDefs.IDC_IBEAM/*OCR_IBEAM*/, /*TEXT_CURSOR*/
+            WindowsDefs.IDC_WAIT /*OCR_WAIT*/, /*WAIT_CURSOR*/
+            WindowsDefs.IDC_SIZENESW/*OCR_SIZENESW*/, /*SW_RESIZE_CURSOR*/
+            WindowsDefs.IDC_SIZENWSE/*OCR_SIZENWSE*/, /*SE_RESIZE_CURSOR*/
+            WindowsDefs.IDC_SIZENWSE/*OCR_SIZENWSE*/, /*NW_RESIZE_CURSOR*/
+            WindowsDefs.IDC_SIZENESW/*OCR_SIZENESW*/, /*NE_RESIZE_CURSOR*/
+            WindowsDefs.IDC_SIZENS/*OCR_SIZENS*/, /*N_RESIZE_CURSOR*/
+            WindowsDefs.IDC_SIZENS/*OCR_SIZENS*/, /*S_RESIZE_CURSOR*/
+            WindowsDefs.IDC_SIZEWE/*OCR_SIZEWE*/, /*W_RESIZE_CURSOR*/
+            WindowsDefs.IDC_SIZEWE/*OCR_SIZEWE*/, /*E_RESIZE_CURSOR*/
+            WindowsDefs.IDC_HAND/*OCR_HAND*/, /*HAND_CURSOR*/
+            WindowsDefs.IDC_SIZEALL/*OCR_SIZEALL*/, /*MOVE_CURSOR*/
 
     };
+
+    WinCursorFactory(WinEventQueue eventQueue) {
+        this.eventQueue = eventQueue;
+    }
     /**
      * @see org.apache.harmony.awt.wtk.CursorFactory#createCursor(int)
      */
     public NativeCursor createCursor(int type) {
         if (type >= 0 && type < predefined.length) {
             long hCursor = win32.LoadCursorW(0l, predefined[type]);
-            return new WinCursor(hCursor);
+            return new WinCursor(eventQueue, hCursor);
         }
         return null;
     }
@@ -73,15 +79,15 @@
      */
     public NativeCursor createCustomCursor(Image img, int xHotSpot, int yHotSpot) {
         long hCursor = WinIcons.createIcon(false, img, xHotSpot, yHotSpot);
-        return new WinCursor(hCursor, false);
+        return new WinCursor(eventQueue, hCursor, false);
     }
 
     /**
      * @see org.apache.harmony.awt.wtk.CursorFactory#getBestCursorSize(int, int)
      */
     public Dimension getBestCursorSize(int prefWidth, int prefHeight) {
-        return new Dimension(win32.GetSystemMetrics(SM_CXCURSOR),
-                win32.GetSystemMetrics(SM_CYCURSOR));
+        return new Dimension(win32.GetSystemMetrics(WindowsDefs.SM_CXCURSOR),
+                win32.GetSystemMetrics(WindowsDefs.SM_CYCURSOR));
     }
 
     /**
@@ -89,11 +95,11 @@
      */
     public int getMaximumCursorColors() {
         long screenDC = win32.GetDC(0);
-        int nColors = win32.GetDeviceCaps(screenDC, NUMCOLORS);
+        int nColors = win32.GetDeviceCaps(screenDC, WindowsDefs.NUMCOLORS);
         if (nColors < 0) {
             //if device has more than 256 colors:
             final int COLORS_PER_PLANE = 256;
-            int nPlanes = win32.GetDeviceCaps(screenDC, PLANES);
+            int nPlanes = win32.GetDeviceCaps(screenDC, WindowsDefs.PLANES);
             nColors = COLORS_PER_PLANE * nPlanes;
         }
         win32.ReleaseDC(0, screenDC);

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/wtk/windows/WinEvent.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/wtk/windows/WinEvent.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/wtk/windows/WinEvent.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/wtk/windows/WinEvent.java Wed Sep  6 09:06:15 2006
@@ -121,10 +121,10 @@
         return lastChar;
     }
 
-    WinEvent(long hwnd, int msg, long wParam, long lParam,
-            long lastTime, StringBuffer lastTranslation, char lastChar, WinEventQueue proxy)
+    WinEvent(long hwnd, int msg, long wParam, long lParam, long lastTime, 
+             StringBuffer lastTranslation, char lastChar, WinWindowFactory factory)
     {
-        factory = proxy.factory;
+        this.factory = factory;
         this.windowId = hwnd;
         this.msg = msg;
         this.wParam = wParam;
@@ -137,13 +137,14 @@
         this.lastChar = lastChar;
         eventId = ID_PLATFORM;
 
-        if (hwnd == proxy.getJavaWindow()) {
+        if (hwnd == factory.eventQueue.getJavaWindow()) {
             if ((msg == WM_THEMECHANGED) || (msg == WM_SYSCOLORCHANGE)
                     || (msg == WM_SETTINGCHANGE)) {
-                // TODO: handle this
+                // TODO: handle this                
 
                 if (msg == WM_THEMECHANGED) {
                     factory.eventQueue.getThemeMap().refresh();
+                    factory.eventQueue.systemProperties.getXPTheme(null);
                 }
                 eventId = ID_THEME_CHANGED;
             }
@@ -160,6 +161,7 @@
             processFocus(msg);
         } else if (msg == WM_PAINT) {
             eventId = PaintEvent.PAINT;
+            processPaint();
         } else if (msg == WM_SIZE) {
             processSize();
         } else if (msg == WM_MOVE) {
@@ -174,16 +176,20 @@
             }
         } else if (msg == WM_CREATE) {
             eventId = ID_CREATED;
-        } else if (msg == WM_AWAKE) {
-            eventId = ID_JAVA_EVENT;
         } else if (msg == WM_SHOWWINDOW) {
             processShowWindow();
         } else if (msg == WM_STYLECHANGED) {
             processStyleChanged();
         } else if (msg == WM_THEMECHANGED) {
             processThemeChanged();
+        } else if (msg == WM_INPUTLANGCHANGEREQUEST) {
+            WinIM.onInputLangChange(lParam);
         }
     }
+    
+    public String toString() {
+        return "hwnd=0x" + Long.toHexString(windowId) + ", msg=0x" + Integer.toHexString(msg);
+    }
 
     private void processChar() {
         keyInfo.keyChars.setLength(0);
@@ -295,6 +301,10 @@
             }
         }
 
+    }
+    
+    private void processPaint() {
+        getClipRects();
     }
 
     private MultiRectArea decodeComplexRgn(long hRgn, int dx, int dy) {

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/wtk/windows/WinEventQueue.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/wtk/windows/WinEventQueue.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/wtk/windows/WinEventQueue.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/wtk/windows/WinEventQueue.java Wed Sep  6 09:06:15 2006
@@ -31,16 +31,19 @@
 import org.apache.harmony.awt.nativebridge.windows.Win32;
 import org.apache.harmony.awt.nativebridge.windows.WindowsDefs;
 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.misc.accessors.AccessorFactory;
+import org.apache.harmony.misc.accessors.ObjectAccessor;
 
 /**
  * Handler of Windows messages
  */
-public class WinEventQueue implements NativeEventQueue {
+public class WinEventQueue extends NativeEventQueue {
+    
     static final NativeBridge bridge = NativeBridge.getInstance();
     static final Win32 win32 = Win32.getInstance();
+    static final ObjectAccessor objAccessor = AccessorFactory.getObjectAccessor();
 
     /**
      * Invisible auxlitary window for service messages
@@ -56,13 +59,7 @@
      */
     private final Win32.MSG lastMsg = win32.createMSG(false);
 
-    /**
-     * Callback to EventDispatchThread
-     */
-    private NativeEventListener listener;
-
     final int dispatchThreadID = win32.GetCurrentThreadId();
-    final Thread dispatchThread = Thread.currentThread();
     final WinSystemProperties systemProperties;
 
     /**
@@ -85,28 +82,15 @@
 
     final WinWindowFactory factory;
 
-    /**
-     * Levels of re-entrant windowProc() calls, saved/restored 
-     * when entering/leaving nested modal loops
-     */
-    private LinkedList nestingEndsStack;
-    /**
-     * Level of re-entrant windowProc() calls for current modal loop. 
-     * For main modal loop it is zero.
-     */
-    private int curNestingEnd;
-    private boolean empty;
-    /**
-     * Current level of re-entrant windowProc() calls
-     */
-    private int msgNestingCnt;
-
     private long utcOffset = -1;
     /**
      * Return value for the Windows message being processed
      */
     private final long[] result = new long[1];
 
+    public static final int WM_PERFORM_TASK = WindowsDefs.WM_USER + 1;
+    public static final int WM_PERFORM_LATER = WindowsDefs.WM_USER + 2;
+
     private LinkedList preprocessors = new LinkedList();
 
     /**
@@ -115,12 +99,6 @@
      */
     public WinEventQueue(WinSystemProperties systemProperties) {
         this.systemProperties = systemProperties;
-        // Force create EventQueue
-        win32.PeekMessageW(lastMsg, 0, WindowsDefs.WM_USER, WindowsDefs.WM_USER, WindowsDefs.PM_NOREMOVE);
-
-        empty = true;
-        msgNestingCnt = 0;
-        nestingEndsStack = new LinkedList();
 
         WindowProcHandler.registerCallback();
         factory = new WinWindowFactory(this);
@@ -140,8 +118,6 @@
     public boolean waitEvent() {
         win32.GetMessageW(lastMsg, 0, 0, 0);
 
-        empty = (win32.PeekMessageW(0, 0, 0, 0, WindowsDefs.PM_NOREMOVE) == 0);
-
         return lastMsg.get_message() != WindowsDefs.WM_QUIT;
     }
 
@@ -153,7 +129,6 @@
         if (win32.GetCurrentThreadId() != dispatchThreadID) {
             win32.PostThreadMessageW(dispatchThreadID, WinEvent.WM_AWAKE, 0, 0);
         }
-        listener.onAwake();
     }
 
     /**
@@ -161,24 +136,9 @@
      * @param msg - the Windows message
      */
     private void processThreadMessage(Win32.MSG msg) {
-        callListener(0, msg.get_message(), msg.get_wParam(), msg.get_lParam());
+        handleEvent(0, msg.get_message(), msg.get_wParam(), msg.get_lParam());
     }
-
-    /**
-     * Indirectly call the windowProc() to handle the message being processed.
-     * Also translate keyboard messages before calling windowProc()
-     * @return - the value returned by windowProc()
-     */
-    public long dispatchEventToListener() {
-        if (lastMsg.get_hwnd() == 0) {
-            processThreadMessage(lastMsg);
-            return 0;
-        }
-
-        translateMessage(lastMsg);
-        return win32.DispatchMessageW(lastMsg);
-    }
-
+    
     /**
      * Translate key code to typed character for keyboard messages,
      * do nothing for all other messages
@@ -244,7 +204,7 @@
         if (preProcessMessage(hwnd, msg,  wParam, lParam, result)) {
             return result[0];
         }
-        if (callListener(hwnd, msg,  wParam, lParam)) {
+        if (handleEvent(hwnd, msg,  wParam, lParam)) {
             return 0;
         }
 
@@ -254,27 +214,7 @@
         return win32.DefWindowProcW(hwnd, msg, wParam, lParam);
     }
 
-    /**
-     * Call native event listener, pass the native event constructed from
-     * the following parameters 
-     * @param hwnd - window handle
-     * @param msg - message code
-     * @param wParam - first message-dependent parameter
-     * @param lParam - second message-dependent parameter
-     * @return - false if the default Windows handler should be called; 
-     *  true otherwise 
-     */
-    private boolean callListener(long hwnd, int msg, long wParam, long lParam) {
-        if (listener == null) {
-            // not intialized yet
-            if (msg == WindowsDefs.WM_CREATE) {
-                // we must return true for WM_CREATE
-                // to continue window creation
-                return true;
-            }
-            return false;
-        }
-
+    private boolean handleEvent(long hwnd, int msg, long wParam, long lParam) {
         if (msg == WindowsDefs.WM_KEYUP || msg == WindowsDefs.WM_SYSKEYUP) {
             Character ch = (Character)keyCodeToChar.remove(new Integer((int)wParam));
             if (ch != null) {
@@ -284,47 +224,21 @@
             }
         }
 
-        WinEvent decoder = new WinEvent(hwnd, msg, wParam,
+        WinEvent event = new WinEvent(hwnd, msg, wParam,
                 lParam, utcOffset + lastMsg.get_time(),
-                lastTranslation, lastChar, this);
-
-        msgNestingCnt++;
-        listener.onEventBegin();
-        try {
-            if ((decoder.getEventId() != NativeEvent.ID_PLATFORM) &&
-                    (decoder.getEventId() != NativeEvent.ID_JAVA_EVENT))
-            {
-                return listener.onEvent(decoder);
-            }
-            return false;
-        } finally {
-            listener.onEventEnd();
-
-            if (msgNestingCnt == curNestingEnd) {
-                listener.onEventNestingEnd();
-            }
-            msgNestingCnt--;
+                lastTranslation, lastChar, factory);
+        if (event.getEventId() != NativeEvent.ID_PLATFORM) {
+            addEvent(event);
+            return !isKeyUpOrKeyDownMessage(msg);
         }
+        return false;
     }
 
-    /**
-     * Enter nested modal loop
-     */
-    public void onModalLoopBegin() {
-        curNestingEnd = msgNestingCnt + 1;
-        nestingEndsStack.addLast(new Integer(curNestingEnd));
-    }
-
-    /**
-     * Leave nested modal loop
-     */
-    public void onModalLoopEnd() {
-        nestingEndsStack.removeLast();
-        if ( !nestingEndsStack.isEmpty()) {
-            curNestingEnd = ((Integer) nestingEndsStack.getLast()).intValue();
-        } else {
-            curNestingEnd = -1;
-        }
+    private boolean isKeyUpOrKeyDownMessage(int msg) {
+        return msg == WindowsDefs.WM_KEYDOWN 
+            || msg == WindowsDefs.WM_KEYUP 
+            || msg == WindowsDefs.WM_SYSKEYDOWN 
+            || msg == WindowsDefs.WM_SYSKEYUP;
     }
 
     /**
@@ -339,6 +253,18 @@
      * @return - false if the default Windows handler should be called; 
      */
     private boolean preProcessMessage(long hwnd, int msg, long wParam, long lParam, long[] result) {
+        if (msg == WM_PERFORM_TASK && hwnd == javaWindow) {
+            Task t = (Task)objAccessor.getObjectFromReference(lParam);
+            t.perform();
+            return true;
+        }
+        
+        if (msg == WM_PERFORM_LATER && hwnd == javaWindow) {
+            Task t = (Task)objAccessor.getObjectFromReference(lParam);
+            t.perform();
+            objAccessor.releaseGlobalReference(lParam);
+            return true;
+        }
         for (Iterator i = preprocessors.iterator(); i.hasNext(); ) {
             if (((Preprocessor) i.next()).preprocess(hwnd, msg, wParam, lParam, result)) {
                 return true;
@@ -364,6 +290,29 @@
                 return true;
             }
             break;
+            
+        case WindowsDefs.WM_ACTIVATE:
+            if (wParam == WindowsDefs.WA_ACTIVE) {
+                // while activation of Frame/Dialog
+                // [actually focus transfer to focusProxy] is in progress
+                // skip all focus events related to windows being activated/deactivated,
+                // such spurious events are sometimes generated by Win32
+                WinWindow ownd = (WinWindow) factory.getWindowById(lParam);
+                long hOwner = lParam;
+                // find nearest decorated ancestor window of
+                // the window being deactivated
+                while ((ownd != null) && ownd.undecorated) {
+                    hOwner = win32.GetParent(hOwner);
+                    ownd = (WinWindow) factory.getWindowById(hOwner);
+                }
+                // cancel focus only if
+                // this is the window found
+                if ((ownd != null) && (hOwner == hwnd)) {
+                    result[0] = 0;
+                    return true;
+                }
+            }
+            break;
 
         case WindowsDefs.WM_SETCURSOR:
             short htCode = (short) lParam;
@@ -398,28 +347,30 @@
                 systemProperties.resetSystemColors();
             }
             break;
+            
+        case WindowsDefs.WM_SETTINGCHANGE:
+            systemProperties.processSettingChange(wParam);
+            break;
+        case WindowsDefs.WM_IME_STARTCOMPOSITION:            
+            return WinIM.onStartComposition(hwnd);
+        case WindowsDefs.WM_IME_SETCONTEXT:
+            if (wParam != 0l) {
+                return WinIM.onActivateContext(hwnd);
+            }
+            break;
+        case WindowsDefs.WM_IME_COMPOSITION:
+            WinIM.onComposition(hwnd, lParam);
+            break;
         }
 
+        
         return false;
     }
 
-    public void setNativeEventListener(NativeEventListener e) {
-        listener = e;
-    }
-
-    public boolean isEmpty() {
-        return empty;
-    }
-
     public ThemeMap getThemeMap() {
         return themeMap;
     }
 
-    NativeServer getNativeServer() {
-        // TODO: obtain NativeServer in more elegant way
-        return (NativeServer)((NativeEventListener) dispatchThread).getSynchronizer();
-    }
-
     /**
      * create invisible auxlitary window to listen to the service messages
      * @return HWND of created window
@@ -531,5 +482,25 @@
                 e.setValue(new Long(hTheme));
             }
         }
+    }
+
+    public void dispatchEvent() {
+        if (lastMsg.get_hwnd() == 0) {
+            processThreadMessage(lastMsg);
+        }
+        
+        translateMessage(lastMsg);
+        win32.DispatchMessageW(lastMsg);
+    }
+
+    public void performTask(Task task) {
+        long ref = objAccessor.getGlobalReference(task);
+        win32.SendMessageW(javaWindow, WM_PERFORM_TASK, 0, ref);
+        objAccessor.releaseGlobalReference(ref);
+    }
+
+    public void performLater(Task task) {
+        long ref = objAccessor.getGlobalReference(task);
+        win32.PostMessageW(javaWindow, WM_PERFORM_LATER, 0, ref);
     }
 }

Added: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/wtk/windows/WinIM.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/wtk/windows/WinIM.java?view=auto&rev=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/wtk/windows/WinIM.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/wtk/windows/WinIM.java Wed Sep  6 09:06:15 2006
@@ -0,0 +1,394 @@
+/*
+ *  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 Dmitry A. Durnev
+ * @version $Revision$
+ */
+package org.apache.harmony.awt.wtk.windows;
+
+import java.awt.AWTException;
+import java.awt.im.spi.InputMethod;
+import java.util.HashMap;
+import java.util.Locale;
+
+import org.apache.harmony.awt.ContextStorage;
+import org.apache.harmony.awt.im.IMManager;
+import org.apache.harmony.awt.im.InputMethodContext;
+import org.apache.harmony.awt.nativebridge.Int16Pointer;
+import org.apache.harmony.awt.nativebridge.Int8Pointer;
+import org.apache.harmony.awt.nativebridge.NativeBridge;
+import org.apache.harmony.awt.nativebridge.PointerPointer;
+import org.apache.harmony.awt.nativebridge.windows.Win32;
+import org.apache.harmony.awt.wtk.NativeIM;
+
+import org.apache.harmony.awt.nativebridge.windows.WindowsDefs;
+
+/**
+ * Windows-specific native input method
+ * functionality
+ */
+public class WinIM extends NativeIM {
+    
+    private static final NativeBridge nb = NativeBridge.getInstance();
+    private static final Win32 win32 = Win32.getInstance();
+    private static WinWindowFactory wwf = (WinWindowFactory) ContextStorage.getWindowFactory();
+    private static HashMap hkl2Locale = new HashMap();;
+    private static HashMap locale2HKL = new HashMap();
+    private Locale curLocale; // last locale set by user
+    private long hIMC; // private native input context handle
+    private long defaultIMC;
+    
+    
+    WinIM() {
+        WinEventQueue.Task task = new WinEventQueue.Task() {
+            public void perform() {
+                hIMC = win32.ImmCreateContext();
+            }
+        };
+        wwf.eventQueue.performTask(task);
+    }
+
+    public Locale[] getAvailableLocales() throws AWTException {
+        int nBuff = win32.GetKeyboardLayoutList(0, null);
+        PointerPointer buffPtr = nb.createPointerPointer(nBuff, false);
+        nBuff = win32.GetKeyboardLayoutList(nBuff, buffPtr);
+        for (int i = 0; i < nBuff; i++) {
+            long hkl = buffPtr.getElementPointer(i).getAddress(0);
+            hkl2Locale(hkl);
+        }
+        
+        return (Locale[]) locale2HKL.keySet().toArray(new Locale[0]);
+    }
+    
+    public boolean setLocale(final Locale locale) {
+        if (getLocale().equals(locale)) {
+            curLocale = locale;
+            return true;
+        }
+        WinEventQueue.Task task = new WinEventQueue.Task () {
+            public void perform() {
+                long hkl = locale2HKL(locale);
+                int flags = 0;
+                boolean res = (win32.ActivateKeyboardLayout(hkl, flags) != 0);
+                returnValue = Boolean.valueOf(res);
+            }
+        };         
+        wwf.eventQueue.performTask(task);
+        boolean result = ((Boolean)task.returnValue).booleanValue();
+        if (result) {
+            curLocale = locale;
+        }
+        return result;
+    }
+    
+    public Locale getLocale() {
+       
+        WinEventQueue.Task task = new WinEventQueue.Task () {
+            public void perform() {
+                returnValue =  new Long(win32.GetKeyboardLayout(0));                
+            }
+        };         
+        wwf.eventQueue.performTask(task);
+        Long hkl = (Long) task.returnValue;        
+        return hkl2Locale(hkl.longValue());
+    }
+    
+    private static int makeLCID(short langid, short sortid) {
+        return ((sortid << 16) | langid);
+        
+    }
+    
+    private static String getLocaleInfo(int lcid, int lcType) {
+        int size = 6;
+        Int16Pointer lpLCData = nb.createInt16Pointer(size, false);
+        size = win32.GetLocaleInfoW(lcid, lcType, lpLCData, size);
+        return lpLCData.getString();
+    }
+
+    /**
+     * convert LANGID(16 low-order bits of HKL) into Locale instance
+     */
+    private static Locale hkl2Locale(long hkl) {
+        Long key = new Long(hkl);
+        if (hkl2Locale.containsKey(key)) {
+            return (Locale) hkl2Locale.get(key);
+        }
+        short langid = (short) hkl;
+        short sortid = WindowsDefs.SORT_DEFAULT;        
+        int lcid = makeLCID(langid, sortid);        
+        String country = getLocaleInfo(lcid, WindowsDefs.LOCALE_SISO3166CTRYNAME);
+        String language = getLocaleInfo(lcid, WindowsDefs.LOCALE_SISO639LANGNAME);
+        Locale locale = new Locale(language, country);
+        hkl2Locale.put(key, locale);
+        locale2HKL.put(locale, key);
+        return locale;
+    }
+    
+  /**
+   * convert Locale instance to HKL
+   * 
+   * @param locale Locale to get HKL for
+   * @return HKL identifier of the given locale
+   */
+    private static long locale2HKL(Locale locale) {
+        // there's no native functionality to get
+        // lcid from locale name
+        // maybe have to call getAvailableLocales()
+        // before to update map(?)
+        Long hkl = (Long) locale2HKL.get(locale);
+        if (hkl != null) {
+            return hkl.longValue();
+        }
+        return 0l;
+    }
+    
+    /**
+     * Must create new instance of this IM for
+     * every instance of input context
+     */
+    public InputMethod createInputMethod() throws Exception {
+        return new WinIM();
+    }
+    
+    public void activate() {
+        // reassociate focused window with
+        // default native input context
+        // if IME was previously disabled
+        WinEventQueue.Task task = new WinEventQueue.Task() {
+            public void perform() {
+                final long hwnd = win32.GetFocus();
+                if (hwnd == 0l) {
+                    return;
+                }
+                long curIMC = win32.ImmGetContext(hwnd);
+                if ((curIMC != 0) && isActiveClient()) {
+                    //  close composition window
+                    // opened by passive client
+                    win32.ImmSetOpenStatus(curIMC, 0);
+                }
+                if (curIMC != hIMC) {                    
+                    long res = win32.ImmAssociateContext(hwnd, hIMC);
+                    
+                    if (res != 0l) {
+                        defaultIMC = res;
+                    }
+                    returnValue = new Long(res);
+                  
+
+                } else {
+                    // have to change input context on every
+                    // activation to be able to process IME
+                    // messages without showing default composition
+                    // window for active clients
+                    
+                    win32.ImmAssociateContext(hwnd, defaultIMC);
+                }
+                
+                win32.ImmReleaseContext(hwnd, curIMC);
+            }
+            
+        };
+        wwf.eventQueue.performTask(task);
+
+        if (curLocale != null)  {
+            setLocale(curLocale);
+        }
+    }    
+    
+    /**
+     * Is called before the IME generates the composition string
+     *  as a result of a keystroke.
+     * @param hwnd owner of the composition window
+     * @return false if the default composition window
+     * should be opened, true otherwise
+     */
+    static boolean onStartComposition(long hwnd) {
+        long hIMC = win32.ImmGetContext(hwnd);
+        boolean active = isActiveClient();
+        
+        if ((hIMC != 0l) && !active) {
+            setDefaultCompositionWindow(hIMC);
+        }
+        win32.ImmReleaseContext(hwnd, hIMC);
+        return active;
+    }
+    
+    /**
+     * Is called when IME composition string changes
+     * @param hwnd window where composition occurs
+     * @param idx specifies how the composition string changed
+     * @return true if message was processed by IM and
+     * no default processing is required
+     */
+    static boolean onComposition(long hwnd, long idx) {
+        // TODO: convert composition string change event
+        // to Java InputMethodEvent and dispatch it
+        // to active client(or post it to the EventQueue?)
+        long hIMC = win32.ImmGetContext(hwnd);        
+        
+        if (hIMC != 0l) {
+            if ((idx & WindowsDefs.GCS_COMPATTR) != 0) {
+                int size=0;
+                size = win32.ImmGetCompositionStringW(hIMC, WindowsDefs.GCS_COMPATTR,
+                                                      0l, size);
+                size += 2; // 0-terminator
+
+                Int8Pointer lpBuf = nb.createInt8Pointer(size, false);                
+                win32.ImmGetCompositionStringW(hIMC, WindowsDefs.GCS_COMPATTR,
+                                               lpBuf, size);
+                System.out.print("attrs:");
+                processAttributes(size - 2, lpBuf);
+            }
+            if ((idx & WindowsDefs.GCS_COMPCLAUSE) != 0) {
+            }
+            if ((idx & WindowsDefs.GCS_COMPREADATTR) != 0) {
+            }
+            if ((idx & WindowsDefs.GCS_COMPREADCLAUSE) != 0) {
+            }
+            if ((idx & WindowsDefs.GCS_COMPREADSTR) != 0) {
+            }
+            if ((idx & WindowsDefs.GCS_COMPSTR) != 0) {
+            }
+            if ((idx & WindowsDefs.GCS_CURSORPOS) != 0) {
+            }
+            if ((idx & WindowsDefs.GCS_DELTASTART) != 0) {
+            }
+            if ((idx & WindowsDefs.GCS_RESULTCLAUSE) != 0) {
+            }
+            if ((idx & WindowsDefs.GCS_RESULTREADCLAUSE) != 0) {
+            }
+            if ((idx & WindowsDefs.GCS_RESULTREADSTR) != 0) {
+            }
+            if ((idx & WindowsDefs.GCS_RESULTSTR) != 0) {
+            }
+        }
+        win32.ImmReleaseContext(hwnd, hIMC);
+        return isActiveClient();
+    }
+
+    private static void processAttributes(int size, Int8Pointer lpBuf) {
+        // TODO: convert windows IM attributes to 
+        // AttributedCharacterIterator attributes
+        for (int i=0; i < size; i++) {
+            byte attr = lpBuf.get(i);
+            String strAttr = "";
+            switch(attr) {
+            case WindowsDefs.ATTR_INPUT:
+                strAttr = "INP";
+                break;
+            case WindowsDefs.ATTR_INPUT_ERROR:
+                strAttr = "IE";
+                break;
+            case WindowsDefs.ATTR_TARGET_CONVERTED:
+                strAttr = "T_CONV";
+                break;
+            case WindowsDefs.ATTR_CONVERTED:
+                strAttr = "CONV";
+                break;
+            case WindowsDefs.ATTR_TARGET_NOTCONVERTED:
+                strAttr = "T_NCONV";
+                break;
+            case WindowsDefs.ATTR_FIXEDCONVERTED:
+                strAttr = "FIX_CONV";
+                break;                        
+            }
+            System.out.print( strAttr + ",");
+        }
+        System.out.println();
+    }
+
+    
+    /**
+     *  sets IME composition window position/style
+     *  for passive clients
+     */
+    private static int setDefaultCompositionWindow(long hIMC) {
+        Win32.COMPOSITIONFORM form = win32.createCOMPOSITIONFORM(false);
+        form.set_dwStyle(WindowsDefs.CFS_DEFAULT);
+        return win32.ImmSetCompositionWindow(hIMC, form);
+    }
+    
+    public void removeNotify() {
+        disableIME();
+    }
+    
+    public void dispose() {
+        WinEventQueue.Task task = new WinEventQueue.Task() {
+            public void perform() {
+                win32.ImmDestroyContext(hIMC);
+            }
+        };
+        wwf.eventQueue.performTask(task);
+    }
+    
+    /**
+     * Disables native input method support for the
+     * focused window
+     */
+    public void disableIME() {        
+        WinEventQueue.Task task = new WinEventQueue.Task () {
+            public void perform() {
+                final long hwnd = win32.GetFocus();
+                long curIMC = win32.ImmGetContext(hwnd); 
+                if (curIMC != 0l) {
+                    win32.ImmAssociateContext(hwnd, 0l);
+                }
+                win32.ImmReleaseContext(hwnd, curIMC);
+                returnValue = new Long(hwnd);
+            }
+        
+        };        
+        wwf.eventQueue.performTask(task);
+    }
+    
+    /**
+     * Is called when user chooses the new input language via
+     * native system interface, i. e. with the hotkey or
+     * from the indicator on the system taskbar.
+     */
+    static void onInputLangChange(long lcid) {
+        // remember the new locale as selected in the
+        // input context of the focused component
+        InputMethodContext imc = IMManager.getLastActiveIMC();
+        if (imc == null) {
+            return;
+        }
+        InputMethod im = imc.getInputMethod();
+        if (im instanceof NativeIM) {
+            im.setLocale(hkl2Locale(lcid));
+        }
+
+    }
+    
+    private static boolean isActiveClient() {
+        InputMethodContext imc = IMManager.getLastActiveIMC();
+        if ((imc == null) || (imc.getClient() == null)) {
+            return false;
+        }
+        return (imc.getClient().getInputMethodRequests() != null);
+    }
+
+    /**
+     * Is called when input context is activated.
+     * @return false if IME default composition window
+     * should be activated for input context, true
+     * otherwise
+     */
+    static boolean onActivateContext(long hwnd) {
+        boolean result = isActiveClient();
+        return result;
+    }
+}

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/wtk/windows/WinRobot.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/wtk/windows/WinRobot.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/wtk/windows/WinRobot.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/wtk/windows/WinRobot.java Wed Sep  6 09:06:15 2006
@@ -50,7 +50,6 @@
 
     private final NativeBridge nb = NativeBridge.getInstance();
     private final Win32 win32 = Win32.getInstance();
-    private final long screenDC = win32.GetDC(0l);
 
     /**
      * @see org.apache.harmony.awt.wtk.NativeRobot#createScreenCapture(java.awt.Rectangle)
@@ -71,8 +70,11 @@
         // compBMP and use them to create BufferedImage
         Int32Pointer pData = nb.createInt32Pointer(size, false);
         win32.DeleteObject(compBMP);
+        long screenDC = win32.GetDC(0l);
         int nLines = win32.GetDIBits(screenDC, compBMP, 0, h, pData,
                         bmi, WindowsDefs.DIB_RGB_COLORS);
+        win32.ReleaseDC(0, screenDC);
+        
         if (nLines != h) {
             return null;
         }
@@ -87,7 +89,9 @@
      * @see org.apache.harmony.awt.wtk.NativeRobot#getPixel(int, int)
      */
     public Color getPixel(int x, int y) {
+        long screenDC = win32.GetDC(0l);
         long bgr = win32.GetPixel(screenDC, x, y);
+        win32.ReleaseDC(0, screenDC);
         return fromBGR(bgr);
     }
 
@@ -209,6 +213,7 @@
     private long createScreenBMP(Rectangle screenRect) {
         int w = screenRect.width;
         int h = screenRect.height;
+        long screenDC = win32.GetDC(0l);
         long compBMP = win32.CreateCompatibleBitmap(screenDC, w, h);
         long compDC = win32.CreateCompatibleDC(screenDC);
         // create a compatible bitmap to copy screen to
@@ -227,6 +232,7 @@
         hObj = win32.BitBlt(compDC, 0, 0, w, h,
                             screenDC, screenRect.x, screenRect.y,
                             SRCCOPY);
+        win32.ReleaseDC(0, screenDC);
         win32.ReleaseDC(0, compDC);
         return compBMP;
     }
@@ -244,7 +250,6 @@
     }
 
     protected void finalize() throws Throwable {
-        win32.ReleaseDC(0, screenDC);
         super.finalize();
     }
 

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/wtk/windows/WinSystemProperties.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/wtk/windows/WinSystemProperties.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/wtk/windows/WinSystemProperties.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/wtk/windows/WinSystemProperties.java Wed Sep  6 09:06:15 2006
@@ -14,24 +14,39 @@
  *  limitations under the License.
  */
 /**
- * @author Pavel Dolgov
+ * @author Pavel Dolgov, Dmitry A. Durnev
  * @version $Revision$
  */
 package org.apache.harmony.awt.wtk.windows;
 
+import java.awt.Color;
 import java.awt.Font;
-
+import java.awt.Toolkit;
+import java.awt.font.TextAttribute;
+import java.awt.im.InputMethodHighlight;
+import java.util.Map;
+import java.util.TreeSet;
+
+import org.apache.harmony.awt.ComponentInternals;
+import org.apache.harmony.awt.nativebridge.Int16Pointer;
+import org.apache.harmony.awt.nativebridge.NativeBridge;
 import org.apache.harmony.awt.nativebridge.windows.Win32;
 import org.apache.harmony.awt.nativebridge.windows.WindowsDefs;
 import org.apache.harmony.awt.wtk.SystemProperties;
 
 /**
  * WinSystemProperties
+ * More information about Windows Desktop Properties can be found at http://java.sun.com/j2se/1.5.0/docs/guide/swing/1.4/w2k_props.html
  */
 
 public class WinSystemProperties implements SystemProperties {
 
     private static final Win32 win32 = Win32.getInstance();
+    
+    private static final int SPI_GETFONTSMOOTHINGTYPE = 0x200A;
+    private static final int SPI_SETFONTSMOOTHINGTYPE = 0x200B;
+    private static final int SPI_GETFONTSMOOTHINGCONTRAST = 0x200C;
+    private static final int SPI_SETFONTSMOOTHINGCONTRAST = 0x200D;
 
     private static int sysColorIndices[] = {    // SystemColor.* constants
             WindowsDefs.COLOR_DESKTOP,          // 0 DESKTOP
@@ -60,8 +75,95 @@
             WindowsDefs.COLOR_SCROLLBAR,        // 23 SCROLLBAR
             WindowsDefs.COLOR_INFOBK,           // 24 INFO
             WindowsDefs.COLOR_INFOTEXT,         // 25 INFO_TEXT
+            // colors not present in SystemColor class:
+            WindowsDefs.COLOR_GRADIENTACTIVECAPTION,
+            WindowsDefs.COLOR_GRADIENTINACTIVECAPTION,
+            WindowsDefs.COLOR_HOTLIGHT,
+            WindowsDefs.COLOR_APPWORKSPACE,
+            WindowsDefs.COLOR_MENUBAR,
+    };
+    
+    private static String sysColorProps[] = { // color property names
+            "win.desktop.backgroundColor", // 0 DESKTOP
+            "win.frame.activeCaptionColor", // 1 ACTIVE_CAPTION
+            "win.frame.captionTextColor", // 2 ACTIVE_CAPTION_TEXT
+            "win.frame.activeBorderColor", // 3 ACTIVE_CAPTION_BORDER
+            "win.frame.inactiveCaptionColor", // 4 INACTIVE_CAPTION
+            "win.frame.inactiveCaptionTextColor", // 5 INACTIVE_CAPTION_TEXT
+            "win.frame.inactiveBorderColor", // 6 INACTIVE_CAPTION_BORDER
+            "win.frame.backgroundColor", // 7 WINDOW
+            "win.frame.color", //? 8 WINDOW_BORDER
+            "win.frame.textColor", // 9 WINDOW_TEXT
+            "win.menu.backgroundColor", // 10 MENU
+            "win.menu.textColor", // 11 MENU_TEXT
+            "win.frame.backgroundColor", // 12 TEXT
+            "win.frame.textColor", // 13 TEXT_TEXT
+            "win.item.highlightColor", // 14 TEXT_HIGHLIGHT
+            "win.item.highlightTextColor", // 15 TEXT_HIGHLIGHT_TEXT
+            "win.text.grayedTextColor", // 16 TEXT_INACTIVE_TEXT
+            "win.3d.backgroundColor", // 17 CONTROL
+            "win.button.textColor", // 18 CONTROL_TEXT
+            "win.3d.lightColor", // 19 CONTROL_HIGHLIGHT
+            "win.3d.highlightColor", // 20 CONTROL_LT_HIGHLIGHT
+            "win.3d.shadowColor", // 21 CONTROL_SHADOW
+            "win.3d.darkShadowColor", // 22 CONTROL_DK_SHADOW
+            "win.scrollbar.backgroundColor", // 23 SCROLLBAR
+            "win.tooltip.backgroundColor", // 24 INFO
+            "win.tooltip.textColor", // 25 INFO_TEXT
+            // colors not present in SystemColor class:
+            "win.frame.activeCaptionGradientColor",
+            "win.frame.inactiveCaptionGradientColor",
+            "win.item.hotTrackedColor",
+            "win.mdi.backgroundColor",
+            "win.menubar.backgroundColor",
     };
 
+    
+    private static int sysFontIndices[] = {
+
+        WindowsDefs.ANSI_FIXED_FONT, 
+        WindowsDefs.ANSI_VAR_FONT,                                           
+        WindowsDefs.DEFAULT_GUI_FONT,                                           
+        WindowsDefs.DEVICE_DEFAULT_FONT,                                           
+        WindowsDefs.OEM_FIXED_FONT,                                           
+        WindowsDefs.SYSTEM_FONT,                                           
+        WindowsDefs.SYSTEM_FIXED_FONT,
+    
+    };
+    
+    private static String sysFontDesktopProps[] = { // color property names
+            "win.ansiFixed.font", // 0 ANSI_FIXED_FONT
+            "win.ansiVar.font", // 1 ANSI_VAR_FONT
+            "win.defaultGUI.font", // 2 DEFAULT_GUI_FONT
+            "win.deviceDefault.font", // 3 DEVICE_DEFAULT_FONT            
+            "win.oemFixed.font", // 4 OEM_FIXED_FONT            
+            "win.system.font", // 5 SYSTEM_FONT
+            "win.systemFixed.font", // 6 SYSTEM_FIXED_FONT            
+    };    
+
+    private class WinPlaySound implements Runnable {
+        final String sndName;
+        
+        WinPlaySound(String snd) {
+            sndName = snd;            
+        }
+        
+        public void run() {
+            final int flags = (WindowsDefs.SND_ALIAS | WindowsDefs.SND_SYNC |
+                               WindowsDefs.SND_NODEFAULT);
+            // have to start another thread to wait until playing ends
+            new Thread() {
+                public void run() {                    
+                    win32.PlaySoundW(sndName, 0, flags);
+                }
+            }.start();
+        }
+        
+        public String toString() {
+            return ("WinPlaySound(" + sndName + ")");
+        }
+    };
+    
     private int sysColorCache[] = null;
 
     private Font defaultFont;
@@ -80,9 +182,11 @@
     void resetSystemColors() {
         synchronized (cacheLock) {
             sysColorCache = null;
+            updateColorCache();
+            updateColorDesktopProperties(null);
         }
-    }
-
+    }   
+    
     private void updateColorCache() {
         sysColorCache = new int[sysColorIndices.length];
         for (int i=0; i<sysColorIndices.length; i++) {
@@ -92,29 +196,362 @@
             int g = (bgr & 0xFF00);
             int r = (bgr & 0xFF) << 16;
             sysColorCache[i] = (0xFF000000 | r | g | b);
+            
         }
     }
 
+    private void updateColorDesktopProperties(Map props) {
+        for (int i = 0; i < sysColorIndices.length; i++) {
+            String name = sysColorProps[i];
+            Color val = new Color(sysColorCache[i]);
+            
+            setDesktopProperty(name, val, props);
+        }
+    }
+
+    private void setDesktopProperty(String name, Object val, Map props) {
+        if (props != null) {
+            props.put(name, val);
+            return; // skip firing property change
+        }
+        ComponentInternals ci = ComponentInternals.getComponentInternals();
+        ci.setDesktopProperty(name, val);
+    }
+    
     public Font getDefaultFont() {
         synchronized (cacheLock) {
             if (defaultFont == null) {
-                initDefaultFont();
+                defaultFont = (Font) Toolkit.getDefaultToolkit().
+                getDesktopProperty("win.defaultGUI.font");
             }
             return defaultFont;
         }
     }
 
-    private void initDefaultFont() {
-        long hFont = win32.GetStockObject(WindowsDefs.DEFAULT_GUI_FONT);
+    private Font getFont(long hFont) {
         Win32.LOGFONTW logFont = win32.createLOGFONTW(false);
         win32.GetObjectW(hFont, logFont.size(), logFont.longLockPointer());
         logFont.unlock();
-
+        return getFont(logFont);
+    }
+    
+    private Font getFont(Win32.LOGFONTW logFont) {
         String name = logFont.get_lfFaceName().getString();
         int size = Math.abs(logFont.get_lfHeight());
-        int bold = (logFont.get_lfWeight() == WindowsDefs.FW_BOLD) ? Font.BOLD : 0;
+        int weight = logFont.get_lfWeight();
+        int bold = (weight == WindowsDefs.FW_BOLD ? Font.BOLD : 0);
         int italic = (logFont.get_lfItalic() != 0) ? Font.ITALIC : 0;
+        return new Font(name, bold | italic, size);
+    }
+    
+    private void initSysFonts(Map props) {
+        for (int i = 0; i < sysFontIndices.length; i++) {
+            long hFont = win32.GetStockObject(sysFontIndices[i]);            
+            Font font = getFont(hFont);
+            if (props != null) {
+                String propName = sysFontDesktopProps[i];
+                setFontProperty(propName, font, props);
+            }
+        }       
+    }
+    
+    private void setBoolProperty(String propName, int val, Map props) {
+        setDesktopProperty(propName, (val != 0 ? Boolean.TRUE : Boolean.FALSE),
+                           props);
+    }
+
+    private void setIntProperty(String propName, int val, Map props) {
+        setDesktopProperty(propName, new Integer(val), props);
+    }
+    
+    private void setFontProperty(String propName, Font font, Map props) {
+        setDesktopProperty(propName, font, props);
+        setIntProperty(propName + ".height", font.getSize(), props);
+    }
+
+    public void init(Map desktopProperties) {
+        synchronized (cacheLock) {
+            getDnDProps(desktopProperties);
+            getShellProps(desktopProperties);
+            getMouseProps(desktopProperties);
+            if (sysColorCache == null) {
+                updateColorCache();
+            }
+            updateColorDesktopProperties(desktopProperties);
+            initSysFonts(desktopProperties);
+            getNonClientMetrics(desktopProperties);
+            getIconMetrics(desktopProperties);
+            getDragSize(true, desktopProperties);
+            getDragSize(false, desktopProperties);
+            getGradientCaptions(desktopProperties);
+            getFullWindowDrags(desktopProperties);
+            getHighContrast(desktopProperties);
+            getHotTracking(desktopProperties);
+            getKeyboardCues(desktopProperties);
+            getFontSmooth(desktopProperties);
+            getFontSmoothContrast(desktopProperties);
+            getFontSmoothType(desktopProperties);
+            getXPTheme(desktopProperties);
+            initSoundProps(desktopProperties);
+            TreeSet keySet = new TreeSet(desktopProperties.keySet());
+            keySet.add("awt.dynamicLayoutSupported");
+            String[] propNames = (String[]) keySet.toArray(new String[0]);            
+            desktopProperties.put("win.propNames", propNames);
+            
+        }
 
-        defaultFont = new Font(name, bold|italic, size);
+    }
+    
+    void processSettingChange(long idx) {
+        switch((int)idx) {
+        case WindowsDefs.SPI_SETNONCLIENTMETRICS:
+            getNonClientMetrics(null);
+            break;
+        case WindowsDefs.SPI_SETICONMETRICS:
+            getIconMetrics(null);
+            break;
+        case WindowsDefs.SPI_SETDRAGHEIGHT:                        
+        case WindowsDefs.SPI_SETDRAGWIDTH:
+            getDragSize(idx == WindowsDefs.SPI_SETDRAGWIDTH, null);
+            break;
+        case WindowsDefs.SPI_SETGRADIENTCAPTIONS:
+            getGradientCaptions(null);
+            break;
+        case WindowsDefs.SPI_SETDRAGFULLWINDOWS:
+            getFullWindowDrags(null);
+            break;
+        case WindowsDefs.SPI_SETHIGHCONTRAST:
+            getHighContrast(null);
+            break;
+        case WindowsDefs.SPI_SETHOTTRACKING:
+            getHotTracking(null);
+            break;
+        case WindowsDefs.SPI_SETKEYBOARDCUES:
+            getKeyboardCues(null);
+            break;
+        case WindowsDefs.SPI_SETFONTSMOOTHING:
+            getFontSmooth(null);
+            break;
+        case SPI_SETFONTSMOOTHINGCONTRAST:
+            getFontSmoothContrast(null);
+            break;
+        case SPI_SETFONTSMOOTHINGTYPE:
+            getFontSmoothType(null);
+            break;
+        case WindowsDefs.SPI_SETDOUBLECLICKTIME:
+        case WindowsDefs.SPI_SETWHEELSCROLLLINES:
+            getMouseProps(null);
+            break;
+        }
+        
+    }
+    
+    private void getFullWindowDrags(Map props) {        
+        getBoolSPI("win.frame.fullWindowDragsOn", 
+                   WindowsDefs.SPI_GETDRAGFULLWINDOWS, props);
+        
+    }
+    
+    private void getGradientCaptions(Map props) {        
+        getBoolSPI("win.frame.captionGradientsOn", 
+                   WindowsDefs.SPI_GETGRADIENTCAPTIONS, props);        
+    }
+    
+    private void getHotTracking(Map props) {        
+        getBoolSPI("win.item.hotTrackingOn", 
+                   WindowsDefs.SPI_GETHOTTRACKING, props);        
+    }
+    
+    private void getKeyboardCues(Map props) {        
+        getBoolSPI("win.menu.keyboardCuesOn", 
+                   WindowsDefs.SPI_GETKEYBOARDCUES, props);        
+    }
+    
+    private void getFontSmooth(Map props) {        
+        getBoolSPI("win.text.fontSmoothingOn", 
+                   WindowsDefs.SPI_GETFONTSMOOTHING, props);        
+    }
+    
+    private void getFontSmoothContrast(Map props) {
+        getIntSPI("win.text.fontSmoothingContrast",
+                  SPI_GETFONTSMOOTHINGCONTRAST, props);
+    }
+    
+    private void getFontSmoothType(Map props) {
+        getIntSPI("win.text.fontSmoothingType", SPI_GETFONTSMOOTHINGTYPE, props);
+    }
+    
+    private void getDragSize(boolean cx, Map props) {
+        int sm_idx = (cx ? WindowsDefs.SM_CXDRAG : WindowsDefs.SM_CYDRAG);
+        String propName = "win.drag";
+        propName += (cx ? ".width" : ".height");
+        getSM(propName, sm_idx, props);
+    }
+
+    private void getNonClientMetrics(Map props) {
+        Win32.NONCLIENTMETRICSW ncm = win32.createNONCLIENTMETRICSW(false);
+        ncm.set_cbSize(ncm.size());
+        win32.SystemParametersInfoW(WindowsDefs.SPI_GETNONCLIENTMETRICS,
+                                    ncm.size(), ncm.getElementPointer(0), 0);
+        setFontProperty("win.frame.captionFont",
+                        getFont(ncm.get_lfCaptionFont()), props);
+        setFontProperty("win.frame.smallCaptionFont",
+                        getFont(ncm.get_lfSmCaptionFont()), props);
+        setFontProperty("win.menu.font", getFont(ncm.get_lfMenuFont()), props);
+        setFontProperty("win.messagebox.font",
+                        getFont(ncm.get_lfMessageFont()), props);
+        setFontProperty("win.status.font", getFont(ncm.get_lfStatusFont()),
+                        props);
+        setFontProperty("win.tooltip.font", getFont(ncm.get_lfStatusFont()),
+                        props);
+        setIntProperty("win.frame.sizingBorderWidth", ncm.get_iBorderWidth(),
+                       props);
+        setIntProperty("win.scrollbar.width", ncm.get_iScrollWidth(),
+                       props);
+        setIntProperty("win.scrollbar.height", ncm.get_iScrollHeight(),
+                       props);
+        setIntProperty("win.frame.captionButtonWidth", ncm.get_iCaptionWidth(),
+                       props);
+        setIntProperty("win.frame.captionButtonHeight", ncm.get_iCaptionHeight(),
+                       props);
+        setIntProperty("win.frame.captionHeight", ncm.get_iCaptionHeight(),
+                       props);
+        setIntProperty("win.frame.smallCaptionButtonWidth", ncm.get_iSmCaptionWidth(),
+                       props);
+        setIntProperty("win.frame.smallCaptionButtonHeight", ncm.get_iSmCaptionHeight(),
+                       props);
+        setIntProperty("win.frame.smallCaptionHeight", ncm.get_iSmCaptionHeight(),
+                       props);
+        setIntProperty("win.menu.buttonWidth", ncm.get_iMenuWidth(), props);
+        setIntProperty("win.menu.height", ncm.get_iMenuHeight(), props);        
+    }
+    
+    private void getIconMetrics(Map props) {
+        Win32.ICONMETRICSW im = win32.createICONMETRICSW(false);
+        im.set_cbSize(im.size());
+        win32.SystemParametersInfoW(WindowsDefs.SPI_GETICONMETRICS,
+                                    im.size(), im.getElementPointer(0), 0);
+        setFontProperty("win.icon.font", getFont(im.get_lfFont()), props);
+        setIntProperty("win.icon.hspacing", im.get_iHorzSpacing(), props);
+        setBoolProperty("win.icon.titleWrappingOn", im.get_iTitleWrap(), props);
+        setIntProperty("win.icon.vspacing", im.get_iVertSpacing(), props);
+    }
+    
+    private void getHighContrast(Map props) {
+        Win32.HIGHCONTRASTA hc = win32.createHIGHCONTRASTA(false);
+        hc.set_cbSize(hc.size());
+        win32.SystemParametersInfoW(WindowsDefs.SPI_GETHIGHCONTRAST,
+                                    hc.size(), hc.getElementPointer(0), 0);        
+        setBoolProperty("win.highContrast.on", 
+                        hc.get_dwFlags() & WindowsDefs.HCF_HIGHCONTRASTON, 
+                        props);
+    }
+    
+    private void getSM(String propName, int idx, Map props) {
+        setIntProperty(propName, win32.GetSystemMetrics(idx), props);
+    }
+    
+    private Int16Pointer getIntSPI(int idx) {
+        NativeBridge bridge = NativeBridge.getInstance();        
+        Int16Pointer ptr = bridge.createInt16Pointer(1, false);
+        win32.SystemParametersInfoW(idx, 0, ptr, 0);
+        return ptr;
+    }
+    
+    private void getBoolSPI(String propName, int idx, Map props) {
+        setBoolProperty(propName, getIntSPI(idx).get(0), props);
+    }
+    
+    private void getIntSPI(String propName, int idx, Map props) {
+        setIntProperty(propName, getIntSPI(idx).get(0), props);
+    }
+    
+    void getXPTheme(Map props) {
+        setBoolProperty("win.xpstyle.themeActive", win32.IsThemeActive(), props);
+    }
+    
+    private void getDnDProps(Map props) {
+        String propName = "DnD";
+        setIntProperty(propName + ".gestureMotionThreshold",
+                       WindowsDefs.DD_DEFDRAGMINDIST, props);
+        propName += ".Autoscroll";
+        setIntProperty(propName + ".initialDelay",
+                       WindowsDefs.DD_DEFSCROLLDELAY, props);
+        setIntProperty(propName + ".interval",
+                       WindowsDefs.DD_DEFSCROLLINTERVAL, props);        
+        
+    }
+    
+    private void getShellProps(Map props) {        
+        Win32.SHELLFLAGSTATE sfs = win32.createSHELLFLAGSTATE(false);
+        int flags = (WindowsDefs.SSF_SHOWATTRIBCOL | 
+                     WindowsDefs.SSF_SHOWALLOBJECTS);
+        win32.SHGetSettings(sfs, flags);
+        String propName = "awt.file";
+        setBoolProperty(propName + ".showAttribCol", 
+                        sfs.get_fShowAttribCol(), props);
+        setBoolProperty(propName + ".showHiddenFiles", 
+                        (sfs.get_fShowAllObjects()), props);
+    }
+    
+    private void getMouseProps(Map props) {
+        String propName = "awt.";
+        getSM(propName + "mouse.numButtons", WindowsDefs.SM_CMOUSEBUTTONS, props);
+        setIntProperty(propName + "multiClickInterval", 
+                       win32.GetDoubleClickTime(), props);
+        setBoolProperty(propName + "wheelMousePresent",
+                        win32.GetSystemMetrics(WindowsDefs.SM_MOUSEWHEELPRESENT),
+                        props);
+        getIntSPI(propName + "wheelScrollLines",
+                  WindowsDefs.SPI_GETWHEELSCROLLLINES, props);
+        
+    }
+    
+    private void setSoundProperty(String propName, String sndName, Map props) {
+        String base = "win.sound.";
+        setDesktopProperty(base + propName, new WinPlaySound(sndName), props);
+    }
+    
+    private void initSoundProps(Map props) {
+        setSoundProperty("asterisk", "SystemAsterisk", props);
+        setSoundProperty("close", "Close", props);
+        setSoundProperty("default", ".Default", props);
+        setSoundProperty("exclamation", "SystemExclamation", props);
+        setSoundProperty("exit", "SystemExit", props);
+        setSoundProperty("hand", "SystemHand", props);
+        setSoundProperty("maximize", "Maximize", props);
+        setSoundProperty("menuCommand", "MenuCommand", props);
+        setSoundProperty("menuPopup", "MenuPopup", props);
+        setSoundProperty("minimize", "Minimize", props);
+        setSoundProperty("open", "Open", props);
+        setSoundProperty("question", "SystemQuestion", props);
+        setSoundProperty("restoreDown", "RestoreDown", props);
+        setSoundProperty("restoreUp", "RestoreUp", props);
+        setSoundProperty("start", "SystemStart", props);
+    
+    }
+
+    public void mapInputMethodHighlight(InputMethodHighlight highlight, Map map) {
+        TextAttribute key = TextAttribute.INPUT_METHOD_UNDERLINE;
+        boolean selected = highlight.isSelected();
+        switch(highlight.getState()) {
+        case InputMethodHighlight.RAW_TEXT:
+            map.put(key, selected ? TextAttribute.UNDERLINE_LOW_GRAY :
+                TextAttribute.UNDERLINE_LOW_DOTTED);
+            break;
+        case InputMethodHighlight.CONVERTED_TEXT:
+            map.put(key, selected ? TextAttribute.UNDERLINE_LOW_ONE_PIXEL :
+                TextAttribute.UNDERLINE_LOW_DOTTED);
+            if (selected) {
+                // maybe get colors from system properties?
+                key = TextAttribute.BACKGROUND;
+                map.put(key, Color.white);
+                key = TextAttribute.FOREGROUND;
+                map.put(key, new Color(0, 0, 128));
+                key = TextAttribute.SWAP_COLORS;
+                map.put(key, TextAttribute.SWAP_COLORS_ON);
+            }
+            break;
+        }
     }
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/wtk/windows/WinWTK.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/wtk/windows/WinWTK.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/wtk/windows/WinWTK.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/wtk/windows/WinWTK.java Wed Sep  6 09:06:15 2006
@@ -82,11 +82,18 @@
         return robot;
     }
 
+    public NativeIM getNativeIM() {
+        if (im == null) {
+            im = new WinIM();
+        }
+        return im;
+    }
+
     private final WinSystemProperties systemProperties = new WinSystemProperties();
     private final WinEventQueue eventQueue = new WinEventQueue(systemProperties);
     private final GraphicsFactory graphicsFactory = new org.apache.harmony.awt.gl.windows.WinGraphics2DFactory();
-    private final CursorFactory cursorFactory = new WinCursorFactory();
+    private final CursorFactory cursorFactory = new WinCursorFactory(eventQueue);
     private final NativeMouseInfo mouseInfo = new WinMouseInfo();
     private WinRobot robot;
-
+    private WinIM im;
 }



Mime
View raw message