00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00050 #ifndef WINSTL_INCL_WINSTL_SHELL_HPP_BROWSE_FOR_FOLDER
00051 #define WINSTL_INCL_WINSTL_SHELL_HPP_BROWSE_FOR_FOLDER
00052
00053 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00054 # define WINSTL_VER_WINSTL_SHELL_HPP_BROWSE_FOR_FOLDER_MAJOR 4
00055 # define WINSTL_VER_WINSTL_SHELL_HPP_BROWSE_FOR_FOLDER_MINOR 2
00056 # define WINSTL_VER_WINSTL_SHELL_HPP_BROWSE_FOR_FOLDER_REVISION 5
00057 # define WINSTL_VER_WINSTL_SHELL_HPP_BROWSE_FOR_FOLDER_EDIT 62
00058 #endif
00059
00060
00061
00062
00063
00064 #ifndef WINSTL_INCL_WINSTL_H_WINSTL
00065 # include <winstl/winstl.h>
00066 #endif
00067 #ifndef WINSTL_INCL_WINSTL_MEMORY_HPP_SHELL_ALLOCATOR
00068 # include <winstl/memory/shell_allocator.hpp>
00069 #endif
00070 #ifndef STLSOFT_INCL_STLSOFT_SHIMS_ACCESS_HPP_STRING
00071 # include <stlsoft/shims/access/string.hpp>
00072 #endif
00073 #ifndef WINSTL_INCL_WINSTL_SHIMS_ACCESS_HPP_STRING
00074 # include <winstl/shims/access/string.hpp>
00075 #endif
00076
00077 #ifdef STLSOFT_UNITTEST
00078 # include <string>
00079 #endif
00080
00081
00082
00083
00084
00085 #ifndef _WINSTL_NO_NAMESPACE
00086 # if defined(_STLSOFT_NO_NAMESPACE) || \
00087 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00088
00089 namespace winstl
00090 {
00091 # else
00092
00093
00094 namespace stlsoft
00095 {
00096
00097 namespace winstl_project
00098 {
00099
00100 # endif
00101 #endif
00102
00103
00104
00105
00106
00107
00108
00109 #ifdef STLSOFT_DOCUMENTATION_SKIP_SECTION
00110
00117 template <ss_typename_param_k C>
00118 struct shell_browse_traits
00119 {
00121 typedef BROWSEINFO browseinfo_t;
00122
00124 static LPITEMIDLIST browseforfolder(browseinfo_t *bi);
00129 static BOOL getpathfromidlist(LPCITEMIDLIST pidl, ws_char_a_t *pszPath);
00130 };
00131
00132 #else
00133
00134
00135 template <ss_typename_param_k C>
00136 struct shell_browse_traits;
00137
00138 STLSOFT_TEMPLATE_SPECIALISATION
00139 struct shell_browse_traits<ws_char_a_t>
00140 {
00141 public:
00142 typedef BROWSEINFOA browseinfo_t;
00143
00144 static LPITEMIDLIST browseforfolder(browseinfo_t *bi)
00145 {
00146 return ::SHBrowseForFolderA(bi);
00147 }
00148
00149 static BOOL getpathfromidlist(LPCITEMIDLIST pidl, ws_char_a_t *pszPath)
00150 {
00151 return ::SHGetPathFromIDListA(pidl, pszPath);
00152 }
00153 };
00154
00155 STLSOFT_TEMPLATE_SPECIALISATION
00156 struct shell_browse_traits<ws_char_w_t>
00157 {
00158 public:
00159 typedef BROWSEINFOW browseinfo_t;
00160
00161 static LPITEMIDLIST browseforfolder(browseinfo_t *bi)
00162 {
00163 return ::SHBrowseForFolderW(bi);
00164 }
00165
00166 static BOOL getpathfromidlist(LPCITEMIDLIST pidl, ws_char_w_t *pszPath)
00167 {
00168 return ::SHGetPathFromIDListW(pidl, pszPath);
00169 }
00170 };
00171
00172 template <ss_typename_param_k C>
00173 struct shell_browse_callback_holder
00174 {
00175 static int CALLBACK proc( HWND hwnd
00176 , UINT uMsg
00177 , LPARAM
00178 , LPARAM lpData)
00179 {
00180 if(BFFM_INITIALIZED == uMsg)
00181 {
00182 C const* path = reinterpret_cast<C const*>(lpData);
00183
00184 ::SendMessage(hwnd, BFFM_SETSELECTION, TRUE, reinterpret_cast<LPARAM>(path));
00185 }
00186
00187 return 0;
00188 }
00189 };
00190
00191 #endif
00192
00193
00194
00195
00196
00197 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00198 template <ss_typename_param_k C>
00199 inline ws_bool_t shell_browse_impl( C const* title
00200 , C* displayName
00201 , UINT flags
00202 , HWND hwndOwner
00203 , LPCITEMIDLIST pidlRoot
00204 , C const* defaultFolder)
00205 {
00206 typedef shell_browse_traits<C> traits_type;
00207 ss_typename_type_k traits_type::browseinfo_t browseinfo;
00208 LPITEMIDLIST lpiidl;
00209 ws_bool_t bRet = false;
00210
00211 browseinfo.hwndOwner = hwndOwner;
00212 browseinfo.pidlRoot = pidlRoot;
00213 browseinfo.pszDisplayName = displayName;
00214 browseinfo.lpszTitle = title;
00215 browseinfo.ulFlags = flags;
00216
00217 if( NULL != defaultFolder &&
00218 '\0' != *defaultFolder)
00219 {
00220 browseinfo.lpfn = &shell_browse_callback_holder<C>::proc;
00221 browseinfo.lParam = reinterpret_cast<LPARAM>(defaultFolder);
00222 }
00223 else
00224 {
00225 browseinfo.lpfn = 0;
00226 browseinfo.lParam = 0;
00227 }
00228
00229 lpiidl = traits_type::browseforfolder(&browseinfo);
00230
00231 if(lpiidl != 0)
00232 {
00233 if(traits_type::getpathfromidlist(lpiidl, displayName))
00234 {
00235 bRet = true;
00236 }
00237
00238 shell_allocator<ITEMIDLIST>().deallocate(lpiidl);
00239 }
00240
00241 if(!bRet)
00242 {
00243 displayName[0] = '\0';
00244 }
00245
00246 return bRet;
00247 }
00248 #endif
00249
00250
00251
00262 template< ss_typename_param_k S
00263 , ss_typename_param_k C
00264 >
00265 inline ws_bool_t browse_for_folder(S const& title, C* displayName, UINT flags, HWND hwndOwner, LPCITEMIDLIST pidlRoot)
00266 {
00267 return shell_browse_impl(stlsoft_ns_qual(c_str_ptr)(title), displayName, flags, hwndOwner, pidlRoot, static_cast<C const*>(NULL));
00268 }
00269
00281 template< ss_typename_param_k S0
00282 , ss_typename_param_k C
00283 , ss_typename_param_k S1
00284 >
00285 inline ws_bool_t browse_for_folder(S0 const& title, C* displayName, UINT flags, HWND hwndOwner, LPCITEMIDLIST pidlRoot, S1 const& defaultFolder)
00286 {
00287 return shell_browse_impl(stlsoft_ns_qual(c_str_ptr)(title), displayName, flags, hwndOwner, pidlRoot, stlsoft_ns_qual(c_str_ptr)(defaultFolder));
00288 }
00289
00299 template< ss_typename_param_k S
00300 , ss_typename_param_k C
00301 >
00302 inline ws_bool_t browse_for_folder(S const& title, C* displayName, UINT flags, HWND hwndOwner)
00303 {
00304 return browse_for_folder(title, displayName, flags, hwndOwner, static_cast<LPCITEMIDLIST>(0));
00305 }
00306
00316 template< ss_typename_param_k S
00317 , ss_typename_param_k C
00318 >
00319 inline ws_bool_t browse_for_folder(S const& title, C* displayName, UINT flags, LPCITEMIDLIST pidlRoot)
00320 {
00321 return browse_for_folder(title, displayName, flags, 0, pidlRoot);
00322 }
00323
00332 template< ss_typename_param_k S
00333 , ss_typename_param_k C
00334 >
00335 inline ws_bool_t browse_for_folder(S const& title, C* displayName, UINT flags)
00336 {
00337 return browse_for_folder(title, displayName, flags, 0, 0);
00338 }
00339
00340 #if !defined(STLSOFT_COMPILER_IS_DMC) && \
00341 !defined(STLSOFT_COMPILER_IS_MWERKS) && \
00342 ( !defined(STLSOFT_COMPILER_IS_MSVC) || \
00343 _MSC_VER != 1300)
00344
00353 template< ss_typename_param_k S0
00354 , ss_typename_param_k C
00355 , ss_typename_param_k S1
00356 >
00357 inline ws_bool_t browse_for_folder( S0 const &title
00358 , C *displayName
00359 , UINT flags
00360 , S1 const &defaultFolder
00361 )
00362 {
00363 return browse_for_folder(title, displayName, flags, 0, 0, defaultFolder);
00364 }
00365
00366 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00367
00368
00369
00370
00371
00372 template< ss_typename_param_k S
00373 , ss_typename_param_k C
00374 >
00375 inline ws_bool_t browse_for_folder(S const& title, C* displayName, UINT flags, LPITEMIDLIST pidlRoot)
00376 {
00377 return browse_for_folder(title, displayName, flags, const_cast<LPCITEMIDLIST>(pidlRoot));
00378 }
00379 #endif
00380
00381 #endif
00382
00390 template< ss_typename_param_k S
00391 , ss_typename_param_k C
00392 >
00393 inline ws_bool_t browse_for_folder(S const& title, C* displayName)
00394 {
00395 return browse_for_folder(title, displayName, 0, 0, 0);
00396 }
00397
00399
00400
00401 #ifdef STLSOFT_UNITTEST
00402 # include "./unittest/browse_for_folder_unittest_.h"
00403 #endif
00404
00405
00406
00407 #ifndef _WINSTL_NO_NAMESPACE
00408 # if defined(_STLSOFT_NO_NAMESPACE) || \
00409 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00410 }
00411 # else
00412 }
00413 }
00414 # endif
00415 #endif
00416
00417
00418
00419 #endif
00420
00421