// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
+
#ifdef __GNUG__
#pragma implementation "dirdlg.h"
#endif
#pragma hdrstop
#endif
+#if wxUSE_DIRDLG
+
+#if defined(__WIN95__) && !defined(__GNUWIN32_OLD__) && wxUSE_OLE
+
#ifndef WX_PRECOMP
#include "wx/utils.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"
-#if defined(__WIN95__) && \
- (!defined(__GNUWIN32__) || defined(wxUSE_NORLANDER_HEADERS))
- #define CAN_COMPILE_DIRDLG
-//#else: we provide a stub version which doesn't do anything
-#endif
-
-#ifdef CAN_COMPILE_DIRDLG
- #include "shlobj.h" // Win95 shell
-#endif
+#include <shlobj.h> // Win95 shell
// ----------------------------------------------------------------------------
// constants
// ----------------------------------------------------------------------------
#ifndef MAX_PATH
- #define MAX_PATH 4096 // be generuous
+ #define MAX_PATH 4096 // be generous
#endif
// ----------------------------------------------------------------------------
// wxWindows macros
// ----------------------------------------------------------------------------
-#if !USE_SHARED_LIBRARY
- IMPLEMENT_CLASS(wxDirDialog, wxDialog)
-#endif
+IMPLEMENT_CLASS(wxDirDialog, wxDialog)
// ----------------------------------------------------------------------------
// private functions prototypes
static int CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lp,
LPARAM pData);
+
// ============================================================================
// implementation
// ============================================================================
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_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("\\"));
+ if ( !m_path.empty() )
+ {
+ 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('\\');
+ }
+ }
+}
+
+#ifndef BIF_NEWDIALOGSTYLE
+#define BIF_NEWDIALOGSTYLE 0x0040
+#endif
+
int wxDirDialog::ShowModal()
{
-#ifdef CAN_COMPILE_DIRDLG
+ wxWindow *parent = GetParent();
+
BROWSEINFO bi;
- bi.hwndOwner = m_parent ? GetHwndOf(m_parent) : NULL;
+ bi.hwndOwner = parent ? GetHwndOf(parent) : NULL;
bi.pidlRoot = NULL;
bi.pszDisplayName = NULL;
bi.lpszTitle = m_message.c_str();
bi.lpfn = BrowseCallbackProc;
bi.lParam = (LPARAM)m_path.c_str(); // param for the callback
+ if ((GetStyle() & wxDD_NEW_DIR_BUTTON) &&
+ (wxApp::GetComCtl32Version() >= 500))
+ {
+ bi.ulFlags |= BIF_NEWDIALOGSTYLE;
+ }
+
LPITEMIDLIST pidl = SHBrowseForFolder(&bi);
if ( bi.pidlRoot )
if ( !ok )
{
- wxLogLastError("SHGetPathFromIDList");
+ wxLogLastError(wxT("SHGetPathFromIDList"));
return wxID_CANCEL;
}
return wxID_OK;
-#else // !CAN_COMPILE_DIRDLG
- return wxID_CANCEL;
-#endif // CAN_COMPILE_DIRDLG/!CAN_COMPILE_DIRDLG
}
// ----------------------------------------------------------------------------
TCHAR szDir[MAX_PATH];
if ( SHGetPathFromIDList((LPITEMIDLIST)lp, szDir) )
{
- SendMessage(hwnd, BFFM_SETSTATUSTEXT, 0, (LPARAM)szDir);
+ wxString strDir(szDir);
+ int maxChars = 40; // Have to truncate string else it displays incorrectly
+ if (strDir.Len() > (size_t) (maxChars - 3))
+ {
+ strDir = strDir.Right(maxChars - 3);
+ strDir = wxString(wxT("...")) + strDir;
+ }
+ SendMessage(hwnd, BFFM_SETSTATUSTEXT, 0, (LPARAM) (const wxChar*) strDir);
}
}
break;
}
else
{
- wxLogLastError("SHGetMalloc");
+ wxLogLastError(wxT("SHGetMalloc"));
}
}
}
+#else
+ #include "../generic/dirdlgg.cpp"
+#endif // compiler/platform on which the code here compiles
+
+#endif // wxUSE_DIRDLG