Changeset 138:b479f7e2f431

Show
Ignore:
Timestamp:
02/13/08 09:23:04 (1 year ago)
Author:
Frank Benoit <benoit@tionex.de>
branch:
default
Message:

FileTransfer?

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • dwt/dnd/FileTransfer.d

    r135 r138  
    1414 
    1515import dwt.internal.ole.win32.COM; 
     16import dwt.internal.ole.win32.OBJIDL; 
    1617import dwt.internal.win32.OS; 
    1718 
     19import dwt.dnd.ByteArrayTransfer; 
     20import dwt.dnd.TransferData; 
     21import dwt.dnd.DND; 
     22 
     23import dwt.dwthelper.utils; 
     24static import tango.text.Text; 
     25alias tango.text.Text.Text!(char) StringBuffer; 
    1826 
    1927/** 
     
    3846public class FileTransfer : ByteArrayTransfer { 
    3947 
    40     private static FileTransfer _instance = new FileTransfer()
    41     private static final String CF_HDROP = "CF_HDROP "; //$NON-NLS-1$ 
     48    private static FileTransfer _instance
     49    private static final char[] CF_HDROP = "CF_HDROP "; //$NON-NLS-1$ 
    4250    private static final int CF_HDROPID = COM.CF_HDROP; 
    43     private static final String CF_HDROP_SEPARATOR = "\0"; //$NON-NLS-1$ 
     51    private static final char[] CF_HDROP_SEPARATOR = "\0"; //$NON-NLS-1$ 
    4452 
    4553private this() {} 
     
    5159 */ 
    5260public static FileTransfer getInstance () { 
     61    if( _instance is null ){ 
     62        synchronized { 
     63            if( _instance is null ){ 
     64                _instance = new FileTransfer(); 
     65            } 
     66        } 
     67    } 
    5368    return _instance; 
    5469} 
     
    7085        DND.error(DND.ERROR_INVALID_DATA); 
    7186    } 
    72     String[] fileNames = (String[]) object; 
     87    char[][] fileNames; 
     88    if( auto strs = cast(ArrayWrapperString2) object ){ 
     89        fileNames = strs.array; 
     90    } 
    7391    StringBuffer allFiles = new StringBuffer(); 
    7492    for (int i = 0; i < fileNames.length; i++) { 
     
    7694        allFiles.append(CF_HDROP_SEPARATOR); // each name is null terminated 
    7795    } 
    78     TCHAR buffer = new TCHAR(0, allFiles.toString(), true); // there is an extra null terminator at the very end 
    79     DROPFILES dropfiles = new DROPFILES()
     96    TCHAR[] buffer = StrToTCHARs(0, allFiles.toString(), true); // there is an extra null terminator at the very end 
     97    DROPFILES dropfiles
    8098    dropfiles.pFiles = DROPFILES.sizeof; 
    81     dropfiles.pt_x = dropfiles.pt_y = 0; 
     99    dropfiles.pt.x = dropfiles.pt.y = 0; 
    82100    dropfiles.fNC = 0; 
    83101    dropfiles.fWide = OS.IsUnicode ? 1 : 0; 
    84102    // Allocate the memory because the caller (DropTarget) has not handed it in 
    85103    // The caller of this method must release the data when it is done with it. 
    86     int byteCount = buffer.length() * TCHAR.sizeof; 
    87     int newPtr = OS.GlobalAlloc(COM.GMEM_FIXED | COM.GMEM_ZEROINIT, DROPFILES.sizeof + byteCount); 
    88     OS.MoveMemory(newPtr, dropfiles, DROPFILES.sizeof); 
    89     OS.MoveMemory(newPtr + DROPFILES.sizeof, buffer, byteCount); 
     104    int byteCount = buffer.length * TCHAR.sizeof; 
     105    auto newPtr = OS.GlobalAlloc(COM.GMEM_FIXED | COM.GMEM_ZEROINIT, DROPFILES.sizeof + byteCount); 
     106    OS.MoveMemory(newPtr, &dropfiles, DROPFILES.sizeof); 
     107    OS.MoveMemory(newPtr + DROPFILES.sizeof, buffer.ptr, byteCount); 
    90108    transferData.stgmedium = new STGMEDIUM(); 
    91109    transferData.stgmedium.tymed = COM.TYMED_HGLOBAL; 
    92110    transferData.stgmedium.unionField = newPtr; 
    93     transferData.stgmedium.pUnkForRelease = 0
     111    transferData.stgmedium.pUnkForRelease = null
    94112    transferData.result = COM.S_OK; 
    95113} 
     
    107125 */ 
    108126public Object nativeToJava(TransferData transferData) { 
    109     if (!isSupportedType(transferData) || transferData.pIDataObject is 0)  return null; 
     127    if (!isSupportedType(transferData) || transferData.pIDataObject is null)  return null; 
    110128 
    111129    // get file names from IDataObject 
    112     IDataObject dataObject = new IDataObject(transferData.pIDataObject)
     130    IDataObject dataObject = transferData.pIDataObject
    113131    dataObject.AddRef(); 
    114     FORMATETC formatetc = new FORMATETC(); 
     132    FORMATETC* formatetc = new FORMATETC(); 
    115133    formatetc.cfFormat = COM.CF_HDROP; 
    116     formatetc.ptd = 0
     134    formatetc.ptd = null
    117135    formatetc.dwAspect = COM.DVASPECT_CONTENT; 
    118136    formatetc.lindex = -1; 
    119137    formatetc.tymed = COM.TYMED_HGLOBAL; 
    120     STGMEDIUM stgmedium = new STGMEDIUM(); 
     138    STGMEDIUM* stgmedium = new STGMEDIUM(); 
    121139    stgmedium.tymed = COM.TYMED_HGLOBAL; 
    122140    transferData.result = dataObject.GetData(formatetc, stgmedium); 
     
    125143    // How many files are there? 
    126144    int count = OS.DragQueryFile(stgmedium.unionField, 0xFFFFFFFF, null, 0); 
    127     String[] fileNames = new String[count]
     145    char[][] fileNames = new char[][](count)
    128146    for (int i = 0; i < count; i++) { 
    129147        // How long is the name ? 
    130148        int size = OS.DragQueryFile(stgmedium.unionField, i, null, 0) + 1; 
    131         TCHAR lpszFile = new TCHAR(0, size); 
     149        TCHAR[] lpszFile = NewTCHARs(0, size); 
    132150        // Get file name and append it to string 
    133         OS.DragQueryFile(stgmedium.unionField, i, lpszFile, size); 
    134         fileNames[i] = lpszFile.toString(0, lpszFile.strlen()); 
     151        OS.DragQueryFile(stgmedium.unionField, i, lpszFile.ptr, size); 
     152        fileNames[i] = TCHARzToStr(lpszFile.ptr); 
    135153    } 
    136154    OS.DragFinish(stgmedium.unionField); // frees data associated with HDROP data 
    137     return fileNames
     155    return new ArrayWrapperString2(fileNames)
    138156} 
    139157 
    140158protected int[] getTypeIds(){ 
    141     return new int[] {CF_HDROPID}
     159    return [CF_HDROPID]
    142160} 
    143161 
    144 protected String[] getTypeNames(){ 
    145     return new String[] {CF_HDROP}
     162protected char[][] getTypeNames(){ 
     163    return [CF_HDROP]
    146164} 
    147165bool checkFile(Object object) { 
    148     if (object is null || !(object instanceof String[]) || ((String[])object).length is 0) return false; 
    149     String[] strings = (String[])object; 
     166    char[][] strings; 
     167    if( auto strs = cast(ArrayWrapperString2)object ){ 
     168        strings = strs.array; 
     169    } 
     170    if (!strings) return false; 
    150171    for (int i = 0; i < strings.length; i++) { 
    151         if (strings[i] is null || strings[i].length() is 0) return false; 
     172        if (strings[i] is null || strings[i].length is 0) return false; 
    152173    } 
    153174    return true;