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.

244 lines
6.6 KiB

  1. //-------------------------------------------------------------------------
  2. // File Manager Extensions support routines
  3. //
  4. //
  5. // radical
  6. //
  7. //-------------------------------------------------------------------------
  8. #include "winfile.h"
  9. #include "winnet.h"
  10. LONG
  11. GetExtSelection(
  12. HWND hWnd,
  13. WORD wItem,
  14. LPFMS_GETFILESEL lpSel,
  15. BOOL bSearch,
  16. BOOL bGetCount,
  17. BOOL bLFNAware
  18. )
  19. {
  20. HANDLE hDTA;
  21. LPMYDTA lpmydta;
  22. LPDTASEARCH lpdtasch, lpdtaschT;
  23. INT count, sel_ind, i;
  24. HWND hwndLB;
  25. CHAR szPath[MAXPATHLEN];
  26. FMS_GETFILESEL file;
  27. if (bGetCount)
  28. lpSel = &file;
  29. if (bSearch) {
  30. hDTA = (HANDLE)GetWindowLongPtr(hWnd, GWLP_HDTASEARCH);
  31. lpdtasch = (LPDTASEARCH)LocalLock(hDTA);
  32. hwndLB = GetDlgItem(hWnd, IDCW_LISTBOX);
  33. } else {
  34. hDTA = (HANDLE)GetWindowLongPtr(HasDirWindow(hWnd), GWLP_HDTA);
  35. hwndLB = GetDlgItem(HasDirWindow(hWnd), IDCW_LISTBOX);
  36. LocalLock(hDTA);
  37. }
  38. count = (WORD)SendMessage(hwndLB, LB_GETCOUNT, 0, 0L);
  39. sel_ind = 0; // index of current selected item
  40. for (i = 0; i < count; i++) {
  41. if ((BOOL)SendMessage(hwndLB, LB_GETSEL, i, 0L)) {
  42. if (bSearch) {
  43. lpdtaschT = &(lpdtasch[(INT)SendMessage(hwndLB, LB_GETITEMDATA, i, 0L)]);
  44. SendMessage(hwndLB, LB_GETTEXT, i, (LPARAM)szPath);
  45. lpSel->bAttr = (BYTE)lpdtaschT->sch_dwAttrs;
  46. lpSel->ftTime = lpdtaschT->sch_ftLastWriteTime;
  47. lpSel->dwSize = lpdtaschT->sch_nFileSizeLow;
  48. } else {
  49. SendMessage(hwndLB, LB_GETTEXT, i, (LPARAM)&lpmydta);
  50. if (lpmydta->my_dwAttrs & ATTR_PARENT)
  51. continue;
  52. SendMessage(hWnd, FS_GETDIRECTORY, sizeof(szPath), (LPARAM)szPath);
  53. lstrcat(szPath, lpmydta->my_cFileName);
  54. lpSel->bAttr = (BYTE)lpmydta->my_dwAttrs;
  55. lpSel->ftTime = lpmydta->my_ftLastWriteTime;
  56. lpSel->dwSize = lpmydta->my_nFileSizeLow;
  57. }
  58. // skip LFN stuff for non LFN aware dudes!
  59. if (!bLFNAware && (lpSel->bAttr & ATTR_LFN))
  60. continue;
  61. FixAnsiPathForDos(szPath);
  62. lstrcpy(lpSel->szName, szPath);
  63. if (!bGetCount) {
  64. if (wItem == (WORD)sel_ind)
  65. goto BailOutDude;
  66. }
  67. sel_ind++;
  68. }
  69. }
  70. BailOutDude:
  71. LocalUnlock(hDTA);
  72. return (LONG)sel_ind;
  73. }
  74. LONG
  75. GetDriveInfo(
  76. HWND hwnd,
  77. LPFMS_GETDRIVEINFO lpSel
  78. )
  79. {
  80. CHAR szPath[MAXPATHLEN];
  81. CHAR szVol[14];
  82. // this has to work for hwnd a tree or search window
  83. SendMessage(hwnd, FS_GETDIRECTORY, sizeof(szPath), (LPARAM)szPath);
  84. StripBackslash(szPath);
  85. FixAnsiPathForDos(szPath);
  86. lstrcpy(lpSel->szPath, szPath);
  87. lpSel->dwTotalSpace = lTotalSpace;
  88. lpSel->dwFreeSpace = lFreeSpace;
  89. GetVolumeLabel((szPath[0] & ~0x20) - 'A', szVol, FALSE);
  90. lstrcpy(lpSel->szVolume, szVol);
  91. szPath[2] = 0;
  92. if (WFGetConnection(szPath, lpSel->szShare, FALSE) != WN_SUCCESS)
  93. lpSel->szShare[0] = 0;
  94. return 1L;
  95. }
  96. VOID
  97. APIENTRY
  98. FreeExtensions()
  99. {
  100. INT i;
  101. HMENU hMenuFrame;
  102. INT iMax;
  103. HWND hwndActive;
  104. hMenuFrame = GetMenu(hwndFrame);
  105. hwndActive = (HWND)SendMessage(hwndMDIClient, WM_MDIGETACTIVE, 0, 0L);
  106. if (hwndActive && GetWindowLong(hwndActive, GWL_STYLE) & WS_MAXIMIZE)
  107. iMax = 1;
  108. else
  109. iMax = 0;
  110. for (i = 0; i < iNumExtensions; i++) {
  111. (extensions[i].ExtProc)(NULL, FMEVENT_UNLOAD, 0L);
  112. DeleteMenu(hMenuFrame, IDM_EXTENSIONS + iMax, MF_BYPOSITION);
  113. FreeLibrary((HANDLE)extensions[i].hModule);
  114. }
  115. iNumExtensions = 0;
  116. }
  117. INT_PTR
  118. APIENTRY
  119. ExtensionMsgProc(
  120. UINT wMsg,
  121. WPARAM wParam,
  122. LPARAM lParam
  123. )
  124. {
  125. HWND hwndActive;
  126. HWND hwndTree, hwndDir, hwndDrives, hwndFocus;
  127. hwndActive = (HWND)SendMessage(hwndMDIClient, WM_MDIGETACTIVE, 0, 0L);
  128. GetTreeWindows(hwndActive, &hwndTree, &hwndDir, &hwndDrives);
  129. switch (wMsg) {
  130. case FM_RELOAD_EXTENSIONS:
  131. SendMessage(hwndFrame, WM_CANCELMODE, 0, 0L);
  132. FreeExtensions();
  133. InitExtensions();
  134. DrawMenuBar(hwndFrame);
  135. break;
  136. case FM_GETFOCUS:
  137. // wParam unused
  138. // lParam unused
  139. // return window tyep with focus
  140. if (hwndActive == hwndSearch)
  141. return FMFOCUS_SEARCH;
  142. hwndFocus = GetTreeFocus(hwndActive);
  143. if (hwndFocus == hwndTree)
  144. return FMFOCUS_TREE;
  145. else if (hwndFocus == hwndDir)
  146. return FMFOCUS_DIR;
  147. else if (hwndFocus == hwndDrives)
  148. return FMFOCUS_DRIVES;
  149. break;
  150. case FM_GETDRIVEINFO:
  151. // wParam unused
  152. // lParam LPFMS_GETDRIVEINFO structure to be filled in
  153. return GetDriveInfo(hwndActive, (LPFMS_GETDRIVEINFO)lParam);
  154. break;
  155. case FM_REFRESH_WINDOWS:
  156. // wParam 0 refresh the current window
  157. // non zero refresh all windows
  158. // lParam unused
  159. if (wParam == 0)
  160. RefreshWindow(hwndActive);
  161. else {
  162. HWND hwndT, hwndNext;
  163. hwndT = GetWindow(hwndMDIClient, GW_CHILD);
  164. while (hwndT) {
  165. hwndNext = GetWindow(hwndT, GW_HWNDNEXT);
  166. if (!GetWindow(hwndT, GW_OWNER))
  167. RefreshWindow(hwndT);
  168. hwndT = hwndNext;
  169. }
  170. }
  171. lFreeSpace = -1L;
  172. UpdateStatus(hwndActive);
  173. break;
  174. case FM_GETSELCOUNT:
  175. case FM_GETSELCOUNTLFN:
  176. // wParam unused
  177. // lParam unused
  178. // return # of selected items
  179. case FM_GETFILESEL:
  180. case FM_GETFILESELLFN:
  181. // wParam index of selected item to get
  182. // lParam LPFMS_GETFILESEL structure to be filled in
  183. if (hwndActive != hwndSearch && !hwndDir)
  184. return 0L;
  185. // note, this uses the fact that LFN messages are odd!
  186. return GetExtSelection(hwndActive, (WORD)wParam, (LPFMS_GETFILESEL)lParam,
  187. hwndActive == hwndSearch, (wMsg & ~1) == FM_GETSELCOUNT,
  188. (BOOL)(wMsg & 1));
  189. }
  190. return 0;
  191. }