Changeset 182:811e926196d6

Show
Ignore:
Timestamp:
03/09/08 23:58:09 (7 months ago)
Author:
Frank Benoit <benoit@tionex.de>
Parents:

180:772f75da6a52 181:52c185ec49e8

branch:
default
Message:

merge

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • dwt/widgets/DirectoryDialog.d

    r82 r182  
    1313module dwt.widgets.DirectoryDialog; 
    1414 
     15import dwt.widgets.Display; 
    1516import dwt.widgets.Dialog; 
    1617import dwt.widgets.Shell; 
    1718 
    18 class DirectoryDialog : Dialog { 
    19     public this (Shell parent, int style) { 
    20         super (parent, style); 
    21     } 
    22 } 
    23  
    24 /++ 
    2519import dwt.DWT; 
    2620import dwt.DWTException; 
    27 import dwt.internal.Callback; 
    28 import dwt.internal.win32.BROWSEINFO; 
    2921import dwt.internal.win32.OS; 
    30 import dwt.internal.win32.TCHAR; 
     22import dwt.internal.C; 
     23 
     24import dwt.dwthelper.utils; 
     25static import tango.text.Text; 
    3126 
    3227/** 
     
    4540 */ 
    4641 
    47 public class DirectoryDialog extends Dialog { 
    48     String message = "", filterPath = "";  //$NON-NLS-1$//$NON-NLS-2$ 
    49     String directoryPath; 
     42public class DirectoryDialog : Dialog { 
     43    static char[] message = ""; 
     44    static char[] filterPath = "";  //$NON-NLS-1$//$NON-NLS-2$ 
     45    static char[] directoryPath; 
    5046 
    5147/** 
     
    6258 * </ul> 
    6359 */ 
    64 public DirectoryDialog (Shell parent) { 
     60public this (Shell parent) { 
    6561    this (parent, DWT.PRIMARY_MODAL); 
    6662} 
     
    9086 * </ul> 
    9187 */ 
    92 public DirectoryDialog (Shell parent, int style) { 
     88public this (Shell parent, int style) { 
    9389    super (parent, style); 
    9490    checkSubclass (); 
    9591} 
    9692 
    97 int BrowseCallbackProc (int hwnd, int uMsg, int lParam, int lpData) { 
     93extern(Windows)static int BrowseCallbackProc (HWND hwnd, uint uMsg, int lParam, int lpData) { 
     94    DirectoryDialog pThis = cast(DirectoryDialog)cast(void*)lpData; 
    9895    switch (uMsg) { 
    9996        case OS.BFFM_INITIALIZED: 
    100             if (filterPath !is null && filterPath.length () !is 0) { 
     97            if (pThis.filterPath !is null && pThis.filterPath.length !is 0) { 
    10198                /* Use the character encoding for the default locale */ 
    102                 TCHAR buffer = new TCHAR (0, filterPath.replace ('/', '\\'), true); 
    103                 OS.SendMessage (hwnd, OS.BFFM_SETSELECTION, 1, buffer); 
     99                TCHAR[] buffer = StrToTCHARs (0, pThis.filterPath.replace ('/', '\\'), true); 
     100                OS.SendMessage (hwnd, OS.BFFM_SETSELECTION, 1, buffer.ptr); 
    104101            } 
    105             if (title !is null && title.length () !is 0) { 
     102            if (pThis.title !is null && pThis.title.length !is 0) { 
    106103                /* Use the character encoding for the default locale */ 
    107                 TCHAR buffer = new TCHAR (0, title, true); 
    108                 OS.SetWindowText (hwnd, buffer); 
     104                TCHAR[] buffer = StrToTCHARs (0, pThis.title, true); 
     105                OS.SetWindowText (hwnd, buffer.ptr); 
    109106            } 
    110107            break; 
     
    112109        case OS.BFFM_VALIDATEFAILEDW: 
    113110            /* Use the character encoding for the default locale */ 
    114             int length = OS.IsUnicode ? OS.wcslen (lParam) : OS.strlen (lParam); 
    115             TCHAR buffer = new TCHAR (0, length); 
    116             int byteCount = buffer.length () * TCHAR.sizeof; 
    117             OS.MoveMemory (buffer, lParam, byteCount); 
    118             directoryPath = buffer.toString (0, length); 
     111//            int length = OS.IsUnicode ? OS.wcslen (lParam) : OS.strlen (lParam); 
     112//            TCHAR buffer = new TCHAR (0, length); 
     113//            int byteCount = buffer.length * TCHAR.sizeof; 
     114//            OS.MoveMemory (buffer, lParam, byteCount); 
     115//            directoryPath = buffer.toString (0, length); 
     116            pThis.directoryPath = TCHARzToStr( cast(TCHAR*)lParam ); 
    119117            break; 
    120118        default: 
     
    131129 * @see #setFilterPath 
    132130 */ 
    133 public String getFilterPath () { 
     131public char[] getFilterPath () { 
    134132    return filterPath; 
    135133} 
     
    142140 * @return the message 
    143141 */ 
    144 public String getMessage () { 
     142public char[] getMessage () { 
    145143    return message; 
    146144} 
     
    158156 * </ul> 
    159157 */ 
    160 public String open () { 
     158public char[] open () { 
    161159    if (OS.IsWinCE) DWT.error (DWT.ERROR_NOT_IMPLEMENTED); 
    162160 
    163     int hHeap = OS.GetProcessHeap (); 
     161    auto hHeap = OS.GetProcessHeap (); 
    164162 
    165163    /* Get the owner HWND for the dialog */ 
    166     int hwndOwner = 0
     164    HWND hwndOwner
    167165    if (parent !is null) hwndOwner = parent.handle; 
    168166 
    169167    /* Copy the message to OS memory */ 
    170     int lpszTitle = 0
    171     if (message.length () !is 0) { 
    172         String string = message; 
     168    TCHAR* lpszTitle
     169    if (message.length !is 0) { 
     170        char[] string = message; 
    173171        if (string.indexOf ('&') !is -1) { 
    174             int length = string.length ()
     172            int length = string.length
    175173            char [] buffer = new char [length * 2]; 
    176174            int index = 0; 
     
    180178                buffer [index++] = ch; 
    181179            } 
    182             string = new String (buffer, 0, index); 
     180//            string = new String (buffer, 0, index); 
    183181        } 
    184182        /* Use the character encoding for the default locale */ 
    185         TCHAR buffer = new TCHAR (0, string, true); 
    186         int byteCount = buffer.length () * TCHAR.sizeof; 
    187         lpszTitle = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount); 
    188         OS.MoveMemory (lpszTitle, buffer, byteCount); 
     183        TCHAR[] buffer = StrToTCHARs (0, string, true); 
     184        int byteCount = buffer.length * TCHAR.sizeof; 
     185        lpszTitle = cast(TCHAR*)OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount); 
     186        OS.MoveMemory (lpszTitle, buffer.ptr, byteCount); 
    189187    } 
    190188 
    191189    /* Create the BrowseCallbackProc */ 
    192     Callback callback = new Callback (this, "BrowseCallbackProc", 4); //$NON-NLS-1$ 
    193     int lpfn = callback.getAddress (); 
    194     if (lpfn is 0) DWT.error (DWT.ERROR_NO_MORE_CALLBACKS); 
     190/+    Callback callback = new Callback (this, "BrowseCallbackProc", 4); //$NON-NLS-1$ 
     191    int lpfn = callback.getAddress ();+/ 
     192    BFFCALLBACK lpfn = &BrowseCallbackProc; 
     193    if (lpfn is null) DWT.error (DWT.ERROR_NO_MORE_CALLBACKS); 
    195194 
    196195    /* Make the parent shell be temporary modal */ 
     
    203202 
    204203    directoryPath = null; 
    205     BROWSEINFO lpbi = new BROWSEINFO ()
     204    BROWSEINFO lpbi
    206205    lpbi.hwndOwner = hwndOwner; 
    207206    lpbi.lpszTitle = lpszTitle; 
    208207    lpbi.ulFlags = OS.BIF_NEWDIALOGSTYLE | OS.BIF_RETURNONLYFSDIRS | OS.BIF_EDITBOX | OS.BIF_VALIDATE; 
    209208    lpbi.lpfn = lpfn; 
     209    lpbi.lParam = cast(int)cast(void*)this; 
    210210    /* 
    211211    * Bug in Windows.  On some hardware configurations, SHBrowseForFolder() 
     
    240240    bool oldRunMessages = display.runMessages; 
    241241    if (OS.COMCTL32_MAJOR < 6) display.runMessages = false; 
    242     int lpItemIdList = OS.SHBrowseForFolder (lpbi); 
     242    ITEMIDLIST* lpItemIdList = OS.SHBrowseForFolder (&lpbi); 
    243243    if (OS.COMCTL32_MAJOR < 6) display.runMessages = oldRunMessages; 
    244244    OS.SetErrorMode (oldErrorMode); 
     
    249249    } 
    250250 
    251     bool success = lpItemIdList !is 0
     251    bool success = lpItemIdList !is null
    252252    if (success) { 
    253253        /* Use the character encoding for the default locale */ 
    254         TCHAR buffer = new TCHAR (0, OS.MAX_PATH)
    255         if (OS.SHGetPathFromIDList (lpItemIdList, buffer)) { 
    256             directoryPath = buffer.toString (0, buffer.strlen ()); 
     254        TCHAR[OS.MAX_PATH] buffer
     255        if (OS.SHGetPathFromIDList (lpItemIdList, buffer.ptr)) { 
     256            directoryPath = TCHARzToStr (buffer.ptr); 
    257257            filterPath = directoryPath; 
    258258        } 
     
    260260 
    261261    /* Free the BrowseCallbackProc */ 
    262     callback.dispose (); 
     262//    callback.dispose (); 
    263263 
    264264    /* Free the OS memory */ 
    265     if (lpszTitle !is 0) OS.HeapFree (hHeap, 0, lpszTitle); 
     265    if (lpszTitle !is null) OS.HeapFree (hHeap, 0, lpszTitle); 
    266266 
    267267    /* Free the pointer to the ITEMIDLIST */ 
    268     int [] ppMalloc = new int [1]
    269     if (OS.SHGetMalloc (ppMalloc) is OS.S_OK) { 
     268    LPVOID ppMalloc
     269    if (OS.SHGetMalloc (&ppMalloc) is OS.S_OK) { 
    270270        /* void Free (struct IMalloc *this, void *pv); */ 
    271         OS.VtblCall (5, ppMalloc [0], lpItemIdList); 
     271        OS.VtblCall (5, ppMalloc , cast(int)lpItemIdList); 
    272272    } 
    273273 
     
    298298 * @param string the filter path 
    299299 */ 
    300 public void setFilterPath (String string) { 
     300public void setFilterPath (char[] string) { 
    301301    filterPath = string; 
    302302} 
     
    313313 * </ul> 
    314314 */ 
    315 public void setMessage (String string) { 
     315public void setMessage (char[] string) { 
    316316    if (string is null) error (DWT.ERROR_NULL_ARGUMENT); 
    317317    message = string; 
     
    319319 
    320320} 
    321 ++/ 
  • dwt/widgets/DirectoryDialog.d

    r181 r182  
    114114//            OS.MoveMemory (buffer, lParam, byteCount); 
    115115//            directoryPath = buffer.toString (0, length); 
    116             pThis.directoryPath = TCHARzToStr( cast(TCHAR*)lParam );  
     116            pThis.directoryPath = TCHARzToStr( cast(TCHAR*)lParam ); 
    117117            break; 
    118118        default: 
     
    190190/+    Callback callback = new Callback (this, "BrowseCallbackProc", 4); //$NON-NLS-1$ 
    191191    int lpfn = callback.getAddress ();+/ 
    192     BFFCALLBACK lpfn = &BrowseCallbackProc;  
     192    BFFCALLBACK lpfn = &BrowseCallbackProc; 
    193193    if (lpfn is null) DWT.error (DWT.ERROR_NO_MORE_CALLBACKS); 
    194194