diff dwt/widgets/FileDialog.d @ 213:36f5cb12e1a2

Update to SWT 3.4M7
author Frank Benoit <benoit@tionex.de>
date Sat, 17 May 2008 17:34:28 +0200
parents ab60f3309436
children fd9c62a2998e
line wrap: on
line diff
--- a/dwt/widgets/FileDialog.d	Mon May 05 00:12:38 2008 +0200
+++ b/dwt/widgets/FileDialog.d	Sat May 17 17:34:28 2008 +0200
@@ -43,9 +43,24 @@
     String [] filterExtensions;
     String [] fileNames;
     String filterPath = "", fileName = "";
-    static final String FILTER = "*.*";
+    int filterIndex = 0;
+    bool overwrite = false;
+    static const String FILTER = "*.*";
     static int BUFFER_SIZE = 1024 * 32;
-    static bool USE_HOOK;
+    static bool USE_HOOK = true;
+    static this() {
+        /*
+        *  Feature in Vista.  When OFN_ENABLEHOOK is set in the
+        *  save or open file dialog,  Vista uses the old XP look
+        *  and feel.  OFN_ENABLEHOOK is used to grow the file
+        *  name buffer in a multi-select file dialog.  The fix
+        *  is to only use OFN_ENABLEHOOK when the buffer has
+        *  overrun.
+        */
+        if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) {
+            USE_HOOK = false;
+        }
+    }
 
 /**
  * Constructs a new instance of this class given only its parent.
@@ -61,7 +76,7 @@
  * </ul>
  */
 public this (Shell parent) {
-    this (parent, DWT.PRIMARY_MODAL);
+    this (parent, DWT.APPLICATION_MODAL);
 }
 
 /**
@@ -89,7 +104,7 @@
  * </ul>
  */
 public this (Shell parent, int style) {
-    super (parent, style);
+    super (parent, checkStyle (parent, style));
     checkSubclass ();
 }
 
