ftpicon.cpp
Upload User: xhy777
Upload Date: 2007-02-14
Package Size: 24088k
Code Size: 7k
Category:

Windows Kernel

Development Platform:

Visual C++

  1. /*****************************************************************************
  2.  *
  3.  *    ftpicon.cpp - IExtractIcon interface
  4.  *
  5.  *****************************************************************************/
  6. #include "priv.h"
  7. #include "ftpicon.h"
  8. #include "ftpurl.h"
  9. INT GetFtpIcon(UINT uFlags, BOOL fIsRoot)
  10. {
  11.     INT nIcon = (uFlags & GIL_OPENICON) ? IDI_FTPOPENFOLDER : IDI_FTPFOLDER;
  12.     if (fIsRoot)
  13.         nIcon = IDI_FTPSERVER;      // This is an FTP Server Icon.
  14.     return nIcon;
  15. }
  16. #ifndef UNICODE
  17. #define PathFindExtensionA PathFindExtension
  18. #endif
  19. //===========================
  20. // *** IExtractIconA Interface ***
  21. //===========================
  22. /*****************************************************************************
  23.     FUNCTION: GetIconLocation
  24.     DESCRIPTION:
  25.         Get the icon location from the registry.
  26.     _UNDOCUMENTED_:  Not mentioned is that if you return GIL_NOTFILENAME,
  27.     you should take steps to ensure uniqueness of the non-filename
  28.     return value, to avoid colliding with non-filenames from other
  29.     shell extensions.
  30.     _UNDOCUMENTED_:  The inability of SHGetFileInfo to work properly
  31.     on "magic internal" cached association icons like "*23" is not
  32.     documented.  As a result of this "feature", the SHGFI_ICONLOCATION
  33.     flag is useless.
  34.     Actually, we can still use SHGetFileInfo; we'll use the shell's own
  35.     feature against it.  We'll do a SHGFI_SYSICONINDEX and return that
  36.     as the icon index, with "*" as the GIL_NOTFILENAME.
  37.     _BUGBUG_: We don't handle the cases where we ought to use
  38.     GIL_SIMULATEDOC.
  39. *****************************************************************************/
  40. HRESULT CFtpIcon::GetIconLocation(UINT uFlags, LPSTR szIconFile, UINT cchMax, int *piIndex, UINT *pwFlags)
  41. {
  42.     static CHAR szMSIEFTP[MAX_PATH] = "";
  43.     if (0 == szMSIEFTP[0])
  44.         GetModuleFileNameA(HINST_THISDLL, szMSIEFTP, ARRAYSIZE(szMSIEFTP));
  45.     // NOTE: This is negative because it's a resource index.
  46.     *piIndex = (0 - GetFtpIcon(uFlags, m_nRoot));
  47.     if (pwFlags)
  48.         *pwFlags = GIL_PERCLASS; //(uFlags & GIL_OPENICON);
  49.     StrCpyNA(szIconFile, szMSIEFTP, cchMax);
  50.     return S_OK;
  51. }
  52. //===========================
  53. // *** IExtractIconW Interface ***
  54. //===========================
  55. HRESULT CFtpIcon::GetIconLocation(UINT uFlags, LPWSTR wzIconFile, UINT cchMax, int *piIndex, UINT *pwFlags)
  56. {
  57.     HRESULT hres;
  58.     CHAR szIconFile[MAX_PATH];
  59.     ASSERT_SINGLE_THREADED;
  60.     hres = GetIconLocation(uFlags, szIconFile, ARRAYSIZE(szIconFile), piIndex, pwFlags);
  61.     if (EVAL(SUCCEEDED(hres)))
  62.         SHAnsiToUnicode(szIconFile, wzIconFile, cchMax);
  63.     return hres;
  64. }
  65. //===========================
  66. // *** IQueryInfo Interface ***
  67. //===========================
  68. HRESULT CFtpIcon::GetInfoTip(DWORD dwFlags, WCHAR **ppwszTip)
  69. {
  70.     ASSERT_SINGLE_THREADED;
  71.     if (ppwszTip)       // The shell is stupid and doesn't check the return value.
  72.         *ppwszTip = NULL;
  73. //        SHStrDupW(L"", ppwszTip);
  74.     return E_NOTIMPL;
  75. /**************
  76.     // This InfoTip will appear when the user hovers over an item in defview.
  77.     // We don't want to support this now because it isn't needed and looks different
  78.     // than the shell.
  79.     HRESULT hr = E_FAIL;
  80.     LPITEMIDLIST pidl;
  81.     if (!ppwszTip)
  82.         return E_INVALIDARG;
  83.     *ppwszTip = NULL;
  84.     if (m_pflHfpl && (pidl = m_pflHfpl->GetPidl(0)))
  85.     {
  86.         WCHAR wzToolTip[MAX_URL_STRING];
  87.         hr = FtpPidl_GetDisplayName(pidl, wzItemName, ARRAYSIZE(wzItemName));
  88.         if (EVAL(SUCCEEDED(hr)))
  89.             hr = SHStrDupW(wzToolTip, ppwszTip);
  90.     }
  91.     return hr;
  92. ***********/
  93. }
  94. HRESULT CFtpIcon::GetInfoFlags(DWORD *pdwFlags)
  95. {
  96.     *pdwFlags = 0;
  97.     return S_OK;
  98. }
  99. /*****************************************************************************
  100.  *    CFtpIcon_Create
  101.  *
  102.  *    We just stash away the pflHfpl; the real work happens on the
  103.  *    GetIconLocation call.
  104.  *
  105.  *    _HACKHACK_: psf = 0 if we are being called by the property sheet code.
  106.  *****************************************************************************/
  107. HRESULT CFtpIcon_Create(CFtpFolder * pff, CFtpPidlList * pflHfpl, REFIID riid, LPVOID * ppvObj)
  108. {
  109.     HRESULT hres;
  110.     CFtpIcon * pfi;
  111.     *ppvObj = NULL;
  112.     hres = CFtpIcon_Create(pff, pflHfpl, &pfi);
  113.     if (EVAL(SUCCEEDED(hres)))
  114.     {
  115.         hres = pfi->QueryInterface(riid, ppvObj);
  116.         pfi->Release();
  117.     }
  118.     return hres;
  119. }
  120. /*****************************************************************************
  121.  *    CFtpIcon_Create
  122.  *
  123.  *    We just stash away the m_pflHfpl; the real work happens on the
  124.  *    GetIconLocation call.
  125.  *
  126.  *    _HACKHACK_: psf = 0 if we are being called by the property sheet code.
  127.  *****************************************************************************/
  128. HRESULT CFtpIcon_Create(CFtpFolder * pff, CFtpPidlList * pflHfpl, CFtpIcon ** ppfi)
  129. {
  130.     HRESULT hres= E_OUTOFMEMORY;
  131.     *ppfi = new CFtpIcon();
  132.     if (EVAL(*ppfi))
  133.     {
  134.         IUnknown_Set(&(*ppfi)->m_pflHfpl, pflHfpl);
  135.         if (pff && pff->IsRoot())
  136.         {
  137.             (*ppfi)->m_nRoot++;
  138.         }
  139.         hres = S_OK;
  140.     }
  141.     return hres;
  142. }
  143. /****************************************************
  144.     Constructor
  145. ****************************************************/
  146. CFtpIcon::CFtpIcon() : m_cRef(1)
  147. {
  148.     DllAddRef();
  149.     // This needs to be allocated in Zero Inited Memory.
  150.     // Assert that all Member Variables are inited to Zero.
  151.     ASSERT(!m_pflHfpl);
  152.     ASSERT(!m_nRoot);
  153.     INIT_SINGLE_THREADED_ASSERT;
  154.     LEAK_ADDREF(LEAK_CFtpIcon);
  155. }
  156. /****************************************************
  157.     Destructor
  158. ****************************************************/
  159. CFtpIcon::~CFtpIcon()
  160. {
  161.     ATOMICRELEASE(m_pflHfpl);
  162.     DllRelease();
  163.     LEAK_DELREF(LEAK_CFtpIcon);
  164. }
  165. //===========================
  166. // *** IUnknown Interface ***
  167. //===========================
  168. ULONG CFtpIcon::AddRef()
  169. {
  170.     m_cRef++;
  171.     return m_cRef;
  172. }
  173. ULONG CFtpIcon::Release()
  174. {
  175.     ASSERT(m_cRef > 0);
  176.     m_cRef--;
  177.     if (m_cRef > 0)
  178.         return m_cRef;
  179.     delete this;
  180.     return 0;
  181. }
  182. HRESULT CFtpIcon::QueryInterface(REFIID riid, void **ppvObj)
  183. {
  184.     static const QITAB qit[] = {
  185.         QITABENT(CFtpIcon, IExtractIconW),
  186.         QITABENT(CFtpIcon, IExtractIconA),
  187.         QITABENT(CFtpIcon, IQueryInfo),
  188.         { 0 },
  189.     };
  190.     
  191.     return QISearch(this, qit, riid, ppvObj);
  192. }