From 141d782d567f92933f6fe868fff5bace77e8ecd2 Mon Sep 17 00:00:00 2001
From: Vadim Zeitlin <vadim@wxwidgets.org>
Date: Sat, 6 May 2006 20:10:11 +0000
Subject: [PATCH] misc fixes for wxDirDialog; new wxDD_CHANGE_DIR flag (patch
 1478051)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@39079 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
---
 docs/latex/wx/dirdlg.tex        | 17 +-------
 include/wx/cocoa/dirdlg.h       |  3 --
 include/wx/defs.h               |  2 +
 include/wx/dirdlg.h             | 27 +++++++++---
 include/wx/generic/dirdlgg.h    |  7 +--
 include/wx/gtk/dirdlg.h         |  2 +-
 include/wx/mac/carbon/dirdlg.h  |  4 --
 include/wx/mac/classic/dirdlg.h |  4 --
 include/wx/os2/dirdlg.h         |  6 +--
 src/generic/dirdlgg.cpp         | 39 ++++++++++++-----
 src/gtk/dirdlg.cpp              | 76 +++++++++------------------------
 src/msw/dirdlg.cpp              |  9 +++-
 12 files changed, 85 insertions(+), 111 deletions(-)

diff --git a/docs/latex/wx/dirdlg.tex b/docs/latex/wx/dirdlg.tex
index 5ac906af22..ec61a15c83 100644
--- a/docs/latex/wx/dirdlg.tex
+++ b/docs/latex/wx/dirdlg.tex
@@ -12,17 +12,16 @@ This class represents the directory chooser dialog.
 \wxheading{Include files}
 
 <wx/dirdlg.h>
-<wx/generic/dirdlgg.h>
 
 \wxheading{Window styles}
 
-\twocolwidtha{5cm}
-\begin{twocollist}
+\begin{twocollist}\itemsep=0pt
 \twocolitem{\windowstyle{wxDD\_DEFAULT\_STYLE}}{Equivalent to a combination of wxDEFAULT\_DIALOG\_STYLE, wxDD\_NEW\_DIR\_BUTTON and wxRESIZE\_BORDER (the last one is not used under wxWinCE).}
 \twocolitem{\windowstyle{wxDD\_NEW\_DIR\_BUTTON}}{Add "Create new
 directory" button and allow directory names to be editable.  On
 Windows the new directory button is only available with recent
 versions of the common dialogs.}
+\twocolitem{\windowstyle{wxDD\_CHANGE\_DIR}}{Change the current working directory to the directory chosen by the user.}
 \end{twocollist}
 
 See also \helpref{Generic window styles}{windowstyles}.
@@ -78,12 +77,6 @@ Returns the default or user-selected path.
 
 Returns the message that will be displayed on the dialog.
 
-\membersection{wxDirDialog::GetStyle}\label{wxdirdialoggetstyle}
-
-\constfunc{long}{GetStyle}{\void}
-
-Returns the dialog style.
-
 \membersection{wxDirDialog::SetMessage}\label{wxdirdialogsetmessage}
 
 \func{void}{SetMessage}{\param{const wxString\& }{message}}
@@ -96,12 +89,6 @@ Sets the message that will be displayed on the dialog.
 
 Sets the default path.
 
-\membersection{wxDirDialog::SetStyle}\label{wxdirdialogsetstyle}
-
-\func{void}{SetStyle}{\param{long }{style}}
-
-Sets the dialog style. This is currently unused.
-
 \membersection{wxDirDialog::ShowModal}\label{wxdirdialogshowmodal}
 
 \func{int}{ShowModal}{\void}
diff --git a/include/wx/cocoa/dirdlg.h b/include/wx/cocoa/dirdlg.h
index 6b74ed026f..b221050d99 100644
--- a/include/wx/cocoa/dirdlg.h
+++ b/include/wx/cocoa/dirdlg.h
@@ -33,15 +33,12 @@ public:
                 const wxString& name = wxDirDialogNameStr);
     ~wxDirDialog();
 
-    long GetStyle() const { return m_dialogStyle; }
-
     virtual int ShowModal();
     
     inline WX_NSSavePanel GetNSSavePanel()
     {   return (WX_NSSavePanel)m_cocoaNSWindow; }
 
 protected:
-    long        m_dialogStyle;
     wxString    m_dir;
     wxWindow *  m_parent;
     wxString    m_fileName;