@@ -125,6 +140,26 @@
 }
 
 /**
+ * Get the 0-based index of the file extension filter
+ * which was selected by the user, or -1 if no filter
+ * was selected.
+ * <p>
+ * This is an index into the FilterExtensions array and
+ * the FilterNames array.
+ * </p>
+ *
+ * @return index the file extension filter index
+ *
+ * @see #getFilterExtensions
+ * @see #getFilterNames
+ *
+ * @since 3.4
+ */
+public int getFilterIndex () {
+    return filterIndex;
+}
+
+/**
  * Returns the names that describe the filter extensions
  * which the dialog will use to filter the files it shows.
  *
@@ -147,6 +182,19 @@
     return filterPath;
 }
 
+/**
+ * Returns the flag that the dialog will use to
+ * determine whether to prompt the user for file
+ * overwrite if the selected file already exists.
+ *
+ * @return true if the dialog will prompt for file overwrite, false otherwise
+ *
+ * @since 3.4
+ */
+public bool getOverwrite () {
+    return overwrite;
+}
+
 private static extern(Windows) uint OFNHookProc (HWND hdlg, uint uiMsg, uint wParam, int lParam) {
     switch (uiMsg) {
         case OS.WM_NOTIFY:
@@ -193,7 +241,35 @@
 
     /* Get the owner HWND for the dialog */
     HWND hwndOwner;
-    if (parent !is null) hwndOwner = parent.handle;
+    auto hwndParent = parent.handle;
+
+    /*
+    * Feature in Windows.  There is no API to set the orientation of a
+    * file dialog.  It is always inherited from the parent.  The fix is
+    * to create a hidden parent and set the orientation in the hidden
+    * parent for the dialog to inherit.
+    */
+    bool enabled = false;
+    if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION(4, 10)) {
+        int dialogOrientation = style & (DWT.LEFT_TO_RIGHT | DWT.RIGHT_TO_LEFT);
+        int parentOrientation = parent.style & (DWT.LEFT_TO_RIGHT | DWT.RIGHT_TO_LEFT);
+        if (dialogOrientation !is parentOrientation) {
+            int exStyle = OS.WS_EX_NOINHERITLAYOUT;
+            if (dialogOrientation is DWT.RIGHT_TO_LEFT) exStyle |= OS.WS_EX_LAYOUTRTL;
+            hwndOwner = OS.CreateWindowEx (
+                exStyle,
+                Shell.DialogClass.ptr,
+                null,
+                0,
+                OS.CW_USEDEFAULT, 0, OS.CW_USEDEFAULT, 0,
+                hwndParent,
+                null,
+                OS.GetModuleHandle (null),
+                null);
+            enabled = OS.IsWindowEnabled (hwndParent) !is 0;
+            if (enabled) OS.EnableWindow (hwndParent, false);
+        }
+    }
 
     /* Convert the title and copy it into lpstrTitle */
     if (title is null) title = "";
@@ -253,7 +329,8 @@
     OPENFILENAME struct_;
     struct_.lStructSize = OPENFILENAME.sizeof;
     struct_.Flags = OS.OFN_HIDEREADONLY | OS.OFN_NOCHANGEDIR;
-    //Callback callback = null;
+    bool save = (style & DWT.SAVE) !is 0;
+    if (save && overwrite) struct_.Flags |= OS.OFN_OVERWRITEPROMPT;
     if ((style & DWT.MULTI) !is 0) {
         struct_.Flags |= OS.OFN_ALLOWMULTISELECT | OS.OFN_EXPLORER;
         if (!OS.IsWinCE && USE_HOOK) {
@@ -271,7 +348,7 @@
     struct_.nMaxFile = nMaxFile;
     struct_.lpstrInitialDir = lpstrInitialDir;
     struct_.lpstrFilter = lpstrFilter;
-    struct_.nFilterIndex = 0;
+    struct_.nFilterIndex = filterIndex is 0 ? filterIndex : filterIndex + 1;
 
     /*
     * Set the default extension to an empty string.  If the
@@ -280,18 +357,17 @@
     * extension at the time that the dialog is closed.
     */
     TCHAR* lpstrDefExt;
-    bool save = (style & DWT.SAVE) !is 0;
     if (save) {
         lpstrDefExt = cast(TCHAR*) OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, TCHAR.sizeof);
         struct_.lpstrDefExt = lpstrDefExt;
     }
 
     /* Make the parent shell be temporary modal */
-    Shell oldModal = null;
+    Dialog oldModal = null;
     Display display = parent.getDisplay ();
     if ((style & (DWT.APPLICATION_MODAL | DWT.SYSTEM_MODAL)) !is 0) {
-        oldModal = display.getModalDialogShell ();
-        display.setModalDialogShell (parent);
+        oldModal = display.getModalDialog ();
+        display.setModalDialog (this);
     }
 
     /*
@@ -327,7 +403,7 @@
 
     /* Clear the temporary dialog modal parent */
     if ((style & (DWT.APPLICATION_MODAL | DWT.SYSTEM_MODAL)) !is 0) {
-        display.setModalDialogShell (oldModal);
+        display.setModalDialog (oldModal);
     }
 
     /* Dispose the callback and reassign the buffer */
@@ -335,7 +411,7 @@
     lpstrFile = struct_.lpstrFile;
 
     /* Set the new path, file name and filter */
-    fileNames = new String [0];
+    fileNames = null;
     String fullPath = null;
     if (success) {
 
@@ -408,6 +484,7 @@
                 fileNames = newFileNames;
             }
         }
+        filterIndex = struct_.nFilterIndex - 1;
     }
 
     /* Free the memory that was allocated. */
@@ -417,6 +494,13 @@
     OS.HeapFree (hHeap, 0, lpstrTitle);
     if (lpstrDefExt !is null) OS.HeapFree (hHeap, 0, lpstrDefExt);
 
+    /* Destroy the BIDI orientation window */
+    if (hwndParent !is hwndOwner) {
+        if (enabled) OS.EnableWindow (hwndParent, true);
+        OS.SetActiveWindow (hwndParent);
+        OS.DestroyWindow (hwndOwner);
+    }
+
     /*
     * This code is intentionally commented.  On some
     * platforms, the owner window is repainted right
@@ -461,7 +545,27 @@
 }
 
 /**
- * Sets the the names that describe the filter extensions
+ * Set the 0-based index of the file extension filter
+ * which the dialog will use initially to filter the files
+ * it shows to the argument.
+ * <p>
+ * This is an index into the FilterExtensions array and
+ * the FilterNames array.
+ * </p>
+ *
+ * @param index the file extension filter index
+ *
+ * @see #setFilterExtensions
+ * @see #setFilterNames
+ *
+ * @since 3.4
+ */
+public void setFilterIndex (int index) {
+    filterIndex = index;
+}
+
+/**
+ * Sets the names that describe the filter extensions
  * which the dialog will use to filter the files it shows
  * to the argument, which may be null.
  * <p>
@@ -499,5 +603,17 @@
     filterPath = string;
 }
 
+/**
+ * Sets the flag that the dialog will use to
+ * determine whether to prompt the user for file
+ * overwrite if the selected file already exists.
+ *
+ * @param overwrite true if the dialog will prompt for file overwrite, false otherwise
+ *
+ * @since 3.4
+ */
+public void setOverwrite (bool overwrite) {
+    this.overwrite = overwrite;
+}
 }