diff dwt/widgets/DirectoryDialog.d @ 181:52c185ec49e8

Directory Dialog ported
author Zhiguang Liang <davelzg@gmail.com>
date Mon, 10 Mar 2008 11:31:43 +0800
parents 43c42c637c9c
children 811e926196d6
line wrap: on
line diff
--- a/dwt/widgets/DirectoryDialog.d	Fri Mar 07 02:36:32 2008 +0100
+++ b/dwt/widgets/DirectoryDialog.d	Mon Mar 10 11:31:43 2008 +0800
@@ -12,22 +12,17 @@
  *******************************************************************************/
 module dwt.widgets.DirectoryDialog;
 
+import dwt.widgets.Display;
 import dwt.widgets.Dialog;
 import dwt.widgets.Shell;
 
-class DirectoryDialog : Dialog {
-    public this (Shell parent, int style) {
-        super (parent, style);
-    }
-}
-
-/++
 import dwt.DWT;
 import dwt.DWTException;
-import dwt.internal.Callback;
-import dwt.internal.win32.BROWSEINFO;
 import dwt.internal.win32.OS;
-import dwt.internal.win32.TCHAR;
+import dwt.internal.C;
+
+import dwt.dwthelper.utils;
+static import tango.text.Text;
 
 /**
  * Instances of this class allow the user to navigate
@@ -44,9 +39,10 @@
  * </p>
  */
 