diff --git a/include/wx/defs.h b/include/wx/defs.h
index 8bfbee8cc2..fa9403a04a 100644
--- a/include/wx/defs.h
+++ b/include/wx/defs.h
@@ -1711,6 +1711,8 @@ enum wxBorder
  */
 
 #define wxDD_NEW_DIR_BUTTON     0x0080
+#define wxDD_CHANGE_DIR         0x0100
+
 
 /*
  * extended dialog specifiers. these values are stored in a different
diff --git a/include/wx/dirdlg.h b/include/wx/dirdlg.h
index 401eeda50f..e8c7e44100 100644
--- a/include/wx/dirdlg.h
+++ b/include/wx/dirdlg.h
@@ -40,6 +40,7 @@ extern WXDLLEXPORT_DATA(const wxChar) wxDirSelectorPromptStr[];
 class WXDLLEXPORT wxDirDialogBase : public wxDialog
 {
 public:
+    wxDirDialogBase() {}
     wxDirDialogBase(wxWindow *parent,
                     const wxString& title = wxDirSelectorPromptStr,
                     const wxString& defaultPath = wxEmptyString,
@@ -47,20 +48,34 @@ public:
                     const wxPoint& pos = wxDefaultPosition,
                     const wxSize& sz = wxDefaultSize,
                     const wxString& name = wxDirDialogNameStr)
-        : wxDialog(parent, wxID_ANY, title, pos, sz, style, name)
-        , m_path(defaultPath)
-    {}
-    wxDirDialogBase() {}
+    {
+        Create(parent, title, defaultPath, style, pos, sz, name);
+    }
 
     virtual ~wxDirDialogBase() {}
 
+
+    bool Create(wxWindow *parent,
+                const wxString& title = wxDirSelectorPromptStr,
+                const wxString& defaultPath = wxEmptyString,
+                long style = wxDD_DEFAULT_STYLE,
+                const wxPoint& pos = wxDefaultPosition,
+                const wxSize& sz = wxDefaultSize,
+                const wxString& name = wxDirDialogNameStr)
+    {
+        if (!wxDialog::Create(parent, wxID_ANY, title, pos, sz, style, name))
+            return false;
+        m_path = defaultPath;
+        m_message = title;
+        return true;
+    }
+
+
     virtual void SetMessage(const wxString& message) { m_message = message; }
     virtual void SetPath(const wxString& path) { m_path = path; }
-    virtual void SetStyle(long style) { SetWindowStyle(style); }
 
     virtual wxString GetMessage() const { return m_message; }
     virtual wxString GetPath() const { return m_path; }
-    virtual long GetStyle() const { return GetWindowStyle(); }
 
 protected:
     wxString m_message;
diff --git a/include/wx/generic/dirdlgg.h b/include/wx/generic/dirdlgg.h
index 93dcac9bec..1c48740479 100644
--- a/include/wx/generic/dirdlgg.h
+++ b/include/wx/generic/dirdlgg.h
@@ -22,8 +22,8 @@ class WXDLLEXPORT wxTreeEvent;
 // we may be included directly as well as from wx/dirdlg.h (FIXME)
 extern WXDLLEXPORT_DATA(const wxChar) wxDirDialogNameStr[];
 extern WXDLLEXPORT_DATA(const wxChar) wxDirSelectorPromptStr[];
-#ifndef wxDD_DEFAULT_STYLE
 
+#ifndef wxDD_DEFAULT_STYLE
 #ifdef __WXWINCE__
     #define wxDD_DEFAULT_STYLE \
         (wxDEFAULT_DIALOG_STYLE | wxDD_NEW_DIR_BUTTON)
@@ -62,13 +62,11 @@ public:
 
     //// Accessors
     void SetPath(const wxString& path);
-    void SetStyle(long style) { m_dialogStyle = style; }
-
     wxString GetPath() const;
-    long GetStyle() const { return m_dialogStyle; }
 
     //// Overrides
     virtual int ShowModal();
+    virtual void EndModal(int retCode);
 
     // this one is specific to wxGenericDirDialog
     wxTextCtrl* GetInputCtrl() const { return m_input; }
@@ -83,7 +81,6 @@ protected:
     void OnGoHome(wxCommandEvent& event);
     void OnShowHidden(wxCommandEvent& event);
 
-    long              m_dialogStyle;
     wxGenericDirCtrl* m_dirCtrl;
     wxTextCtrl*       m_input;
 
diff --git a/include/wx/gtk/dirdlg.h b/include/wx/gtk/dirdlg.h
index d044dee873..ea078fd2ab 100644
--- a/include/wx/gtk/dirdlg.h
+++ b/include/wx/gtk/dirdlg.h
@@ -23,7 +23,7 @@ public:
 
     wxDirDialogGTK(wxWindow *parent,
                 const wxString& message = wxDirSelectorPromptStr,
-                const wxString& defaultPath = _T(""),
+                const wxString& defaultPath = wxEmptyString,
                 long style = wxDD_DEFAULT_STYLE,
                 const wxPoint& pos = wxDefaultPosition,
                 const wxSize& size = wxDefaultSize,
diff --git a/include/wx/mac/carbon/dirdlg.h b/include/wx/mac/carbon/dirdlg.h
index 1017750ea3..5db3edc6bb 100644
--- a/include/wx/mac/carbon/dirdlg.h
+++ b/include/wx/mac/carbon/dirdlg.h
@@ -23,13 +23,9 @@ public:
                 const wxSize& size = wxDefaultSize,
                 const wxString& name = wxDirDialogNameStr);
 
-    void SetStyle(long style) { m_dialogStyle = style; }
-    long GetStyle() const { return m_dialogStyle; }
-
     virtual int ShowModal();
 
 protected:
-    long        m_dialogStyle;
     wxWindow *  m_parent;
 
     DECLARE_DYNAMIC_CLASS(wxDirDialog)
diff --git a/include/wx/mac/classic/dirdlg.h b/include/wx/mac/classic/dirdlg.h
index 1017750ea3..5db3edc6bb 100644
--- a/include/wx/mac/classic/dirdlg.h
+++ b/include/wx/mac/classic/dirdlg.h
@@ -23,13 +23,9 @@ public:
                 const wxSize& size = wxDefaultSize,
                 const wxString& name = wxDirDialogNameStr);
 
-    void SetStyle(long style) { m_dialogStyle = style; }
-    long GetStyle() const { return m_dialogStyle; }
-
     virtual int ShowModal();
 
 protected:
-    long        m_dialogStyle;
     wxWindow *  m_parent;
 
     DECLARE_DYNAMIC_CLASS(wxDirDialog)
diff --git a/include/wx/os2/dirdlg.h b/include/wx/os2/dirdlg.h
index 9f8d900ae3..250da8c5bb 100644
--- a/include/wx/os2/dirdlg.h
+++ b/include/wx/os2/dirdlg.h
@@ -18,19 +18,15 @@ WXDLLEXPORT_DATA(extern const wxChar) wxFileSelectorPromptStr[];
 
 class WXDLLEXPORT wxDirDialog: public wxDirDialogBase
 {
-DECLARE_DYNAMIC_CLASS(wxDirDialog)
+    DECLARE_DYNAMIC_CLASS(wxDirDialog)
 public:
     wxDirDialog(wxWindow *parent, const wxString& message = wxFileSelectorPromptStr,
         const wxString& defaultPath = "",
         long style = 0, const wxPoint& pos = wxDefaultPosition);
 
-    inline void SetStyle(long style) { m_dialogStyle = style; }
-    inline long GetStyle() const { return m_dialogStyle; }
-
     int ShowModal();
 
 protected:
-    long        m_dialogStyle;
     wxWindow *  m_parent;
 };
 
diff --git a/src/generic/dirdlgg.cpp b/src/generic/dirdlgg.cpp
index 2c50f0ec39..078123f983 100644
--- a/src/generic/dirdlgg.cpp
+++ b/src/generic/dirdlgg.cpp
@@ -78,21 +78,23 @@ END_EVENT_TABLE()
 wxGenericDirDialog::wxGenericDirDialog(wxWindow* parent, const wxString& title,
                                        const wxString& defaultPath, long style,
                                        const wxPoint& pos, const wxSize& sz,
-                                       const wxString& name):
-                wxDirDialogBase(parent, title, defaultPath, style, pos, sz, name)
+                                       const wxString& name)
 {
     Create(parent, title, defaultPath, style, pos, sz, name);
 }
 
-bool wxGenericDirDialog::Create(wxWindow* WXUNUSED(parent),
-                                const wxString& WXUNUSED(title),
+bool wxGenericDirDialog::Create(wxWindow* parent,
+                                const wxString& title,
                                 const wxString& defaultPath, long style,
-                                const wxPoint& WXUNUSED(pos),
-                                const wxSize& WXUNUSED(sz),
-                                const wxString& WXUNUSED(name))
+                                const wxPoint& pos,
+                                const wxSize& sz,
+                                const wxString& name)
 {
     wxBusyCursor cursor;
 
+    if (!wxDirDialogBase::Create(parent, title, defaultPath, style, pos, sz, name))
+        return false;
+
     m_path = defaultPath;
     if (m_path == wxT("~"))
         wxGetHomeDir(&m_path);
@@ -211,6 +213,15 @@ bool wxGenericDirDialog::Create(wxWindow* WXUNUSED(parent),
     return true;
 }
 
+void wxGenericDirDialog::EndModal(int retCode)
+{
+    // before proceeding, change the current working directory if user asked so
+    if (retCode == wxID_OK && HasFlag(wxDD_CHANGE_DIR))
+        wxSetWorkingDirectory(m_path);
+
+    wxDialog::EndModal(retCode);
+}
+
 void wxGenericDirDialog::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
 {
     EndModal(wxID_CANCEL);
@@ -219,12 +230,15 @@ void wxGenericDirDialog::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
 void wxGenericDirDialog::OnOK(wxCommandEvent& WXUNUSED(event))
 {
     m_path = m_input->GetValue();
+
     // Does the path exist? (User may have typed anything in m_input)
-    if (wxDirExists(m_path)) {
+    if (wxDirExists(m_path))
+    {
         // OK, path exists, we're done.
         EndModal(wxID_OK);
         return;
     }
+
     // Interact with user, find out if the dir is a typo or to be created
     wxString msg;
     msg.Printf(_("The directory '%s' does not exist\nCreate it now?"),
@@ -232,15 +246,18 @@ void wxGenericDirDialog::OnOK(wxCommandEvent& WXUNUSED(event))
     wxMessageDialog dialog(this, msg, _("Directory does not exist"),
                            wxYES_NO | wxICON_WARNING);
 
-    if ( dialog.ShowModal() == wxID_YES ) {
+    if ( dialog.ShowModal() == wxID_YES )
+    {
         // Okay, let's make it
         wxLogNull log;
-        if (wxMkdir(m_path)) {
+        if (wxMkdir(m_path))
+        {
             // The new dir was created okay.
             EndModal(wxID_OK);
             return;
         }
-        else {
+        else
+        {
             // Trouble...
             msg.Printf(_("Failed to create directory '%s'\n(Do you have the required permissions?)"),
                        m_path.c_str());
diff --git a/src/gtk/dirdlg.cpp b/src/gtk/dirdlg.cpp
index 56ad5ae859..bfd86d0b39 100644
--- a/src/gtk/dirdlg.cpp
+++ b/src/gtk/dirdlg.cpp
@@ -1,6 +1,6 @@
 /////////////////////////////////////////////////////////////////////////////
 // Name:        src/gtk/dirdlg.cpp
-// Purpose:     native implementation of wxDirDialog
+// Purpose:     native implementation of wxDirDialogGTK
 // Author:      Robert Roebling, Zbigniew Zagorski, Mart Raudsepp, Francesco Montorsi
 // Id:          $Id$
 // Copyright:   (c) 1998 Robert Roebling, 2004 Zbigniew Zagorski, 2005 Mart Raudsepp
@@ -13,7 +13,7 @@
 
 
 /*
-  NOTE: the GtkFileChooser interface can be used both for wxFileDialog and for wxDirDialog.
+  NOTE: the GtkFileChooser interface can be used both for wxFileDialog and for wxDirDialogGTK.
         Thus following code is very similar (even if not identic) to src/gtk/filedlg.cpp
         If you find a problem in this code, remember to check also that file !
 */
