]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/dirdlg.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxDirDialog
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #pragma implementation "dirdlg.h"
23 // For compilers that support precompilation, includes "wx.h".
24 #include "wx/wxprec.h"
30 #if defined(__WIN95__) && !defined(__GNUWIN32_OLD__)
34 #include "wx/dialog.h"
35 #include "wx/dirdlg.h"
39 #include "wx/msw/private.h"
41 #include "shlobj.h" // Win95 shell
43 // ----------------------------------------------------------------------------
45 // ----------------------------------------------------------------------------
48 #define MAX_PATH 4096 // be generous
51 // ----------------------------------------------------------------------------
53 // ----------------------------------------------------------------------------
55 IMPLEMENT_CLASS(wxDirDialog
, wxDialog
)
57 // ----------------------------------------------------------------------------
58 // private functions prototypes
59 // ----------------------------------------------------------------------------
62 static void ItemListFree(LPITEMIDLIST pidl
);
64 // the callback proc for the dir dlg
65 static int CALLBACK
BrowseCallbackProc(HWND hwnd
, UINT uMsg
, LPARAM lp
,
69 // ============================================================================
71 // ============================================================================
73 // ----------------------------------------------------------------------------
75 // ----------------------------------------------------------------------------
77 wxDirDialog::wxDirDialog(wxWindow
*parent
,
78 const wxString
& message
,
79 const wxString
& defaultPath
,
81 const wxPoint
& WXUNUSED(pos
))
86 m_path
.Replace(_T("/"), _T("\\")); // SHBrowseForFolder doesn't like '/'s
89 int wxDirDialog::ShowModal()
92 bi
.hwndOwner
= m_parent
? GetHwndOf(m_parent
) : NULL
;
94 bi
.pszDisplayName
= NULL
;
95 bi
.lpszTitle
= m_message
.c_str();
96 bi
.ulFlags
= BIF_RETURNONLYFSDIRS
| BIF_STATUSTEXT
;
97 bi
.lpfn
= BrowseCallbackProc
;
98 bi
.lParam
= (LPARAM
)m_path
.c_str(); // param for the callback
100 LPITEMIDLIST pidl
= SHBrowseForFolder(&bi
);
104 ItemListFree((LPITEMIDLIST
)bi
.pidlRoot
);
109 // Cancel button pressed
113 BOOL ok
= SHGetPathFromIDList(pidl
, m_path
.GetWriteBuf(MAX_PATH
));
114 m_path
.UngetWriteBuf();
120 wxLogLastError(wxT("SHGetPathFromIDList"));
128 // ----------------------------------------------------------------------------
130 // ----------------------------------------------------------------------------
133 BrowseCallbackProc(HWND hwnd
, UINT uMsg
, LPARAM lp
, LPARAM pData
)
137 case BFFM_INITIALIZED
:
138 // sent immediately after initialisation and so we may set the
139 // initial selection here
141 // wParam = TRUE => lParam is a string and not a PIDL
142 SendMessage(hwnd
, BFFM_SETSELECTION
, TRUE
, pData
);
145 case BFFM_SELCHANGED
:
147 // Set the status window to the currently selected path.
148 TCHAR szDir
[MAX_PATH
];
149 if ( SHGetPathFromIDList((LPITEMIDLIST
)lp
, szDir
) )
151 wxString
strDir(szDir
);
152 int maxChars
= 40; // Have to truncate string else it displays incorrectly
153 if (strDir
.Len() > (size_t) (maxChars
- 3))
155 strDir
= strDir
.Right(maxChars
- 3);
156 strDir
= wxString(wxT("...")) + strDir
;
158 SendMessage(hwnd
, BFFM_SETSTATUSTEXT
, 0, (LPARAM
) (const wxChar
*) strDir
);
163 //case BFFM_VALIDATEFAILED: -- might be used to provide custom message
164 // if the user types in invalid dir name
171 static void ItemListFree(LPITEMIDLIST pidl
)
176 SHGetMalloc(&pMalloc
);
184 wxLogLastError(wxT("SHGetMalloc"));
190 #include "../generic/dirdlgg.cpp"
191 #endif // compiler/platform on which the code here compiles