Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

266 lines
7.2 KiB

  1. #include "folder.h"
  2. #include "item.h"
  3. #include "utils.h"
  4. #include <mluisupp.h>
  5. ///////////////////////////////////////////////////////////////////////////////
  6. // View functions
  7. const struct {
  8. short int iCol;
  9. short int ids;
  10. short int cchCol;
  11. short int iFmt;
  12. } s_ControlFolder_cols[] = {
  13. {SI_CONTROL, IDS_COL_CONTROL, 20, LVCFMT_LEFT},
  14. {SI_STATUS, IDS_COL_STATUS, 20, LVCFMT_LEFT},
  15. {SI_TOTALSIZE, IDS_COL_TOTALSIZE, 18, LVCFMT_LEFT},
  16. {SI_CREATION, IDS_COL_CREATION, 18, LVCFMT_LEFT},
  17. {SI_LASTACCESS, IDS_COL_LASTACCESS, 18, LVCFMT_LEFT},
  18. {SI_VERSION, IDS_COL_VERSION, 18, LVCFMT_LEFT}
  19. };
  20. HRESULT ControlFolderView_Command(HWND hwnd, UINT uID)
  21. {
  22. switch (uID)
  23. {
  24. case IDM_SORTBYNAME:
  25. case IDM_SORTBYSTATUS:
  26. case IDM_SORTBYTOTALSIZE:
  27. case IDM_SORTBYCREATION:
  28. case IDM_SORTBYLASTACCESS:
  29. case IDM_SORTBYVERSION:
  30. ShellFolderView_ReArrange(hwnd, uID - IDM_SORTBYNAME);
  31. break;
  32. default:
  33. return E_FAIL;
  34. }
  35. return NOERROR;
  36. }
  37. HMENU GetMenuFromID(HMENU hmenu, UINT idm)
  38. {
  39. MENUITEMINFO mii = {sizeof(mii), MIIM_SUBMENU, 0, 0, 0, NULL, NULL, NULL, 0, NULL, 0};
  40. GetMenuItemInfo(hmenu, idm, FALSE, &mii);
  41. return mii.hSubMenu;
  42. }
  43. UINT MergeMenuHierarchy(
  44. HMENU hmenuDst,
  45. HMENU hmenuSrc,
  46. UINT idcMin,
  47. UINT idcMax)
  48. {
  49. UINT idcMaxUsed = idcMin;
  50. int imi = GetMenuItemCount(hmenuSrc);
  51. while (--imi >= 0)
  52. {
  53. MENUITEMINFO mii = {sizeof(mii), MIIM_ID | MIIM_SUBMENU, 0, 0, 0, NULL, NULL, NULL, 0, NULL, 0};
  54. if (GetMenuItemInfo(hmenuSrc, imi, TRUE, &mii))
  55. {
  56. UINT idcT = Shell_MergeMenus(
  57. GetMenuFromID(hmenuDst, mii.wID),
  58. mii.hSubMenu,
  59. 0, idcMin, idcMax,
  60. MM_ADDSEPARATOR|MM_SUBMENUSHAVEIDS);
  61. idcMaxUsed = max(idcMaxUsed, idcT);
  62. }
  63. }
  64. return idcMaxUsed;
  65. }
  66. HRESULT ControlFolderView_MergeMenu(LPQCMINFO pqcm)
  67. {
  68. HMENU hmenu = LoadMenu(MLGetHinst(), MAKEINTRESOURCE(IDR_CONTROLFOLDER));
  69. Assert(hmenu != NULL);
  70. if (hmenu)
  71. {
  72. MENUITEMINFO mii;
  73. mii.cbSize = sizeof(mii);
  74. mii.fMask = MIIM_ID;
  75. mii.wID = SFVIDM_MENU_ARRANGE;
  76. SetMenuItemInfo(hmenu, 0, TRUE, &mii);
  77. MergeMenuHierarchy(pqcm->hmenu, hmenu, pqcm->idCmdFirst, pqcm->idCmdLast);
  78. DestroyMenu(hmenu);
  79. }
  80. return NOERROR;
  81. }
  82. HRESULT ControlFolderView_InitMenuPopup(
  83. HWND hwnd,
  84. UINT idCmdFirst,
  85. int nIndex,
  86. HMENU hmenu)
  87. {
  88. return NOERROR;
  89. }
  90. HRESULT ControlFolderView_OnGetDetailsOf(
  91. HWND hwnd,
  92. UINT iColumn,
  93. PDETAILSINFO pdi)
  94. {
  95. BOOL bResult = TRUE;
  96. LPCONTROLPIDL pcpidl = (LPCONTROLPIDL)pdi->pidl;
  97. if (iColumn >= NUM_COLUMNS)
  98. return E_NOTIMPL;
  99. pdi->str.uType = STRRET_CSTR;
  100. pdi->str.cStr[0] = '\0';
  101. // if NULL, asking for column info
  102. if (pcpidl == NULL)
  103. {
  104. MLLoadString(
  105. s_ControlFolder_cols[iColumn].ids,
  106. pdi->str.cStr,
  107. ARRAYSIZE(pdi->str.cStr));
  108. pdi->fmt = s_ControlFolder_cols[iColumn].iFmt;
  109. pdi->cxChar = s_ControlFolder_cols[iColumn].cchCol;
  110. return NOERROR;
  111. }
  112. switch (iColumn)
  113. {
  114. case SI_CONTROL:
  115. lstrcpy(pdi->str.cStr, GetStringInfo(pcpidl, SI_CONTROL));
  116. break;
  117. case SI_VERSION:
  118. lstrcpy(pdi->str.cStr, GetStringInfo(pcpidl, SI_VERSION));
  119. break;
  120. case SI_CREATION:
  121. lstrcpy(pdi->str.cStr, GetStringInfo(pcpidl, SI_CREATION));
  122. break;
  123. case SI_LASTACCESS:
  124. lstrcpy(pdi->str.cStr, GetStringInfo(pcpidl, SI_LASTACCESS));
  125. break;
  126. case SI_TOTALSIZE:
  127. GetSizeSaved(pcpidl, pdi->str.cStr);
  128. break;
  129. case SI_STATUS:
  130. GetStatus(pcpidl, pdi->str.cStr, sizeof(pdi->str.cStr));
  131. break;
  132. default:
  133. bResult = FALSE;
  134. }
  135. return (bResult ? NOERROR : E_FAIL);
  136. }
  137. HRESULT ControlFolderView_OnColumnClick(HWND hwnd, UINT iColumn)
  138. {
  139. ShellFolderView_ReArrange(hwnd, iColumn);
  140. return NOERROR;
  141. }
  142. HRESULT ControlFolderView_DidDragDrop(HWND hwnd, IDataObject *pdo, DWORD dwEffect)
  143. {
  144. HRESULT hr = E_FAIL;
  145. if (dwEffect & DROPEFFECT_MOVE)
  146. {
  147. CControlItem *pCItem;
  148. if (SUCCEEDED(pdo->QueryInterface(CLSID_ControlFolder, (void **)&pCItem)))
  149. {
  150. hr = pCItem->Remove(hwnd);
  151. pCItem->Release();
  152. }
  153. }
  154. return hr;
  155. }
  156. HRESULT CALLBACK ControlFolderView_ViewCallback(
  157. IShellView *psvOuter,
  158. IShellFolder *psf,
  159. HWND hwnd,
  160. UINT uMsg,
  161. WPARAM wParam,
  162. LPARAM lParam)
  163. {
  164. HRESULT hres = NOERROR;
  165. switch (uMsg)
  166. {
  167. case DVM_GETHELPTEXT:
  168. {
  169. UINT id = LOWORD(wParam);
  170. UINT cchBuf = HIWORD(wParam);
  171. LPTSTR pszBuf = (LPTSTR)lParam;
  172. MLLoadString(id + IDS_HELP_SORTBYNAME ,pszBuf, cchBuf);
  173. }
  174. break;
  175. case DVM_DIDDRAGDROP:
  176. hres = ControlFolderView_DidDragDrop(
  177. hwnd,
  178. (IDataObject*)lParam,
  179. (DWORD)wParam);
  180. break;
  181. case DVM_INITMENUPOPUP:
  182. hres = ControlFolderView_InitMenuPopup(
  183. hwnd,
  184. LOWORD(wParam),
  185. HIWORD(wParam),
  186. (HMENU)lParam);
  187. break;
  188. case DVM_INVOKECOMMAND:
  189. ControlFolderView_Command(hwnd, (UINT)wParam);
  190. break;
  191. case DVM_COLUMNCLICK:
  192. hres = ControlFolderView_OnColumnClick(hwnd, (UINT)wParam);
  193. break;
  194. case DVM_GETDETAILSOF:
  195. hres = ControlFolderView_OnGetDetailsOf(hwnd, (UINT)wParam, (PDETAILSINFO)lParam);
  196. break;
  197. case DVM_MERGEMENU:
  198. hres = ControlFolderView_MergeMenu((LPQCMINFO)lParam);
  199. break;
  200. case DVM_DEFVIEWMODE:
  201. *(FOLDERVIEWMODE *)lParam = FVM_DETAILS;
  202. break;
  203. default:
  204. hres = E_FAIL;
  205. }
  206. return hres;
  207. }
  208. HRESULT ControlFolderView_CreateInstance(
  209. CControlFolder *pCFolder,
  210. LPCITEMIDLIST pidl,
  211. void **ppvOut)
  212. {
  213. CSFV csfv;
  214. csfv.cbSize = sizeof(csfv);
  215. csfv.pshf = (IShellFolder*)pCFolder;
  216. csfv.psvOuter = NULL;
  217. csfv.pidl = pidl;
  218. csfv.lEvents = SHCNE_DELETE | SHCNE_UPDATEITEM; // SHCNE_DISKEVENTS | SHCNE_ASSOCCHANGED | SHCNE_GLOBALEVENTS;
  219. csfv.pfnCallback = ControlFolderView_ViewCallback;
  220. csfv.fvm = (FOLDERVIEWMODE)0; // Have defview restore the folder view mode
  221. return SHCreateShellFolderViewEx(&csfv, (IShellView**)ppvOut); // &this->psv);
  222. }