STLSoft - ... Robust, Lightweight, Cross-platform, Template Software ... ATLSTL - Template Software for the Active Template Library COMSTL - The Standard Template Library meets the Component Object Model .netSTL - Standard Template Library meets the Microsoft.NET Common Language Runtime InetSTL - The Standard Template Library meets WinInet MFCSTL - Template Software for the Microsoft Foundation Classes UNIXSTL - Template Software for the UNIX Operating System WinSTL - where the Standard Template Library meets the Win32 API

Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

winstl_shell_browse.h

Go to the documentation of this file.
00001 /* 
00002  * File:        winstl_shell_browse.h
00003  *
00004  * Purpose:     shell_browsing class.
00005  *
00006  * Created:     2nd March 2002
00007  * Updated:     11th September 2004
00008  *
00009  * Home:        http://stlsoft.org/
00010  *
00011  * Copyright (c) 2002-2004, Matthew Wilson and Synesis Software
00012  * All rights reserved.
00013  *
00014  * Redistribution and use in source and binary forms, with or without
00015  * modification, are permitted provided that the following conditions are met:
00016  *
00017  * - Redistributions of source code must retain the above copyright notice, this
00018  *   list of conditions and the following disclaimer.
00019  * - Redistributions in binary form must reproduce the above copyright notice,
00020  *   this list of conditions and the following disclaimer in the documentation
00021  *   and/or other materials provided with the distribution.
00022  * - Neither the name(s) of Matthew Wilson and Synesis Software nor the names of
00023  *   any contributors may be used to endorse or promote products derived from
00024  *   this software without specific prior written permission.
00025  *
00026  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00027  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00028  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00029  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00030  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00031  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00032  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00033  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00034  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00035  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00036  * POSSIBILITY OF SUCH DAMAGE.
00037  *
00038  * 
00039 
00040 
00044 
00045 #ifndef WINSTL_INCL_H_WINSTL_SHELL_BROWSE
00046 #define WINSTL_INCL_H_WINSTL_SHELL_BROWSE
00047 
00048 #ifndef __STLSOFT_DOCUMENTATION_SKIP_SECTION
00049 # define WINSTL_VER_H_WINSTL_SHELL_BROWSE_MAJOR       2
00050 # define WINSTL_VER_H_WINSTL_SHELL_BROWSE_MINOR       0
00051 # define WINSTL_VER_H_WINSTL_SHELL_BROWSE_REVISION    1
00052 # define WINSTL_VER_H_WINSTL_SHELL_BROWSE_EDIT        31
00053 #endif /* !__STLSOFT_DOCUMENTATION_SKIP_SECTION */
00054 
00055 /* 
00056  * Includes.
00057  */
00058 
00059 #ifndef WINSTL_INCL_H_WINSTL
00060 # include "winstl.h"                    // Include the WinSTL root header
00061 #endif /* !WINSTL_INCL_H_WINSTL */
00062 #ifndef WINSTL_INCL_H_WINSTL_SHELL_ALLOCATOR
00063 # include "winstl_shell_allocator.h"    // shell_allocator
00064 #endif /* !WINSTL_INCL_H_WINSTL_SHELL_ALLOCATOR */
00065 #ifndef STLSOFT_INCL_H_STLSOFT_STRING_ACCESS
00066 # include "stlsoft_string_access.h"     // stlsoft::c_str_ptr
00067 #endif /* !STLSOFT_INCL_H_STLSOFT_STRING_ACCESS */
00068 #ifndef WINSTL_INCL_H_WINSTL_STRING_ACCESS
00069 # include "winstl_string_access.h"      // stlsoft::c_str_ptr
00070 #endif /* !WINSTL_INCL_H_WINSTL_STRING_ACCESS */
00071 
00072 /* 
00073  * Namespace
00074  */
00075 
00076 #ifndef _WINSTL_NO_NAMESPACE
00077 # if defined(_STLSOFT_NO_NAMESPACE) || \
00078      defined(__STLSOFT_DOCUMENTATION_SKIP_SECTION)
00079 /* There is no stlsoft namespace, so must define ::winstl */
00080 namespace winstl
00081 {
00082 # else
00083 /* Define stlsoft::winstl_project */
00084 
00085 namespace stlsoft
00086 {
00087 
00088 namespace winstl_project
00089 {
00090 
00091 # endif /* _STLSOFT_NO_NAMESPACE */
00092 #endif /* !_WINSTL_NO_NAMESPACE */
00093 
00094 #if !defined(__STLSOFT_COMPILER_IS_MWERKS)
00095 stlsoft_ns_using(c_str_ptr)
00096 #endif /* compiler */
00097 
00098 /* 
00099  * Classes
00100  */
00101 
00102 // struct shell_browse_traits
00103 
00104 #ifdef __STLSOFT_DOCUMENTATION_SKIP_SECTION
00111 template <ss_typename_param_k C>
00112 struct shell_browse_traits
00113 {
00115     typedef BROWSEINFO     browseinfo_t;
00116 
00118     static LPITEMIDLIST browseforfolder(browseinfo_t *bi);
00123     static BOOL getpathfromidlist(LPCITEMIDLIST pidl, ws_char_a_t *pszPath);
00124 };
00125 
00126 #else
00127 
00128 // class shell_browse_traits
00129 template <ss_typename_param_k C>
00130 struct shell_browse_traits;
00131 
00132 STLSOFT_TEMPLATE_SPECIALISATION
00133 struct shell_browse_traits<ws_char_a_t>
00134 {
00135 public:
00136     typedef BROWSEINFOA     browseinfo_t;
00137 
00138     static LPITEMIDLIST browseforfolder(browseinfo_t *bi)
00139     {
00140         return SHBrowseForFolderA(bi);
00141     }
00142 
00143     static BOOL getpathfromidlist(LPCITEMIDLIST pidl, ws_char_a_t *pszPath)
00144     {
00145         return SHGetPathFromIDListA(pidl, pszPath);
00146     }
00147 };
00148 
00149 STLSOFT_TEMPLATE_SPECIALISATION
00150 struct shell_browse_traits<ws_char_w_t>
00151 {
00152 public:
00153     typedef BROWSEINFOW     browseinfo_t;
00154 
00155     static LPITEMIDLIST browseforfolder(browseinfo_t *bi)
00156     {
00157         return SHBrowseForFolderW(bi);
00158     }
00159 
00160     static BOOL getpathfromidlist(LPCITEMIDLIST pidl, ws_char_w_t *pszPath)
00161     {
00162         return SHGetPathFromIDListW(pidl, pszPath);
00163     }
00164 };
00165 
00166 #endif /* !__STLSOFT_DOCUMENTATION_SKIP_SECTION */
00167 
00168 /* 
00169  * Functions
00170  */
00171 
00172 // function shell_browse
00180 template<   ss_typename_param_k S
00181         ,   ss_typename_param_k C
00182         >
00183 inline ws_bool_t shell_browse(const S &title, C *displayName, UINT flags, HWND hwndOwner, LPCITEMIDLIST pidlRoot)
00184 {
00185     typedef shell_browse_traits<C>                  traits_type;
00186     ss_typename_type_k traits_type::browseinfo_t    browseinfo;
00187     LPITEMIDLIST                                    lpiidl;
00188     ws_bool_t                                       bRet    =   false;
00189 
00190     browseinfo.hwndOwner        =   hwndOwner;
00191     browseinfo.pidlRoot         =   pidlRoot;
00192     browseinfo.pszDisplayName   =   displayName;
00193     browseinfo.lpszTitle        =   c_str_ptr(title);
00194     browseinfo.ulFlags          =   flags;
00195     browseinfo.lpfn             =   0;
00196     browseinfo.lParam           =   0;
00197 
00198     lpiidl                      =   traits_type::browseforfolder(&browseinfo);
00199 
00200     if(lpiidl != 0)
00201     {
00202         if(traits_type::getpathfromidlist(lpiidl, displayName))
00203         {
00204             bRet = true;
00205         }
00206 
00207         shell_allocator<ITEMIDLIST>().deallocate(lpiidl);
00208     }
00209 
00210     if(!bRet)
00211     {
00212         displayName[0] = '\0';
00213     }
00214 
00215     return bRet;
00216 }
00217 
00224 template<   ss_typename_param_k S
00225         ,   ss_typename_param_k C
00226         >
00227 inline ws_bool_t shell_browse(const S &title, C *displayName, UINT flags, HWND hwndOwner)
00228 {
00229     return shell_browse(title, displayName, flags, hwndOwner, static_cast<LPCITEMIDLIST>(0));
00230 }
00231 
00238 template<   ss_typename_param_k S
00239         ,   ss_typename_param_k C
00240         >
00241 inline ws_bool_t shell_browse(const S &title, C *displayName, UINT flags, LPCITEMIDLIST pidlRoot)
00242 {
00243     return shell_browse(title, displayName, flags, 0, pidlRoot);
00244 }
00245 
00251 template<   ss_typename_param_k S
00252         ,   ss_typename_param_k C
00253         >
00254 inline ws_bool_t shell_browse(const S &title, C *displayName, UINT flags)
00255 {
00256     return shell_browse(title, displayName, flags, 0, 0);
00257 }
00258 
00263 template<   ss_typename_param_k S
00264         ,   ss_typename_param_k C
00265         >
00266 inline ws_bool_t shell_browse(const S &title, C *displayName)
00267 {
00268     return shell_browse(title, displayName, 0, 0, 0);
00269 }
00270 
00272 // Unit-testing
00273 
00274 #ifdef STLSOFT_UNITTEST
00275 
00276 namespace unittest
00277 {
00278     ss_bool_t test_winstl_shell_browse(unittest_reporter *r)
00279     {
00280         using stlsoft::unittest::unittest_initialiser;
00281 
00282         ss_bool_t               bSuccess    =   true;
00283 
00284         unittest_initialiser    init(r, "WinSTL", "shell_browse", __FILE__);
00285 
00286 #if 0
00287         if(<<TODO>>)
00288         {
00289             r->report("<<TODO>> failed ", __LINE__);
00290             bSuccess = false;
00291         }
00292 #endif /* 0 */
00293 
00294         return bSuccess;
00295     }
00296 
00297     unittest_registrar    unittest_winstl_shell_browse(test_winstl_shell_browse);
00298 
00299 } // namespace unittest
00300 
00301 #endif /* STLSOFT_UNITTEST */
00302 
00303 /* 
00304 
00305 #ifndef _WINSTL_NO_NAMESPACE
00306 # if defined(_STLSOFT_NO_NAMESPACE) || \
00307      defined(__STLSOFT_DOCUMENTATION_SKIP_SECTION)
00308 } // namespace winstl
00309 # else
00310 } // namespace winstl_project
00311 } // namespace stlsoft
00312 # endif /* _STLSOFT_NO_NAMESPACE */
00313 #endif /* !_WINSTL_NO_NAMESPACE */
00314 
00315 /* 
00316 
00317 #endif /* WINSTL_INCL_H_WINSTL_SHELL_BROWSE */
00318 
00319 /* 

STLSoft Libraries documentation © Synesis Software Pty Ltd, 2001-2004