root/dwt/dnd/Transfer.d

Revision 321:a3b84f877e63, 6.6 kB (checked in by Frank Benoit <benoit@tionex.de>, 1 month ago)

Fix compile errors

Line 
1 /*******************************************************************************
2  * Copyright (c) 2000, 2008 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  * Port to the D programming language:
11  *     Frank Benoit <benoit@tionex.de>
12  *******************************************************************************/
13 module dwt.dnd.Transfer;
14
15
16 import dwt.internal.win32.OS;
17 import dwt.internal.ole.win32.COM;
18
19 import dwt.dnd.TransferData;
20 import dwt.dwthelper.utils;
21 import dwt.internal.ole.win32.OBJIDL;
22 static import tango.core.Thread;
23
24 /**
25  * <code>Transfer</code> provides a mechanism for converting between a java
26  * representation of data and a platform specific representation of data and
27  * vice versa.  It is used in data transfer operations such as drag and drop and
28  * clipboard copy/paste.
29  *
30  * <p>You should only need to become familiar with this class if you are
31  * implementing a Transfer subclass and you are unable to subclass the
32  * ByteArrayTransfer class.</p>
33  *
34  * @see ByteArrayTransfer
35  * @see <a href="http://www.eclipse.org/swt/snippets/#dnd">Drag and Drop snippets</a>
36  * @see <a href="http://www.eclipse.org/swt/examples.php">DWT Example: DNDExample</a>
37  * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
38  */
39 public abstract class Transfer {
40
41 private static final int RETRY_LIMIT = 10;
42 /*
43  * Feature in Windows. When another application has control
44  * of the clipboard, the clipboard is locked and it's not
45  * possible to retrieve data until the other application is
46  * finished. To allow other applications to get the
47  * data, use PeekMessage() to enable cross thread
48  * message sends.
49  */
50 int getData(IDataObject dataObject, FORMATETC* pFormatetc, STGMEDIUM* pmedium) {
51     if (dataObject.GetData(pFormatetc, pmedium) is COM.S_OK) return COM.S_OK;
52     try {tango.core.Thread.Thread.sleep(0.050);} catch (Exception t) {}
53     int result = dataObject.GetData(pFormatetc, pmedium);
54     int retryCount = 0;
55     while (result !is COM.S_OK && retryCount++ < RETRY_LIMIT) {
56         MSG msg;
57         OS.PeekMessage(&msg, null, 0, 0, OS.PM_NOREMOVE | OS.PM_NOYIELD);
58         try {tango.core.Thread.Thread.sleep(0.050);} catch (Exception t) {}
59         result = dataObject.GetData(pFormatetc, pmedium);
60     }
61     return result;
62 }
63
64 /**
65  * Returns a list of the platform specific data types that can be converted using
66  * this transfer agent.
67  *
68  * <p>Only the data type fields of the <code>TransferData</code> objects are filled
69  * in.</p>
70  *
71  * @return a list of the data types that can be converted using this transfer agent
72  */
73 abstract public TransferData[] getSupportedTypes();
74
75 /**
76  * Returns true if the <code>TransferData</code> data type can be converted
77  * using this transfer agent, or false otherwise (including if transferData is
78  * <code>null</code>).
79  *
80  * @param transferData a platform specific description of a data type; only the data
81  *  type fields of the <code>TransferData</code> object need to be filled in
82  *
83  * @return true if the transferData data type can be converted using this transfer
84  * agent
85  */
86 abstract public bool isSupportedType(TransferData transferData);
87
88 /**
89  * Returns the platform specific ids of the  data types that can be converted using
90  * this transfer agent.
91  *
92  * @return the platform specific ids of the data types that can be converted using
93  * this transfer agent
94  */
95 abstract protected int[] getTypeIds();
96
97 /**
98  * Returns the platform specific names of the  data types that can be converted
99  * using this transfer agent.
100  *
101  * @return the platform specific names of the data types that can be converted
102  * using this transfer agent.
103  */
104 abstract protected String[] getTypeNames();
105
106 /**
107  * Converts a java representation of data to a platform specific representation of
108  * the data.
109  *
110  * <p>On a successful conversion, the transferData.result field will be set as follows:
111  * <ul>
112  * <li>Windows: COM.S_OK
113  * <li>Motif: 1
114  * <li>GTK: 1
115  * <li>Photon: 1
116  * </ul></p>
117  *
118  * <p>If this transfer agent is unable to perform the conversion, the transferData.result
119  * field will be set to a failure value as follows:
120  * <ul>
121  * <li>Windows: COM.DV_E_TYMED or COM.E_FAIL
122  * <li>Motif: 0
123  * <li>GTK: 0
124  * <li>Photon: 0
125  * </ul></p>
126  *
127  * @param object a java representation of the data to be converted; the type of
128  * Object that is passed in is dependent on the <code>Transfer</code> subclass.
129  *
130  * @param transferData an empty TransferData object; this object will be
131  * filled in on return with the platform specific representation of the data
132  *
133  * @exception dwt.DWTException <ul>
134  *    <li>ERROR_INVALID_DATA - if object does not contain data in a valid format or is <code>null</code></li>
135  * </ul>
136  */
137 abstract public void javaToNative (Object object, TransferData transferData);
138
139 /**
140  * Converts a platform specific representation of data to a java representation.
141  *
142  * @param transferData the platform specific representation of the data to be
143  * converted
144  *
145  * @return a java representation of the converted data if the conversion was
146  * successful; otherwise null.  If transferData is <code>null</code> then
147  * <code>null</code> is returned.  The type of Object that is returned is
148  * dependent on the <code>Transfer</code> subclass.
149  */
150 abstract public Object nativeToJava(TransferData transferData);
151
152 /**
153  * Registers a name for a data type and returns the associated unique identifier.
154  *
155  * <p>You may register the same type more than once, the same unique identifier
156  * will be returned if the type has been previously registered.</p>
157  *
158  * <p>Note: On windows, do <b>not</b> call this method with pre-defined
159  * Clipboard Format types such as CF_TEXT or CF_BITMAP because the
160  * pre-defined identifier will not be returned</p>
161  *
162  * @param formatName the name of a data type
163  *
164  * @return the unique identifier associated with this data type
165  */
166 public static int registerType(String formatName) {
167     // Look name up in the registry
168     // If name is not in registry, add it and return assigned value.
169     // If name already exists in registry, return its assigned value
170     TCHAR* chFormatName = StrToTCHARz(0, formatName);
171     return OS.RegisterClipboardFormat(chFormatName);
172 }
173
174 /**
175  * Test that the object is of the correct format for this Transfer class.
176  *
177  * @param object a java representation of the data to be converted
178  *
179  * @return true if object is of the correct form for this transfer type
180  *
181  * @since 3.1
182  */
183 public bool validate(Object object) {
184     return true;
185 }
186 }
Note: See TracBrowser for help on using the browser.