]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/dirdlg.cpp
fixes to radio button handling (patch 803360)
[wxWidgets.git] / src / msw / dirdlg.cpp
index 7e0994ed74b9176f3c0a6c906bc689c3eb6c2e34..bf9a67c590493b539a4c2971c1111edf19fdeda4 100644 (file)
@@ -5,7 +5,7 @@
 // Modified by:
 // Created:     01/02/97
 // RCS-ID:      $Id$
 // Modified by:
 // Created:     01/02/97
 // RCS-ID:      $Id$
-// Copyright:   (c) Julian Smart and Markus Holzem
+// Copyright:   (c) Julian Smart
 // Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
 // Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
@@ -17,7 +17,7 @@
 // headers
 // ----------------------------------------------------------------------------
 
 // headers
 // ----------------------------------------------------------------------------
 
-#ifdef __GNUG__
+#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
     #pragma implementation "dirdlg.h"
 #endif
 
     #pragma implementation "dirdlg.h"
 #endif
 
     #include "wx/dialog.h"
     #include "wx/dirdlg.h"
     #include "wx/log.h"
     #include "wx/dialog.h"
     #include "wx/dirdlg.h"
     #include "wx/log.h"
+    #include "wx/app.h"     // for GetComCtl32Version()
 #endif
 
 #include "wx/msw/private.h"
 
 #endif
 
 #include "wx/msw/private.h"
 
+#ifdef __WXWINCE__
+#include <winreg.h>
+#include <objbase.h>
+#include <shlguid.h>
+#endif
 #include <shlobj.h> // Win95 shell
 
 // ----------------------------------------------------------------------------
 #include <shlobj.h> // Win95 shell
 
 // ----------------------------------------------------------------------------
     #define MAX_PATH 4096      // be generous
 #endif
 
     #define MAX_PATH 4096      // be generous
 #endif
 
+#ifndef BIF_NEWDIALOGSTYLE
+    #define BIF_NEWDIALOGSTYLE 0x0040
+#endif
+
+#ifndef BIF_NONEWFOLDERBUTTON
+    #define BIF_NONEWFOLDERBUTTON  0x0200
+#endif
+
+#ifndef BIF_EDITBOX
+    #define BIF_EDITBOX 16
+#endif
+
 // ----------------------------------------------------------------------------
 // wxWindows macros
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------
 // wxWindows macros
 // ----------------------------------------------------------------------------
@@ -80,32 +98,92 @@ static int CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lp,
 wxDirDialog::wxDirDialog(wxWindow *parent,
                          const wxString& message,
                          const wxString& defaultPath,
 wxDirDialog::wxDirDialog(wxWindow *parent,
                          const wxString& message,
                          const wxString& defaultPath,
-                         long WXUNUSED(style),
-                         const wxPoint& WXUNUSED(pos))
+                         long style,
+                         const wxPoint& WXUNUSED(pos),
+                         const wxSize& WXUNUSED(size),
+                         const wxString& WXUNUSED(name))
 {
     m_message = message;
     m_parent = parent;
 {
     m_message = message;
     m_parent = parent;
-    m_path = defaultPath;
+
+    SetStyle(style);
+    SetPath(defaultPath);
+}
+
+void wxDirDialog::SetPath(const wxString& path)
+{
+    m_path = path;
 
     // SHBrowseForFolder doesn't like '/'s nor the trailing backslashes
     m_path.Replace(_T("/"), _T("\\"));
 
     // SHBrowseForFolder doesn't like '/'s nor the trailing backslashes
     m_path.Replace(_T("/"), _T("\\"));
-    if ( *m_path.end() == _T('\\') )
+    if ( !m_path.empty() )
     {
     {
-        m_path.erase(m_path.length() - 1);
+        while ( *(m_path.end() - 1) == _T('\\') )
+        {
+            m_path.erase(m_path.length() - 1);
+        }
+
+        // but the root drive should have a trailing slash (again, this is just
+        // the way the native dialog works)
+        if ( *(m_path.end() - 1) == _T(':') )
+        {
+            m_path += _T('\\');
+        }
     }
 }
 
 int wxDirDialog::ShowModal()
 {
     }
 }
 
 int wxDirDialog::ShowModal()
 {
+    wxWindow *parent = GetParent();
+
     BROWSEINFO bi;
     BROWSEINFO bi;
-    bi.hwndOwner      = m_parent ? GetHwndOf(m_parent) : NULL;
+    bi.hwndOwner      = parent ? GetHwndOf(parent) : NULL;
     bi.pidlRoot       = NULL;
     bi.pszDisplayName = NULL;
     bi.pidlRoot       = NULL;
     bi.pszDisplayName = NULL;
+#ifdef __WXWINCE__
+    bi.lpszTitle      = m_message.mb_str();
+#else
     bi.lpszTitle      = m_message.c_str();
     bi.lpszTitle      = m_message.c_str();
+#endif
     bi.ulFlags        = BIF_RETURNONLYFSDIRS | BIF_STATUSTEXT;
     bi.lpfn           = BrowseCallbackProc;
     bi.lParam         = (LPARAM)m_path.c_str();    // param for the callback
 
     bi.ulFlags        = BIF_RETURNONLYFSDIRS | BIF_STATUSTEXT;
     bi.lpfn           = BrowseCallbackProc;
     bi.lParam         = (LPARAM)m_path.c_str();    // param for the callback
 
+    static const int verComCtl32 = wxApp::GetComCtl32Version();
+
+    // we always add the edit box (it doesn't hurt anybody, does it?) if it is
+    // supported by the system
+    if ( verComCtl32 >= 471 )
+    {
+        bi.ulFlags |= BIF_EDITBOX;
+    }
+
+    // to have the "New Folder" button we must use the "new" dialog style which
+    // is also the only way to have a resizable dialog
+    //
+    // "new" style is only available in the version 5.0+ of comctl32.dll
+    const bool needNewDir = HasFlag(wxDD_NEW_DIR_BUTTON);
+    if ( (needNewDir || HasFlag(wxRESIZE_BORDER)) && (verComCtl32 >= 500) )
+    {
+        if (needNewDir)
+        {
+            bi.ulFlags |= BIF_NEWDIALOGSTYLE;
+        }
+        else
+        {
+            // Versions < 600 doesn't support BIF_NONEWFOLDERBUTTON
+            // The only way to get rid of the Make New Folder button is use
+            // the old dialog style which doesn't have the button thus we
+            // simply don't set the New Dialog Style for such comctl versions.
+            if (verComCtl32 >= 600)
+            {
+                bi.ulFlags |= BIF_NEWDIALOGSTYLE;
+                bi.ulFlags |= BIF_NONEWFOLDERBUTTON;
+            }
+        }
+    }
+
+    // do show the dialog
     LPITEMIDLIST pidl = SHBrowseForFolder(&bi);
 
     if ( bi.pidlRoot )
     LPITEMIDLIST pidl = SHBrowseForFolder(&bi);
 
     if ( bi.pidlRoot )
@@ -119,8 +197,7 @@ int wxDirDialog::ShowModal()
         return wxID_CANCEL;
     }
 
         return wxID_CANCEL;
     }
 
