isbcache.c
Upload User: xhy777
Upload Date: 2007-02-14
Package Size: 24088k
Code Size: 3k
Category:

Windows Kernel

Development Platform:

Visual C++

  1. #include "shellprv.h"
  2. /*
  3.   this caches a mapping between hwnd's and ishell browsers
  4.   this facilitates finding the ishellbrowser and telling it to 
  5.   browse to something.. that browser may or may not decide to
  6.   then create a new window, but if it does, it can then pass along
  7.   history information.
  8.   
  9.   
  10.   currently this is kept per instance.  at this point, it would help us
  11.   to make the cache global because we don't marshal the 
  12.   IShellBrowser::BrowseToObject calls anyways...  when this changes, we 
  13.   should also make the cache system global.
  14.  */
  15. HDSA g_hdsaSB = NULL;
  16. typedef struct tabSBCacheItem {
  17.     HWND hwnd;
  18.     LPSHELLBROWSER psb;
  19. } SBCACHEITEM, *PSBCACHEITEM;
  20. enum {
  21.     SBCF_ADD,
  22.     SBCF_REMOVE,
  23.     SBCF_FIND,
  24. } ;
  25. int SBFind(HWND hwnd , LPSHELLBROWSER *ppsb)
  26. {
  27.     int i = -1;
  28.     PSBCACHEITEM pci;
  29.     LPSHELLBROWSER psb = NULL;
  30.     
  31.     if (g_hdsaSB) {
  32.         ENTERCRITICAL;
  33.         
  34.         // walk the dsa looking for the hwnd
  35.         for (i = DSA_GetItemCount(g_hdsaSB) - 1; i >= 0; i--) {
  36.             pci = DSA_GetItemPtr(g_hdsaSB, i);
  37.             if (pci->hwnd == hwnd) {
  38.                 psb = pci->psb;
  39.                 break;
  40.             }
  41.         }
  42.         LEAVECRITICAL;
  43.     }
  44.     
  45.     if (ppsb) 
  46.         *ppsb = psb;
  47.     
  48.     return i;
  49. }
  50. LPSHELLBROWSER SHSBCache(UINT uOperation, HWND hwnd, LPSHELLBROWSER psb)
  51. {
  52.     PSBCACHEITEM pci;
  53.     int i;
  54.     switch (uOperation)
  55.     {
  56.     case SBCF_ADD:
  57.         ENTERCRITICAL;
  58.         if (!g_hdsaSB) {
  59.             g_hdsaSB = DSA_Create(SIZEOF(SBCACHEITEM), 1);
  60.         }
  61.         LEAVECRITICAL;
  62.         
  63.         if (!g_hdsaSB)
  64.             return NULL;
  65.         
  66.         ENTERCRITICAL;
  67.         i = SBFind(hwnd, NULL);
  68.         if (i == -1) {
  69.             SBCACHEITEM ci;
  70.             ci.hwnd = hwnd;
  71.             ci.psb = psb;
  72.             i = DSA_AppendItem(g_hdsaSB, &ci);
  73.             if (i == -1) {
  74.                 // failed to add.
  75.                 psb = NULL;
  76.             }
  77.         } else {
  78.             // was already in there.. make sure things are correct
  79.             pci = DSA_GetItemPtr(g_hdsaSB, i);
  80.             ASSERT(pci->hwnd == hwnd);
  81.             ASSERT(pci->psb == psb);
  82.             pci->psb = psb;
  83.         }
  84.         LEAVECRITICAL;
  85.         break;
  86.         
  87.     case SBCF_REMOVE:
  88.         ENTERCRITICAL;
  89.         i = SBFind(hwnd, &psb);
  90.         if (i != -1) {
  91.             DSA_DeleteItem(g_hdsaSB, i);
  92.         }
  93.         LEAVECRITICAL;
  94.         break;
  95.         
  96.     case SBCF_FIND:
  97.         i = SBFind(hwnd, &psb);
  98.         break;
  99.     }
  100.     
  101.     return psb;
  102. }