]>
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 // ----------------------------------------------------------------------------
21 #pragma implementation "dirdlg.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
35 #if defined(__WIN95__) && !defined(__GNUWIN32_OLD__) && wxUSE_OLE
39 #include "wx/dialog.h"
40 #include "wx/dirdlg.h"
44 #include "wx/msw/private.h"
46 #include "shlobj.h" // Win95 shell
48 // ----------------------------------------------------------------------------
50 // ----------------------------------------------------------------------------
53 #define MAX_PATH 4096 // be generous
56 // ----------------------------------------------------------------------------
58 // ----------------------------------------------------------------------------
60 IMPLEMENT_CLASS(wxDirDialog
, wxDialog
)
62 // ----------------------------------------------------------------------------
63 // private functions prototypes
64 // ----------------------------------------------------------------------------
67 static void ItemListFree(LPITEMIDLIST pidl
);
69 // the callback proc for the dir dlg
70 static int CALLBACK
BrowseCallbackProc(HWND hwnd
, UINT uMsg
, LPARAM lp
,
74 // ============================================================================
76 // ============================================================================
78 // ----------------------------------------------------------------------------
80 // ----------------------------------------------------------------------------
82 wxDirDialog::wxDirDialog(wxWindow
*parent
,
83 const wxString
& message
,
84 const wxString
& defaultPath
,
86 const wxPoint
& WXUNUSED(pos
))
91 m_path
.Replace(_T("/"), _T("\\")); // SHBrowseForFolder doesn't like '/'s
94 int wxDirDialog::ShowModal()
97 bi
.hwndOwner
= m_parent
? GetHwndOf(m_parent
) : NULL
;
99 bi
.pszDisplayName
= NULL
;
100 bi
.lpszTitle
= m_message
.c_str();
101 bi
.ulFlags
= BIF_RETURNONLYFSDIRS
| BIF_STATUSTEXT
;
102 bi
.lpfn
= BrowseCallbackProc
;
103 bi
.lParam
= (LPARAM
)m_path
.c_str(); // param for the callback
105 LPITEMIDLIST pidl
= SHBrowseForFolder(&bi
);
109 ItemListFree((LPITEMIDLIST
)bi
.pidlRoot
);
114 // Cancel button pressed
118 BOOL ok
= SHGetPathFromIDList(pidl
, m_path
.GetWriteBuf(MAX_PATH
));
119 m_path
.UngetWriteBuf();
125 wxLogLastError(wxT("SHGetPathFromIDList"));
133 // ----------------------------------------------------------------------------
135 // ----------------------------------------------------------------------------
138 BrowseCallbackProc(HWND hwnd
, UINT uMsg
, LPARAM lp
, LPARAM pData
)
142 case BFFM_INITIALIZED
:
143 // sent immediately after initialisation and so we may set the
144 // initial selection here
146 // wParam = TRUE => lParam is a string and not a PIDL
147 SendMessage(hwnd
, BFFM_SETSELECTION
, TRUE
, pData
);
150 case BFFM_SELCHANGED
:
152 // Set the status window to the currently selected path.
153 TCHAR szDir
[MAX_PATH
];
154 if ( SHGetPathFromIDList((LPITEMIDLIST
)lp
, szDir
) )
156 wxString
strDir(szDir
);
157 int maxChars
= 40; // Have to truncate string else it displays incorrectly
158 if (strDir
.Len() > (size_t) (maxChars
- 3))
160 strDir
= strDir
.Right(maxChars
- 3);
161 strDir
= wxString(wxT("...")) + strDir
;
163 SendMessage(hwnd
, BFFM_SETSTATUSTEXT
, 0, (LPARAM
) (const wxChar
*) strDir
);
168 //case BFFM_VALIDATEFAILED: -- might be used to provide custom message
169 // if the user types in invalid dir name
176 static void ItemListFree(LPITEMIDLIST pidl
)
181 SHGetMalloc(&pMalloc
);
189 wxLogLastError(wxT("SHGetMalloc"));
195 #include "../generic/dirdlgg.cpp"
196 #endif // compiler/platform on which the code here compiles
198 #endif // wxUSE_DIRDLG