-    BOOL ok = SHGetPathFromIDList(pidl, m_path.GetWriteBuf(MAX_PATH));
-    m_path.UngetWriteBuf();
+    BOOL ok = SHGetPathFromIDList(pidl, wxStringBuffer(m_path, MAX_PATH));
 
     ItemListFree(pidl);
 
 
     ItemListFree(pidl);
 
@@ -148,23 +225,36 @@ BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lp, LPARAM pData)
             // initial selection here
             //
             // wParam = TRUE => lParam is a string and not a PIDL
             // initial selection here
             //
             // wParam = TRUE => lParam is a string and not a PIDL
+#ifndef __WXWINCE__
             SendMessage(hwnd, BFFM_SETSELECTION, TRUE, pData);
             SendMessage(hwnd, BFFM_SETSELECTION, TRUE, pData);
+#endif
             break;
 
         case BFFM_SELCHANGED:
             break;
 
         case BFFM_SELCHANGED:
+            // note that this doesn't work with the new style UI (MSDN doesn't
+            // say anything about it, but the comments in shlobj.h do!) but we
+            // still execute this code in case it starts working again with the
+            // "new new UI" (or would it be "NewUIEx" according to tradition?)
             {
                 // Set the status window to the currently selected path.
             {
                 // Set the status window to the currently selected path.
-                TCHAR szDir[MAX_PATH];
-                if ( SHGetPathFromIDList((LPITEMIDLIST)lp, szDir) )
+                wxString strDir;
+                if ( SHGetPathFromIDList((LPITEMIDLIST)lp,
+                                         wxStringBuffer(strDir, MAX_PATH)) )
                 {
                 {
-                    wxString strDir(szDir);
-                    int maxChars = 40; // Have to truncate string else it displays incorrectly
-                    if (strDir.Len() > (size_t) (maxChars - 3))
+                    // NB: this shouldn't be necessary with the new style box
+                    //     (which is resizable), but as for now it doesn't work
+                    //     anyhow (see the comment above) no harm in doing it
+
+                    // need to truncate or it displays incorrectly
+                    static const size_t maxChars = 37;
+                    if ( strDir.length() > maxChars )
                     {
                     {
-                        strDir = strDir.Right(maxChars - 3);
+                        strDir = strDir.Right(maxChars);
                         strDir = wxString(wxT("...")) + strDir;
                     }
                         strDir = wxString(wxT("...")) + strDir;
                     }
-                    SendMessage(hwnd, BFFM_SETSTATUSTEXT, 0, (LPARAM) (const wxChar*) strDir);
+
+                    SendMessage(hwnd, BFFM_SETSTATUSTEXT,
+                                0, (LPARAM)strDir.c_str());
                 }
             }
             break;
                 }
             }
             break;