@@ -29,17 +29,13 @@
     #include "wx/filedlg.h"
 #endif
 
-#ifdef __WXGTK24__
+#ifdef __WXGTK24__      // only for GTK+ > 2.4 there is GtkFileChooserDialog
 
 #include <gtk/gtk.h>
 #include "wx/gtk/private.h"
 
 #include <unistd.h> // chdir
 
-#include "wx/filename.h" // wxFilename
-#include "wx/tokenzr.h" // wxStringTokenizer
-#include "wx/filefn.h" // ::wxGetCwd
-#include "wx/msgdlg.h" // wxMessageDialog
 
 //-----------------------------------------------------------------------------
 // idle system
@@ -52,43 +48,13 @@ extern void wxapp_install_idle_handler();
 //-----------------------------------------------------------------------------
 
 extern "C" {
-static void gtk_filedialog_ok_callback(GtkWidget *widget, wxDirDialog *dialog)
+static void gtk_filedialog_ok_callback(GtkWidget *widget, wxDirDialogGTK *dialog)
 {
-    int style = dialog->GetStyle();
     gchar* filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(widget));
 
-    // gtk version numbers must be identical with the one in ctor (that calls set_do_overwrite_confirmation)
-#if GTK_CHECK_VERSION(2,7,3)
-    if(gtk_check_version(2,7,3) != NULL)
-#endif
-    if ((style & wxSAVE) && (style & wxOVERWRITE_PROMPT))
-    {
-        if ( g_file_test(filename, G_FILE_TEST_EXISTS) )
-        {
-            wxString msg;
-
-            msg.Printf(
-                _("File '%s' already exists, do you really want to overwrite it?"),
-                wxString(wxConvFileName->cMB2WX(filename)).c_str());
-
-            wxMessageDialog dlg(dialog, msg, _("Confirm"),
-                               wxYES_NO | wxICON_QUESTION);
-            if (dlg.ShowModal() != wxID_YES)
-            {
-                g_free(filename);
-                return;
-            }
-        }
-    }
-
     // change to the directory where the user went if asked
-    if (style & wxCHANGE_DIR)
-    {
-        // Use chdir to not care about filename encodings
-        gchar* folder = g_path_get_dirname(filename);
-        chdir(folder);
-        g_free(folder);
-    }
+    if (dialog->HasFlag(wxDD_CHANGE_DIR))
+        chdir(filename);
 
     g_free(filename);
 
@@ -104,7 +70,7 @@ static void gtk_filedialog_ok_callback(GtkWidget *widget, wxDirDialog *dialog)
 
 extern "C" {
 static void gtk_filedialog_cancel_callback(GtkWidget *WXUNUSED(w),
-                                           wxDirDialog *dialog)
+                                           wxDirDialogGTK *dialog)
 {
     wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL);
     event.SetEventObject(dialog);
@@ -115,7 +81,7 @@ static void gtk_filedialog_cancel_callback(GtkWidget *WXUNUSED(w),
 extern "C" {
 static void gtk_filedialog_response_callback(GtkWidget *w,
                                              gint response,
-                                             wxDirDialog *dialog)
+                                             wxDirDialogGTK *dialog)
 {
     wxapp_install_idle_handler();
 
@@ -134,16 +100,16 @@ static void gtk_filedialog_response_callback(GtkWidget *w,
 #endif // __WXGTK24__
 
 //-----------------------------------------------------------------------------
-// wxDirDialog
+// wxDirDialogGTK
 //-----------------------------------------------------------------------------
 
-IMPLEMENT_DYNAMIC_CLASS(wxDirDialog,wxGenericDirDialog)
+IMPLEMENT_DYNAMIC_CLASS(wxDirDialogGTK,wxGenericDirDialog)
 
-BEGIN_EVENT_TABLE(wxDirDialog,wxGenericDirDialog)
-    EVT_BUTTON(wxID_OK, wxDirDialog::OnFakeOk)
+BEGIN_EVENT_TABLE(wxDirDialogGTK,wxGenericDirDialog)
+    EVT_BUTTON(wxID_OK, wxDirDialogGTK::OnFakeOk)
 END_EVENT_TABLE()
 
-wxDirDialog::wxDirDialog(wxWindow* parent, const wxString& title,
+wxDirDialogGTK::wxDirDialogGTK(wxWindow* parent, const wxString& title,
                         const wxString& defaultPath, long style,
                         const wxPoint& pos, const wxSize& sz,
                         const wxString& name)
@@ -159,7 +125,7 @@ wxDirDialog::wxDirDialog(wxWindow* parent, const wxString& title,
             !CreateBase(parent, wxID_ANY, pos, wxDefaultSize, style,
                     wxDefaultValidator, wxT("filedialog")))
         {
-            wxFAIL_MSG( wxT("wxDirDialog creation failed") );
+            wxFAIL_MSG( wxT("wxDirDialogGTK creation failed") );
             return;
         }
 
@@ -199,7 +165,7 @@ wxDirDialog::wxDirDialog(wxWindow* parent, const wxString& title,
         wxGenericDirDialog::Create(parent, title, defaultPath, style, pos, sz, name);
 }
 
-wxDirDialog::~wxDirDialog()
+wxDirDialogGTK::~wxDirDialogGTK()
 {
 #ifdef __WXGTK24__
     if (!gtk_check_version(2,4,0))
@@ -210,7 +176,7 @@ wxDirDialog::~wxDirDialog()
 #endif
 }
 
-void wxDirDialog::OnFakeOk( wxCommandEvent &event )
+void wxDirDialogGTK::OnFakeOk( wxCommandEvent &event )
 {
 #ifdef __WXGTK24__
     if (!gtk_check_version(2,4,0))
@@ -220,7 +186,7 @@ void wxDirDialog::OnFakeOk( wxCommandEvent &event )
         wxGenericDirDialog::OnOK( event );
 }
 
-int wxDirDialog::ShowModal()
+int wxDirDialogGTK::ShowModal()
 {
 #ifdef __WXGTK24__
     if (!gtk_check_version(2,4,0))
@@ -230,7 +196,7 @@ int wxDirDialog::ShowModal()
         return wxGenericDirDialog::ShowModal();
 }
 
-bool wxDirDialog::Show( bool show )
+bool wxDirDialogGTK::Show( bool show )
 {
 #ifdef __WXGTK24__
     if (!gtk_check_version(2,4,0))
@@ -240,7 +206,7 @@ bool wxDirDialog::Show( bool show )
         return wxGenericDirDialog::Show( show );
 }
 
-void wxDirDialog::DoSetSize(int x, int y, int width, int height, int sizeFlags )
+void wxDirDialogGTK::DoSetSize(int x, int y, int width, int height, int sizeFlags )
 {
     if (!m_wxwindow)
         return;
@@ -248,7 +214,7 @@ void wxDirDialog::DoSetSize(int x, int y, int width, int height, int sizeFlags )
         wxGenericDirDialog::DoSetSize( x, y, width, height, sizeFlags );
 }
 
-void wxDirDialog::SetPath(const wxString& dir)
+void wxDirDialogGTK::SetPath(const wxString& dir)
 {
 #ifdef __WXGTK24__
     if (!gtk_check_version(2,4,0))
@@ -263,7 +229,7 @@ void wxDirDialog::SetPath(const wxString& dir)
         wxGenericDirDialog::SetPath( dir );
 }
 
-wxString wxDirDialog::GetPath() const
+wxString wxDirDialogGTK::GetPath() const
 {
 #ifdef __WXGTK24__
     if (!gtk_check_version(2,4,0))
diff --git a/src/msw/dirdlg.cpp b/src/msw/dirdlg.cpp
index 5f2f111abb..018f4e1323 100644
--- a/src/msw/dirdlg.cpp
+++ b/src/msw/dirdlg.cpp
@@ -26,7 +26,8 @@
 
 #if wxUSE_DIRDLG
 
-#if wxUSE_OLE && !defined(__GNUWIN32_OLD__) && (!defined(__WXWINCE__) || (defined(__HANDHELDPC__) && (_WIN32_WCE >= 500)))
+#if wxUSE_OLE && !defined(__GNUWIN32_OLD__) && (!defined(__WXWINCE__) || \
+    (defined(__HANDHELDPC__) && (_WIN32_WCE >= 500)))
 
 #ifndef WX_PRECOMP
     #include "wx/utils.h"
@@ -89,7 +90,7 @@ wxDirDialog::wxDirDialog(wxWindow *parent,
     m_message = message;
     m_parent = parent;
 
-    SetStyle(style);
+    SetWindowStyle(style);
     SetPath(defaultPath);
 }
 
@@ -181,6 +182,10 @@ int wxDirDialog::ShowModal()
 
     m_path = pidl.GetPath();
 
+    // change current working directory if asked so
+    if (HasFlag(wxDD_CHANGE_DIR))
+        wxSetWorkingDirectory(m_path);
+
     return m_path.empty() ? wxID_CANCEL : wxID_OK;
 }
 
-- 
2.50.0

