]>
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"
33 #if defined(__WIN95__) && !defined(__GNUWIN32_OLD__)
37 #include "wx/dialog.h"
38 #include "wx/dirdlg.h"
42 #include "wx/msw/private.h"
44 #include "shlobj.h" // Win95 shell
46 // ----------------------------------------------------------------------------
48 // ----------------------------------------------------------------------------
51 #define MAX_PATH 4096 // be generous
54 // ----------------------------------------------------------------------------
56 // ----------------------------------------------------------------------------
58 IMPLEMENT_CLASS(wxDirDialog
, wxDialog
)
60 // ----------------------------------------------------------------------------
61 // private functions prototypes
62 // ----------------------------------------------------------------------------
65 static void ItemListFree(LPITEMIDLIST pidl
);
67 // the callback proc for the dir dlg
68 static int CALLBACK
BrowseCallbackProc(HWND hwnd
, UINT uMsg
, LPARAM lp
,
72 // ============================================================================
74 // ============================================================================
76 // ----------------------------------------------------------------------------
78 // ----------------------------------------------------------------------------
80 wxDirDialog::wxDirDialog(wxWindow
*parent
,
81 const wxString
& message
,
82 const wxString
& defaultPath
,
84 const wxPoint
& WXUNUSED(pos
))
89 m_path
.Replace(_T("/"), _T("\\")); // SHBrowseForFolder doesn't like '/'s
92 int wxDirDialog::ShowModal()
95 bi
.hwndOwner
= m_parent
? GetHwndOf(m_parent
) : NULL
;
97 bi
.pszDisplayName
= NULL
;
98 bi
.lpszTitle
= m_message
.c_str();
99 bi
.ulFlags
= BIF_RETURNONLYFSDIRS
| BIF_STATUSTEXT
;
100 bi
.lpfn
= BrowseCallbackProc
;
101 bi
.lParam
= (LPARAM
)m_path
.c_str(); // param for the callback
103 LPITEMIDLIST pidl
= SHBrowseForFolder(&bi
);
107 ItemListFree((LPITEMIDLIST
)bi
.pidlRoot
);
112 // Cancel button pressed
116 BOOL ok
= SHGetPathFromIDList(pidl
, m_path
.GetWriteBuf(MAX_PATH
));
117 m_path
.UngetWriteBuf();
123 wxLogLastError(wxT("SHGetPathFromIDList"));
131 // ----------------------------------------------------------------------------
133 // ----------------------------------------------------------------------------
136 BrowseCallbackProc(HWND hwnd
, UINT uMsg
, LPARAM lp
, LPARAM pData
)
140 case BFFM_INITIALIZED
:
141 // sent immediately after initialisation and so we may set the
142 // initial selection here
144 // wParam = TRUE => lParam is a string and not a PIDL
145 SendMessage(hwnd
, BFFM_SETSELECTION
, TRUE
, pData
);
148 case BFFM_SELCHANGED
:
150 // Set the status window to the currently selected path.
151 TCHAR szDir
[MAX_PATH
];
152 if ( SHGetPathFromIDList((LPITEMIDLIST
)lp
, szDir
) )
154 wxString
strDir(szDir
);
155 int maxChars
= 40; // Have to truncate string else it displays incorrectly
156 if (strDir
.Len() > (size_t) (maxChars
- 3))
158 strDir
= strDir
.Right(maxChars
- 3);
159 strDir
= wxString(wxT("...")) + strDir
;
161 SendMessage(hwnd
, BFFM_SETSTATUSTEXT
, 0, (LPARAM
) (const wxChar
*) strDir
);
166 //case BFFM_VALIDATEFAILED: -- might be used to provide custom message
167 // if the user types in invalid dir name
174 static void ItemListFree(LPITEMIDLIST pidl
)
179 SHGetMalloc(&pMalloc
);
187 wxLogLastError(wxT("SHGetMalloc"));
193 #include "../generic/dirdlgg.cpp"
194 #endif // compiler/platform on which the code here compiles
196 #endif // wxUSE_DIRDLG