001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: /**
018: * @author Michael Danilov, Pavel Dolgov
019: * @version $Revision$
020: */package org.apache.harmony.awt.datatransfer.windows;
021:
022: import java.awt.dnd.DragGestureEvent;
023: import java.awt.dnd.DropTargetContext;
024: import java.awt.dnd.peer.DragSourceContextPeer;
025: import java.awt.dnd.peer.DropTargetContextPeer;
026:
027: import org.apache.harmony.awt.datatransfer.DTK;
028: import org.apache.harmony.awt.datatransfer.NativeClipboard;
029: import org.apache.harmony.awt.nativebridge.windows.Callback;
030: import org.apache.harmony.awt.nativebridge.windows.Win32;
031: import org.apache.harmony.awt.nativebridge.windows.WinDataTransfer;
032: import org.apache.harmony.awt.nativebridge.windows.WindowsDefs;
033: import org.apache.harmony.awt.wtk.NativeEventQueue.Task;
034: import org.apache.harmony.awt.wtk.windows.WindowProcHandler;
035: import org.apache.harmony.misc.accessors.AccessorFactory;
036: import org.apache.harmony.misc.accessors.ObjectAccessor;
037:
038: public final class WinDTK extends DTK implements Callback.Handler {
039:
040: private static final Win32 win32 = Win32.getInstance();
041: private static final ObjectAccessor objAccessor = AccessorFactory
042: .getObjectAccessor();
043:
044: private static final int WM_TASK = WindowsDefs.WM_USER + 1;
045:
046: private long dataTransferWindow;
047: private long windowProc;
048: private static final String windowClass = "org.apache.harmony.awt.datatransfer.window"; //$NON-NLS-1$
049:
050: @Override
051: protected NativeClipboard newNativeClipboard() {
052: return new WinClipboard();
053: }
054:
055: @Override
056: protected NativeClipboard newNativeSelection() {
057: return null;
058: }
059:
060: @Override
061: public void initDragAndDrop() {
062: WinDataTransfer.init();
063:
064: if (windowProc != 0) {
065: return;
066: }
067: windowProc = Callback.registerCallbackDataTransfer(this );
068: WindowProcHandler.registerWindowClass(windowClass, windowProc);
069: dataTransferWindow = win32.CreateWindowExW(0, windowClass,
070: windowClass, 0, 0, 0, 0, 0, // style, x, y, w, h
071: WindowsDefs.HWND_MESSAGE, 0, 0, null);
072: }
073:
074: @Override
075: public void runEventLoop() {
076: Win32.MSG msg = win32.createMSG(false);
077: while (win32.GetMessageW(msg, 0, 0, 0) != 0) {
078: win32.DispatchMessageW(msg);
079: }
080: }
081:
082: @Override
083: public DropTargetContextPeer createDropTargetContextPeer(
084: DropTargetContext context) {
085: return new WinDropTarget(this , context);
086: }
087:
088: @Override
089: public DragSourceContextPeer createDragSourceContextPeer(
090: DragGestureEvent dge) {
091: return new WinDragSource();
092: }
093:
094: @Override
095: public String getDefaultCharset() {
096: return "utf-16le"; //$NON-NLS-1$
097: }
098:
099: public long windowProc(long hwnd, int msg, long wParam, long lParam) {
100: if (hwnd == dataTransferWindow && msg == WM_TASK) {
101: Task t = (Task) objAccessor.getObjectFromReference(lParam);
102: t.perform();
103: return 0;
104: }
105: return win32.DefWindowProcW(hwnd, msg, wParam, lParam);
106: }
107:
108: public void performTask(Task task) {
109: long ref = objAccessor.getGlobalReference(task);
110: win32.SendMessageW(dataTransferWindow, WM_TASK, 0, ref);
111: objAccessor.releaseGlobalReference(ref);
112: }
113: }
|