-public class DirectoryDialog extends Dialog {
-    String message = "", filterPath = "";  //$NON-NLS-1$//$NON-NLS-2$
-    String directoryPath;
+public class DirectoryDialog : Dialog {
+    static char[] message = "";
+    static char[] filterPath = "";  //$NON-NLS-1$//$NON-NLS-2$
+    static char[] directoryPath;
 
 /**
  * Constructs a new instance of this class given only its parent.
@@ -61,7 +57,7 @@
  *    <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
  * </ul>
  */
-public DirectoryDialog (Shell parent) {
+public this (Shell parent) {
     this (parent, DWT.PRIMARY_MODAL);
 }
 
@@ -89,33 +85,35 @@
  *    <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
  * </ul>
  */
-public DirectoryDialog (Shell parent, int style) {
+public this (Shell parent, int style) {
     super (parent, style);
     checkSubclass ();
 }
 
-int BrowseCallbackProc (int hwnd, int uMsg, int lParam, int lpData) {
+extern(Windows)static int BrowseCallbackProc (HWND hwnd, uint uMsg, int lParam, int lpData) {
+    DirectoryDialog pThis = cast(DirectoryDialog)cast(void*)lpData;
     switch (uMsg) {
         case OS.BFFM_INITIALIZED:
-            if (filterPath !is null && filterPath.length () !is 0) {
+            if (pThis.filterPath !is null && pThis.filterPath.length !is 0) {
                 /* Use the character encoding for the default locale */
-                TCHAR buffer = new TCHAR (0, filterPath.replace ('/', '\\'), true);
-                OS.SendMessage (hwnd, OS.BFFM_SETSELECTION, 1, buffer);
+                TCHAR[] buffer = StrToTCHARs (0, pThis.filterPath.replace ('/', '\\'), true);
+                OS.SendMessage (hwnd, OS.BFFM_SETSELECTION, 1, buffer.ptr);
             }
-            if (title !is null && title.length () !is 0) {
+            if (pThis.title !is null && pThis.title.length !is 0) {
                 /* Use the character encoding for the default locale */
-                TCHAR buffer = new TCHAR (0, title, true);
-                OS.SetWindowText (hwnd, buffer);
+                TCHAR[] buffer = StrToTCHARs (0, pThis.title, true);
+                OS.SetWindowText (hwnd, buffer.ptr);
             }
             break;
         case OS.BFFM_VALIDATEFAILEDA:
         case OS.BFFM_VALIDATEFAILEDW:
             /* Use the character encoding for the default locale */
-            int length = OS.IsUnicode ? OS.wcslen (lParam) : OS.strlen (lParam);
-            TCHAR buffer = new TCHAR (0, length);
-            int byteCount = buffer.length () * TCHAR.sizeof;
-            OS.MoveMemory (buffer, lParam, byteCount);
-            directoryPath = buffer.toString (0, length);
+//            int length = OS.IsUnicode ? OS.wcslen (lParam) : OS.strlen (lParam);
+//            TCHAR buffer = new TCHAR (0, length);
+//            int byteCount = buffer.length * TCHAR.sizeof;
+//            OS.MoveMemory (buffer, lParam, byteCount);
+//            directoryPath = buffer.toString (0, length);
+            pThis.directoryPath = TCHARzToStr( cast(TCHAR*)lParam ); 
             break;
         default:
     }
@@ -130,7 +128,7 @@
  *
  * @see #setFilterPath
  */
-public String getFilterPath () {
+public char[] getFilterPath () {
     return filterPath;
 }
 
@@ -141,7 +139,7 @@
  *
  * @return the message
  */
-public String getMessage () {
+public char[] getMessage () {
     return message;
 }
 
@@ -157,21 +155,21 @@
  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the dialog</li>
  * </ul>
  */
-public String open () {
+public char[] open () {
     if (OS.IsWinCE) DWT.error (DWT.ERROR_NOT_IMPLEMENTED);
 
-    int hHeap = OS.GetProcessHeap ();
+    auto hHeap = OS.GetProcessHeap ();
 
     /* Get the owner HWND for the dialog */
-    int hwndOwner = 0;
+    HWND hwndOwner;
     if (parent !is null) hwndOwner = parent.handle;
 
     /* Copy the message to OS memory */
-    int lpszTitle = 0;
-    if (message.length () !is 0) {
-        String string = message;
+    TCHAR* lpszTitle;
+    if (message.length !is 0) {
+        char[] string = message;
         if (string.indexOf ('&') !is -1) {
-            int length = string.length ();
+            int length = string.length;
             char [] buffer = new char [length * 2];
             int index = 0;
             for (int i=0; i<length; i++) {
@@ -179,19 +177,20 @@
                 if (ch is '&') buffer [index++] = '&';
                 buffer [index++] = ch;
             }
-            string = new String (buffer, 0, index);
+//            string = new String (buffer, 0, index);
         }
         /* Use the character encoding for the default locale */
-        TCHAR buffer = new TCHAR (0, string, true);
-        int byteCount = buffer.length () * TCHAR.sizeof;
-        lpszTitle = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount);
-        OS.MoveMemory (lpszTitle, buffer, byteCount);
+        TCHAR[] buffer = StrToTCHARs (0, string, true);
+        int byteCount = buffer.length * TCHAR.sizeof;
+        lpszTitle = cast(TCHAR*)OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount);
+        OS.MoveMemory (lpszTitle, buffer.ptr, byteCount);
     }
 
     /* Create the BrowseCallbackProc */
-    Callback callback = new Callback (this, "BrowseCallbackProc", 4); //$NON-NLS-1$
-    int lpfn = callback.getAddress ();
-    if (lpfn is 0) DWT.error (DWT.ERROR_NO_MORE_CALLBACKS);
+/+    Callback callback = new Callback (this, "BrowseCallbackProc", 4); //$NON-NLS-1$
+    int lpfn = callback.getAddress ();+/
+    BFFCALLBACK lpfn = &BrowseCallbackProc; 
+    if (lpfn is null) DWT.error (DWT.ERROR_NO_MORE_CALLBACKS);
 
     /* Make the parent shell be temporary modal */
     Shell oldModal = null;
@@ -202,11 +201,12 @@
     }
 
     directoryPath = null;
-    BROWSEINFO lpbi = new BROWSEINFO ();
+    BROWSEINFO lpbi;
     lpbi.hwndOwner = hwndOwner;
     lpbi.lpszTitle = lpszTitle;
     lpbi.ulFlags = OS.BIF_NEWDIALOGSTYLE | OS.BIF_RETURNONLYFSDIRS | OS.BIF_EDITBOX | OS.BIF_VALIDATE;
     lpbi.lpfn = lpfn;
+    lpbi.lParam = cast(int)cast(void*)this;
     /*
     * Bug in Windows.  On some hardware configurations, SHBrowseForFolder()
     * causes warning dialogs with the message "There is no disk in the drive
@@ -239,7 +239,7 @@
     */
     bool oldRunMessages = display.runMessages;
     if (OS.COMCTL32_MAJOR < 6) display.runMessages = false;
-    int lpItemIdList = OS.SHBrowseForFolder (lpbi);
+    ITEMIDLIST* lpItemIdList = OS.SHBrowseForFolder (&lpbi);
     if (OS.COMCTL32_MAJOR < 6) display.runMessages = oldRunMessages;
     OS.SetErrorMode (oldErrorMode);
 
@@ -248,27 +248,27 @@
         display.setModalDialogShell (oldModal);
     }
 
-    bool success = lpItemIdList !is 0;
+    bool success = lpItemIdList !is null;
     if (success) {
         /* Use the character encoding for the default locale */
-        TCHAR buffer = new TCHAR (0, OS.MAX_PATH);
-        if (OS.SHGetPathFromIDList (lpItemIdList, buffer)) {
-            directoryPath = buffer.toString (0, buffer.strlen ());
+        TCHAR[OS.MAX_PATH] buffer;
+        if (OS.SHGetPathFromIDList (lpItemIdList, buffer.ptr)) {
+            directoryPath = TCHARzToStr (buffer.ptr);
             filterPath = directoryPath;
         }
     }
 
     /* Free the BrowseCallbackProc */
-    callback.dispose ();
+//    callback.dispose ();
 
     /* Free the OS memory */
-    if (lpszTitle !is 0) OS.HeapFree (hHeap, 0, lpszTitle);
+    if (lpszTitle !is null) OS.HeapFree (hHeap, 0, lpszTitle);
 
     /* Free the pointer to the ITEMIDLIST */
-    int [] ppMalloc = new int [1];
-    if (OS.SHGetMalloc (ppMalloc) is OS.S_OK) {
+    LPVOID ppMalloc;
+    if (OS.SHGetMalloc (&ppMalloc) is OS.S_OK) {
         /* void Free (struct IMalloc *this, void *pv); */
-        OS.VtblCall (5, ppMalloc [0], lpItemIdList);
+        OS.VtblCall (5, ppMalloc , cast(int)lpItemIdList);
     }
 
     /*
@@ -297,7 +297,7 @@
  *
  * @param string the filter path
  */
-public void setFilterPath (String string) {
+public void setFilterPath (char[] string) {
     filterPath = string;
 }
 
@@ -312,10 +312,9 @@
  *    <li>ERROR_NULL_ARGUMENT - if the string is null</li>
  * </ul>
  */
-public void setMessage (String string) {
+public void setMessage (char[] string) {
     if (string is null) error (DWT.ERROR_NULL_ARGUMENT);
     message = string;
 }
 
 }
-++/
\ No newline at end of file