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.datatransfer.ClipboardOwner;
023: import java.awt.datatransfer.DataFlavor;
024: import java.awt.datatransfer.Transferable;
025: import java.awt.datatransfer.UnsupportedFlavorException;
026: import java.io.IOException;
027:
028: import org.apache.harmony.awt.ContextStorage;
029: import org.apache.harmony.awt.datatransfer.DataProxy;
030: import org.apache.harmony.awt.datatransfer.DataSnapshot;
031: import org.apache.harmony.awt.datatransfer.DataSource;
032: import org.apache.harmony.awt.datatransfer.NativeClipboard;
033: import org.apache.harmony.awt.nativebridge.windows.WinDataTransfer;
034: import org.apache.harmony.awt.wtk.windows.WinEventQueue;
035:
036: public final class WinClipboard extends NativeClipboard implements
037: WinEventQueue.Preprocessor {
038:
039: private final WinEventQueue winEventQueue;
040:
041: public WinClipboard() {
042: super ("System"); //$NON-NLS-1$
043: winEventQueue = ((WinEventQueue) ContextStorage
044: .getNativeEventQueue());
045: winEventQueue.addPreprocessor(this );
046: }
047:
048: @Override
049: public void onShutdown() {
050: }
051:
052: @Override
053: public void onRestart() {
054: }
055:
056: @Override
057: public void setContents(Transferable contents, ClipboardOwner owner) {
058: DataSource dc = new DataSource(contents);
059: final DataSnapshot snapshot = new DataSnapshot(dc);
060:
061: WinEventQueue.Task task = new WinEventQueue.Task() {
062: @Override
063: public void perform() {
064: WinDataTransfer.setClipboardContents(snapshot);
065: }
066: };
067: winEventQueue.performTask(task);
068: // TODO: fire flavor change events
069: }
070:
071: @Override
072: public Object getData(DataFlavor flavor)
073: throws UnsupportedFlavorException, IOException {
074: return getContents(this ).getTransferData(flavor);
075: }
076:
077: @Override
078: public Transferable getContents(Object requestor) {
079: WinEventQueue.Task task = new WinEventQueue.Task() {
080: @Override
081: public void perform() {
082: WinDataTransfer.IDataObject dataObject = WinDataTransfer
083: .getClipboardContents();
084: DataSnapshot snapshot = new DataSnapshot(dataObject);
085: dataObject.release();
086: returnValue = new DataProxy(snapshot);
087: }
088: };
089: winEventQueue.performTask(task);
090: return (DataProxy) task.returnValue;
091: }
092:
093: @Override
094: public DataFlavor[] getAvailableDataFlavors() {
095: Transferable t = getContents(this );
096: return (t != null) ? t.getTransferDataFlavors()
097: : new DataFlavor[0];
098: }
099:
100: public boolean preprocess(long hwnd, int msg, long wParam,
101: long lParam, long[] result) {
102: // TODO: track changes in Windows clipboard
103: return false;
104: }
105:
106: }
|