X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/da03e3303f63960ee75b4bfa7d1319f337a728fa..fe4fcb5f4f4fc7ee4c116673c213f53b2bc798fc:/src/msw/dirdlg.cpp diff --git a/src/msw/dirdlg.cpp b/src/msw/dirdlg.cpp index 7e4d420847..0bb55362d5 100644 --- a/src/msw/dirdlg.cpp +++ b/src/msw/dirdlg.cpp @@ -5,7 +5,7 @@ // Modified by: // Created: 01/02/97 // RCS-ID: $Id$ -// Copyright: (c) Julian Smart and Markus Holzem +// Copyright: (c) Julian Smart // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -17,7 +17,7 @@ // headers // ---------------------------------------------------------------------------- -#ifdef __GNUG__ +#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) #pragma implementation "dirdlg.h" #endif @@ -28,7 +28,7 @@ #pragma hdrstop #endif -#if wxUSE_DIRDLG +#if wxUSE_DIRDLG && !(defined(__SMARTPHONE__) && defined(__WXWINCE__)) #if defined(__WIN95__) && !defined(__GNUWIN32_OLD__) && wxUSE_OLE @@ -37,22 +37,30 @@ #include "wx/dialog.h" #include "wx/dirdlg.h" #include "wx/log.h" + #include "wx/app.h" // for GetComCtl32Version() #endif #include "wx/msw/private.h" - -#include // Win95 shell +#include "wx/msw/wrapshl.h" // ---------------------------------------------------------------------------- // constants // ---------------------------------------------------------------------------- -#ifndef MAX_PATH - #define MAX_PATH 4096 // be generous +#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 +// wxWidgets macros // ---------------------------------------------------------------------------- IMPLEMENT_CLASS(wxDirDialog, wxDialog) @@ -61,9 +69,6 @@ IMPLEMENT_CLASS(wxDirDialog, wxDialog) // private functions prototypes // ---------------------------------------------------------------------------- -// free the parameter -static void ItemListFree(LPITEMIDLIST pidl); - // the callback proc for the dir dlg static int CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lp, LPARAM pData); @@ -80,12 +85,15 @@ static int CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lp, 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; - + + SetStyle(style); SetPath(defaultPath); } @@ -119,37 +127,65 @@ int wxDirDialog::ShowModal() bi.hwndOwner = parent ? GetHwndOf(parent) : NULL; bi.pidlRoot = NULL; bi.pszDisplayName = NULL; + // Please don't change this without checking it compiles + // with eVC++ first. +#if defined(__POCKETPC__) || defined(__SMARTPHONE__) + bi.lpszTitle = m_message.mb_str(); +#else 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 - LPITEMIDLIST pidl = SHBrowseForFolder(&bi); + static const int verComCtl32 = wxApp::GetComCtl32Version(); - if ( bi.pidlRoot ) + // we always add the edit box (it doesn't hurt anybody, does it?) if it is + // supported by the system + if ( verComCtl32 >= 471 ) { - ItemListFree((LPITEMIDLIST)bi.pidlRoot); + bi.ulFlags |= BIF_EDITBOX; } - if ( !pidl ) + // 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) ) { - // Cancel button pressed - return wxID_CANCEL; + 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; + } + } } - BOOL ok = SHGetPathFromIDList(pidl, m_path.GetWriteBuf(MAX_PATH)); - m_path.UngetWriteBuf(); + // do show the dialog + wxItemIdList pidl(SHBrowseForFolder(&bi)); - ItemListFree(pidl); + wxItemIdList::Free((LPITEMIDLIST)bi.pidlRoot); - if ( !ok ) + if ( !pidl ) { - wxLogLastError(wxT("SHGetPathFromIDList")); - + // Cancel button pressed return wxID_CANCEL; } - return wxID_OK; + m_path = pidl.GetPath(); + + return m_path.empty() ? wxID_CANCEL : wxID_OK; } // ---------------------------------------------------------------------------- @@ -161,28 +197,42 @@ BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lp, LPARAM pData) { switch(uMsg) { +#ifdef BFFM_SETSELECTION case BFFM_INITIALIZED: // sent immediately after initialisation and so we may set the // initial selection here // // wParam = TRUE => lParam is a string and not a PIDL - SendMessage(hwnd, BFFM_SETSELECTION, TRUE, pData); + ::SendMessage(hwnd, BFFM_SETSELECTION, TRUE, pData); break; +#endif // BFFM_SETSELECTION + 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. - 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; } - SendMessage(hwnd, BFFM_SETSTATUSTEXT, 0, (LPARAM) (const wxChar*) strDir); + + SendMessage(hwnd, BFFM_SETSTATUSTEXT, + 0, (LPARAM)strDir.c_str()); } } break; @@ -195,26 +245,8 @@ BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lp, LPARAM pData) } -static void ItemListFree(LPITEMIDLIST pidl) -{ - if ( pidl ) - { - LPMALLOC pMalloc; - SHGetMalloc(&pMalloc); - if ( pMalloc ) - { - pMalloc->Free(pidl); - pMalloc->Release(); - } - else - { - wxLogLastError(wxT("SHGetMalloc")); - } - } -} - #else #include "../generic/dirdlgg.cpp" #endif // compiler/platform on which the code here compiles -#endif // wxUSE_DIRDLG +#endif // wxUSE_DIRDLG && !(__SMARTPHONE__ && __WXWINCE__)