Leaked source code of windows server 2003
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.

2723 lines
83 KiB

  1. /****************************************************************************/
  2. /* */
  3. /* WFDIR.C - */
  4. /* */
  5. /* Windows File System Directory Window Proc Routines */
  6. /* */
  7. /****************************************************************************/
  8. #include "winfile.h"
  9. #include "winnet.h"
  10. #include "lfn.h"
  11. #include "wfcopy.h"
  12. #define MAXDIGITSINSIZE 8
  13. #define DATEMASK 0x001F
  14. #define MONTHMASK 0x01E0
  15. #define MINUTEMASK 0x07E0
  16. #define SECONDSMASK 0x001F
  17. #define DATESEPERATOR '-'
  18. #define TIMESEPERATOR ':'
  19. CHAR szAttr[] = "RHSA";
  20. INT iLastSel = -1;
  21. INT_PTR APIENTRY DirWndProc(register HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam);
  22. LPSTR DirGetSelection(HWND hwndDir, HWND hwndLB, INT iSelType, BOOL *pfDir);
  23. VOID DirGetAnchorFocus(register HWND hwndLB, HANDLE hDTA, LPSTR szAnchor, LPSTR szCaret, LPSTR szTopIndex);
  24. VOID FillDirList(HWND hWnd, HANDLE hDirEntries);
  25. VOID DrawItemFast(HWND hWnd, LPDRAWITEMSTRUCT lpLBItem, LPMYDTA lpmydta, BOOL bHasFocus);
  26. INT GetPict(CHAR ch, LPSTR szStr);
  27. INT DirFindIndex(HWND hwndLB, HANDLE hDTA, LPSTR szFile);
  28. INT CompareDTA(register LPMYDTA item1, LPMYDTA item2, WORD wSort);
  29. VOID CreateLBLine(register WORD wLineFormat, LPMYDTA lpmydta, LPSTR szBuffer);
  30. HANDLE CreateDTABlock(HWND hWnd, LPSTR pPath, DWORD dwAttribs, BOOL bAllowAbort, BOOL bDontSteal);
  31. BOOL SetSelection(HWND hwndLB, HANDLE hDTA, LPSTR pSel);
  32. INT CreateDate(WORD *wValArray, LPSTR szOutStr);
  33. INT CreateTime(WORD * wValArray, LPSTR szOutStr);
  34. VOID GetDirStatus(HWND hWnd, LPSTR szMsg1, LPSTR szMsg2);
  35. INT GetMaxExtent(HWND hwndLB, HANDLE hDTA);
  36. BOOL CheckEarlyAbort(VOID);
  37. BOOL SetDirFocus(HWND hwndDir);
  38. VOID APIENTRY CheckEscapes(LPSTR);
  39. VOID SortDirList(HWND, LPMYDTA, WORD ,LPMYDTA *);
  40. /*--------------------------------------------------------------------------*/
  41. /* */
  42. /* DrawItemFast() - */
  43. /* */
  44. /*--------------------------------------------------------------------------*/
  45. VOID
  46. DrawItemFast(
  47. HWND hWnd,
  48. LPDRAWITEMSTRUCT lpLBItem,
  49. LPMYDTA lpmydta,
  50. BOOL bHasFocus
  51. )
  52. {
  53. INT x, y, i;
  54. HDC hDC;
  55. BOOL bDrawSelected;
  56. HWND hwndLB;
  57. RECT rc;
  58. DWORD rgbText, rgbBackground;
  59. CHAR szBuf[MAXFILENAMELEN+2];
  60. hWnd;
  61. ENTER("DrawItemFast");
  62. hDC = lpLBItem->hDC;
  63. hwndLB = lpLBItem->hwndItem;
  64. bDrawSelected = (lpLBItem->itemState & ODS_SELECTED);
  65. if (bHasFocus && bDrawSelected) {
  66. rgbText = SetTextColor(hDC, GetSysColor(COLOR_HIGHLIGHTTEXT));
  67. rgbBackground = SetBkColor(hDC, GetSysColor(COLOR_HIGHLIGHT));
  68. }
  69. if (lpLBItem->itemAction == ODA_FOCUS)
  70. goto FocusOnly;
  71. /* Draw the black/white background. */
  72. x = lpLBItem->rcItem.left + 1;
  73. y = lpLBItem->rcItem.top + (dyFileName/2);
  74. lstrcpy(szBuf, lpmydta->my_cFileName);
  75. if ((wTextAttribs & TA_LOWERCASE) && !(lpmydta->my_dwAttrs & ATTR_LFN))
  76. AnsiLower(szBuf);
  77. ExtTextOut(hDC, x + dxFolder + dyBorderx2 + dyBorder, y-(dyText/2),
  78. ETO_OPAQUE, &lpLBItem->rcItem, szBuf, lstrlen(szBuf), NULL);
  79. if (fShowSourceBitmaps || (hwndDragging != hwndLB) || !bDrawSelected) {
  80. LONG ySrc;
  81. i = lpmydta->iBitmap;
  82. if (i & 0x40) {
  83. // It's an object type bitmap
  84. ySrc = (dyFolder * 2) + dyDriveBitmap;
  85. i = i & (~0x40);
  86. while (i >= 16) {
  87. i -= 16;
  88. ySrc += (dyFolder * 2);
  89. }
  90. } else {
  91. ySrc = 0;
  92. }
  93. ySrc += (bHasFocus && bDrawSelected) ? dyFolder : 0;
  94. BitBlt(hDC, x + dyBorderx2, y-(dyFolder/2), dxFolder, dyFolder, hdcMem,
  95. i * dxFolder, ySrc, SRCCOPY);
  96. }
  97. if (lpLBItem->itemState & ODS_FOCUS)
  98. FocusOnly:
  99. DrawFocusRect(hDC, &lpLBItem->rcItem); // toggles focus (XOR)
  100. /* Restore the normal drawing colors. */
  101. if (bDrawSelected) {
  102. if (bHasFocus) {
  103. SetTextColor(hDC, rgbText);
  104. SetBkColor(hDC, rgbBackground);
  105. } else {
  106. HBRUSH hbr;
  107. if (hbr = CreateSolidBrush(GetSysColor(COLOR_HIGHLIGHT))) {
  108. rc = lpLBItem->rcItem;
  109. rc.left += dyBorder;
  110. rc.right -= dyBorder;
  111. if (lpLBItem->itemID > 0 &&
  112. (BOOL)SendMessage(hwndLB, LB_GETSEL, lpLBItem->itemID - 1, 0L))
  113. rc.top -= dyBorder;
  114. FrameRect(hDC, &rc, hbr);
  115. DeleteObject(hbr);
  116. }
  117. }
  118. }
  119. LEAVE("DrawItemFast");
  120. }
  121. /*--------------------------------------------------------------------------*/
  122. /* */
  123. /* FillDirList() - */
  124. /* */
  125. /* HANDLE hDirEntries; Array of directory entries */
  126. /*--------------------------------------------------------------------------*/
  127. VOID
  128. FillDirList(
  129. HWND hWnd,
  130. HANDLE hDTA
  131. )
  132. {
  133. register WORD count;
  134. LPMYDTA lpmydta;
  135. LPMYDTA *alpmydtaSorted;
  136. WORD i;
  137. lpmydta = (LPMYDTA)LocalLock(hDTA);
  138. count = (WORD)lpmydta->my_nFileSizeLow;
  139. if (count == 0) {
  140. SendMessage(hWnd, LB_ADDSTRING, 0, 0L); // tolken for no items
  141. } else {
  142. alpmydtaSorted = (LPMYDTA *)LocalAlloc(LMEM_FIXED,
  143. sizeof(LPMYDTA) * count);
  144. if (alpmydtaSorted != NULL) {
  145. SortDirList(hWnd, lpmydta, count, alpmydtaSorted);
  146. for (i = 0; i < count; i++) {
  147. alpmydtaSorted[i]->nIndex = i;
  148. SendMessage(hWnd, LB_INSERTSTRING,(WPARAM)-1, (LPARAM)alpmydtaSorted[i]);
  149. }
  150. LocalFree((HANDLE)alpmydtaSorted);
  151. }
  152. }
  153. LocalUnlock(hDTA);
  154. }
  155. BOOL
  156. CheckEarlyAbort()
  157. {
  158. MSG msg;
  159. if (PeekMessage(&msg, NULL, WM_KEYDOWN, WM_KEYDOWN, PM_NOREMOVE | PM_NOYIELD)) {
  160. if (msg.wParam == VK_UP ||
  161. msg.wParam == VK_DOWN) {
  162. return TRUE;
  163. }
  164. }
  165. return FALSE;
  166. }
  167. HANDLE
  168. CopyDTABlock(
  169. HANDLE hDTASrc
  170. )
  171. {
  172. LPMYDTA lpmydtaSrc, lpmydtaDst;
  173. HANDLE hDTADst;
  174. SIZE_T dwSize;
  175. lpmydtaSrc = (LPMYDTA)LocalLock(hDTASrc);
  176. dwSize = LocalSize(hDTASrc);
  177. if (hDTADst = LocalAlloc(LPTR, dwSize)) {
  178. lpmydtaDst = (LPMYDTA)LocalLock(hDTADst);
  179. memcpy(lpmydtaDst, lpmydtaSrc, (size_t)dwSize);
  180. LocalUnlock(hDTASrc);
  181. LocalUnlock(hDTADst);
  182. return hDTADst;
  183. } else {
  184. LocalUnlock(hDTASrc);
  185. return NULL;
  186. }
  187. }
  188. HANDLE
  189. StealDTABlock(
  190. HWND hWnd,
  191. LPSTR pPath,
  192. DWORD dwAttribs
  193. )
  194. {
  195. HWND hwnd;
  196. HWND hwndDir;
  197. HANDLE hDTA;
  198. CHAR szPath[MAXPATHLEN];
  199. ENTER("StealDTABlock");
  200. for (hwnd = GetWindow(hwndMDIClient, GW_CHILD); hwnd;
  201. hwnd = GetWindow(hwnd, GW_HWNDNEXT)) {
  202. if ((hwndDir = HasDirWindow(hwnd)) && (hwndDir != hWnd)) {
  203. GetMDIWindowText(hwnd, szPath, sizeof(szPath));
  204. if ((dwAttribs == (DWORD)GetWindowLong(hwnd, GWL_ATTRIBS)) &&
  205. !lstrcmpi(pPath, szPath) &&
  206. (hDTA = (HANDLE)GetWindowLongPtr(hwndDir, GWLP_HDTA))) {
  207. LEAVE("StealDTABlock");
  208. return CopyDTABlock(hDTA);
  209. }
  210. }
  211. }
  212. LEAVE("StealDTABlock");
  213. return NULL;
  214. }
  215. /*--------------------------------------------------------------------------*/
  216. /* */
  217. /* CreateDTABlock() - */
  218. /* */
  219. /*--------------------------------------------------------------------------*/
  220. /* Builds a global memory block full of DTAs for the path 'pPath'. */
  221. /* Returns:
  222. * An unlocked global memory handle to DTA block with first DTA
  223. * my_nFileSizeLow field indicating the number of DTA blocks that follow
  224. *
  225. * This builds a global memory block that has DTA entries for all
  226. * of the files with dwAttributes in pPath. The first DTA entry's
  227. * my_nFileSizeLow field indicates the number of actual DTA areas found
  228. */
  229. HANDLE
  230. CreateDTABlock(
  231. HWND hWnd,
  232. LPSTR pPath,
  233. DWORD dwAttribs,
  234. BOOL bAllowAbort,
  235. BOOL bDontSteal
  236. )
  237. {
  238. register LPSTR pName;
  239. WORD wPathLen;
  240. BOOL bDoc, bProgram;
  241. DWORD dwCurrentSize, dwBlockSize;
  242. WORD wSize, wLastSize;
  243. LFNDTA lfndta;
  244. HANDLE hMem;
  245. LPMYDTA lpmydta, lpStart;
  246. CHAR szPathOEM[MAXPATHLEN];
  247. DWORD iBitmap;
  248. WORD wDrive;
  249. ENTER("CreateDTABlock");
  250. PRINT(BF_PARMTRACE, "IN: pPath=%s", pPath);
  251. PRINT(BF_PARMTRACE, "IN: dwAttribs=0x%lx", UlongToPtr(dwAttribs));
  252. PRINT(BF_PARMTRACE, "IN: bDontSteal=%d", IntToPtr(bDontSteal));
  253. #define BLOCK_SIZE_GRANULARITY 512 // must be larger than MYDTA
  254. // get the drive index assuming path is
  255. // fully qualified...
  256. wDrive = (WORD)((*pPath - 'A') & 31);
  257. if (bAllowAbort && CheckEarlyAbort()) {
  258. PRINT(BF_PARMTRACE, "OUT: hDTA=-1", 0);
  259. LEAVE("CreateDTABlock");
  260. return (HANDLE)-1;
  261. }
  262. if (!bDontSteal && (hMem = StealDTABlock(hWnd, pPath, dwAttribs))) {
  263. PRINT(BF_PARMTRACE, "OUT: hDTA=0x%lx", hMem);
  264. LEAVE("CreateDTABlock");
  265. return hMem;
  266. }
  267. dwBlockSize = BLOCK_SIZE_GRANULARITY;
  268. hMem = LocalAlloc(LPTR, (DWORD)dwBlockSize);
  269. if (!hMem) {
  270. PRINT(BF_PARMTRACE, "OUT: hDTA=NULL", 0);
  271. LEAVE("CreateDTABlock");
  272. return NULL;
  273. }
  274. lpmydta = lpStart = (LPMYDTA)LocalLock(hMem);
  275. lpStart->my_nFileSizeLow = 0;
  276. wLastSize = sizeof(MYDTA);
  277. wLastSize = (WORD)DwordAlign(wLastSize);
  278. lpStart->wSize = wLastSize;
  279. dwCurrentSize = (DWORD)wLastSize;
  280. lstrcpy(szPathOEM, pPath);
  281. FixAnsiPathForDos(szPathOEM);
  282. wPathLen = (WORD)(lstrlen(szPathOEM)-3); /* Ignore '*.*' */
  283. if (!WFFindFirst(&lfndta, szPathOEM, (dwAttribs | ATTR_DIR) & ATTR_ALL)) {
  284. // Try again if the disk is available
  285. if (!IsTheDiskReallyThere(hWnd, pPath, FUNC_EXPAND) ||
  286. !WFFindFirst(&lfndta, szPathOEM, (dwAttribs | ATTR_DIR) & ATTR_ALL))
  287. goto CDBDone;
  288. }
  289. while (TRUE) {
  290. pName = lfndta.fd.cFileName;
  291. OemToCharBuff(pName, pName, sizeof(lfndta.fd.cFileName)/sizeof(lfndta.fd.cFileName[0]));
  292. // be safe, zero unused DOS dta bits
  293. lfndta.fd.dwFileAttributes &= ATTR_USED;
  294. // filter unwanted stuff here based on current view settings
  295. if (!(lfndta.fd.dwFileAttributes & ATTR_DIR)) {
  296. bProgram = IsProgramFile(pName);
  297. bDoc = IsDocument(pName);
  298. }
  299. // figure out the bitmap type here
  300. if (lfndta.fd.dwFileAttributes & ATTR_DIR) {
  301. // ignore the "." directory
  302. if (pName[0] == '.' && pName[1] != '.')
  303. goto CDBCont;
  304. // parent ".." dir
  305. if (pName[0] == '.') {
  306. pName = szNULL;
  307. iBitmap = BM_IND_DIRUP;
  308. lfndta.fd.dwFileAttributes |= ATTR_PARENT; // mark this!
  309. } else {
  310. // We always include DIRs so that the .. is
  311. // included. Now we filter other dirs off.
  312. if (!(dwAttribs & ATTR_DIR))
  313. goto CDBCont;
  314. iBitmap = BM_IND_CLOSE;
  315. }
  316. } else if (lfndta.fd.dwFileAttributes & ATTR_TYPES) {
  317. iBitmap = ((lfndta.fd.dwFileAttributes & ATTR_TYPES) >> 16) | 0x40;
  318. } else {
  319. iBitmap = BM_IND_DOC;
  320. }
  321. //
  322. // calc the size of this portion
  323. //
  324. // pName is assumed to be ANSI re: OemToAnsi() call,
  325. // so lstrlen() should be size in bytes. We just need to add one
  326. // for the terminating NULL
  327. wSize = (WORD)(sizeof(MYDTA) + lstrlen(pName) + sizeof('\0'));
  328. wSize = (WORD)DwordAlign(wSize);
  329. if ((wSize + dwCurrentSize) > dwBlockSize) {
  330. DWORD dwDelta;
  331. // grow the block
  332. dwBlockSize += BLOCK_SIZE_GRANULARITY;
  333. LocalUnlock(hMem);
  334. dwDelta = (DWORD)((LPBYTE)lpmydta - (LPBYTE)lpStart);
  335. {
  336. void *pv = LocalReAlloc(hMem, dwBlockSize, LMEM_MOVEABLE);
  337. if (!pv)
  338. goto CDBMemoryErr;
  339. else
  340. hMem = pv;
  341. }
  342. lpStart = (LPMYDTA)LocalLock(hMem);
  343. lpmydta = (LPMYDTA)((LPBYTE)lpStart + dwDelta);
  344. }
  345. lpStart->my_nFileSizeLow++;
  346. dwCurrentSize += wSize;
  347. // now it is safe to advance the pointer
  348. lpmydta = GETDTAPTR(lpmydta, wLastSize);
  349. wLastSize = lpmydta->wSize = wSize;
  350. lpmydta->my_dwAttrs = lfndta.fd.dwFileAttributes;
  351. lpmydta->my_ftLastWriteTime = lfndta.fd.ftLastWriteTime;
  352. lpmydta->my_nFileSizeLow = lfndta.fd.nFileSizeLow;
  353. lpmydta->my_nFileSizeHigh = lfndta.fd.nFileSizeHigh;
  354. lpmydta->iBitmap = (SHORT)iBitmap;
  355. if (IsLFN(pName)) {
  356. lpmydta->my_dwAttrs |= ATTR_LFN;
  357. }
  358. lstrcpy(lpmydta->my_cFileName, pName);
  359. CDBCont:
  360. if (bAllowAbort && CheckEarlyAbort()) {
  361. LocalUnlock(hMem);
  362. LocalFree(hMem);
  363. WFFindClose(&lfndta);
  364. PRINT(BF_PARMTRACE, "OUT: hDTA=-1", 0);
  365. LEAVE("CreateDTABlock");
  366. return (HANDLE)-1;
  367. }
  368. if (!WFFindNext(&lfndta)) {
  369. break;
  370. }
  371. }
  372. CDBDone:
  373. LocalUnlock(hMem);
  374. WFFindClose(&lfndta);
  375. PRINT(BF_PARMTRACE, "OUT: hDTA=0x%lx", hMem);
  376. LEAVE("CreateDTABlock");
  377. return hMem;
  378. CDBMemoryErr:
  379. WFFindClose(&lfndta);
  380. MyMessageBox(hwndFrame, IDS_OOMTITLE, IDS_OOMREADINGDIRMSG, MB_OK | MB_ICONEXCLAMATION);
  381. PRINT(BF_PARMTRACE, "OUT: hDTA=0x%lx", hMem);
  382. LEAVE("CreateDTABlock");
  383. return hMem;
  384. }
  385. /*--------------------------------------------------------------------------*/
  386. /* */
  387. /* DirGetSelection() - */
  388. /* */
  389. /*--------------------------------------------------------------------------*/
  390. /* Takes a Listbox and returns a string containing the names of the selected
  391. * files seperated by spaces.
  392. *
  393. * bSingle == 1 return only the first file
  394. * bSingle == 2 test for LFN files in the selection, doesn't return string
  395. * bSingle == 3 return fully qualified names
  396. *
  397. * returns:
  398. * if (bSingle == 1)
  399. * TRUE/FALSE if LFN is in the selection
  400. * else
  401. * pointer to the list of names (ANSI strings)
  402. * (must be freed by caller!)
  403. * *pfDir -> bool indicating directories are
  404. * contained in the selection (or that LFN names are present)
  405. *
  406. * NOTE: The caller must free the returned pointer!
  407. */
  408. LPSTR
  409. DirGetSelection(
  410. HWND hwndDir,
  411. HWND hwndLB,
  412. INT iSelType,
  413. BOOL *pfDir
  414. )
  415. {
  416. LPSTR p, pT;
  417. WORD i;
  418. WORD cch;
  419. WORD iMac;
  420. LPMYDTA lpmydta;
  421. CHAR szFile[MAXPATHLEN];
  422. CHAR szPath[MAXPATHLEN];
  423. BOOL bDir, bPropertyDialog;
  424. LPINT lpSelItems;
  425. BOOL bLFNTest;
  426. if (bLFNTest = (iSelType == 2)) {
  427. // determine if the directory it self is long...
  428. iSelType = FALSE;
  429. SendMessage(hwndDir, FS_GETDIRECTORY, sizeof(szPath), (LPARAM)szPath);
  430. StripBackslash(szPath);
  431. if (IsLFN(szPath))
  432. if (pfDir) {
  433. *pfDir = TRUE;
  434. }
  435. return NULL;
  436. }
  437. if (bPropertyDialog = (iSelType == 3)) {
  438. iSelType = FALSE;
  439. }
  440. bDir = FALSE;
  441. if (!bLFNTest) {
  442. cch = 1;
  443. p = (LPSTR)LocalAlloc(LPTR, cch);
  444. if (!p)
  445. return NULL;
  446. *p = '\0';
  447. }
  448. #ifdef DEBUG
  449. else
  450. p = (LPSTR)0xFFFF; // force a GP fault with bogus p use below
  451. #endif
  452. iLastSel = -1;
  453. iMac = (WORD)SendMessage(hwndLB, LB_GETSELCOUNT, 0, 0L);
  454. lpSelItems = LocalAlloc(LMEM_FIXED, sizeof(INT) * iMac);
  455. if (lpSelItems == NULL)
  456. return NULL;
  457. iMac = (WORD)SendMessage(hwndLB, LB_GETSELITEMS, (WPARAM)iMac, (LPARAM)lpSelItems);
  458. for (i=0; i < iMac; i++) {
  459. if (iLastSel == -1) // remember the first selection
  460. iLastSel = lpSelItems[i];
  461. SendMessage(hwndLB, LB_GETTEXT, lpSelItems[i], (LPARAM)&lpmydta);
  462. if (!lpmydta)
  463. break;
  464. lstrcpy(szFile, (LPSTR)lpmydta->my_cFileName);
  465. if (lpmydta->my_dwAttrs & ATTR_DIR) { // is this a dir
  466. SendMessage(hwndDir, FS_GETDIRECTORY, sizeof(szPath), (LPARAM)szPath);
  467. if (lpmydta->my_dwAttrs & ATTR_PARENT) { // parent dir?
  468. // if we are getting a full selection don't
  469. // return the parent ".." entry (avoid deleting
  470. // and other nasty operations on the parent)
  471. if (!iSelType)
  472. continue;
  473. StripBackslash(szPath); // trim it down
  474. StripFilespec(szPath);
  475. } else {
  476. lstrcat(szPath, szFile); // fully qualified
  477. }
  478. lstrcpy(szFile, szPath);
  479. bDir = TRUE;
  480. }
  481. if (bPropertyDialog)
  482. QualifyPath(szFile);
  483. if (bLFNTest && lpmydta->my_dwAttrs & ATTR_LFN) {
  484. return (LPSTR)TRUE;
  485. }
  486. CheckEscapes(szFile);
  487. if (!bLFNTest) {
  488. cch += lstrlen(szFile) + 1;
  489. pT = (LPSTR)LocalReAlloc((HANDLE)p, cch, LMEM_MOVEABLE | LMEM_ZEROINIT);
  490. if (!pT)
  491. goto GDSExit;
  492. p = pT;
  493. lstrcat(p, szFile);
  494. }
  495. if (iSelType)
  496. goto GDSExit;
  497. if (!bLFNTest)
  498. lstrcat(p, szBlank);
  499. }
  500. GDSExit:
  501. LocalFree(lpSelItems);
  502. if (bLFNTest) {
  503. if (pfDir) {
  504. *pfDir = FALSE;
  505. }
  506. return NULL;
  507. }
  508. if (pfDir) {
  509. *pfDir = bDir;
  510. }
  511. return p;
  512. }
  513. // compute the max extent of all the files in this DTA block
  514. // and update the case to match (wTextAttribs & TA_LOWERCASE)
  515. INT
  516. GetMaxExtent(
  517. HWND hwndLB,
  518. HANDLE hDTA
  519. )
  520. {
  521. LPMYDTA lpmydta;
  522. HDC hdc;
  523. INT nItems;
  524. INT maxWidth = 0;
  525. INT wWidth;
  526. HFONT hOld;
  527. CHAR szPath[MAXPATHLEN];
  528. lpmydta = (LPMYDTA)LocalLock(hDTA);
  529. nItems = (INT)lpmydta->my_nFileSizeLow;
  530. hdc = GetDC(hwndLB);
  531. hOld = SelectObject(hdc, hFont);
  532. while (nItems-- > 0) {
  533. lpmydta = GETDTAPTR(lpmydta, lpmydta->wSize);
  534. lstrcpy(szPath, lpmydta->my_cFileName);
  535. // set the case of the file names here!
  536. if (!(lpmydta->my_dwAttrs & ATTR_LFN)) {
  537. if (wTextAttribs & TA_LOWERCASE)
  538. AnsiLower(szPath);
  539. else
  540. AnsiUpper(szPath);
  541. }
  542. MGetTextExtent(hdc, szPath, lstrlen(szPath), &wWidth, NULL);
  543. maxWidth = max(wWidth, maxWidth);
  544. }
  545. if (hOld)
  546. SelectObject(hdc, hOld);
  547. ReleaseDC(hwndLB, hdc);
  548. LocalUnlock(hDTA);
  549. return maxWidth + 3; // pad it out
  550. }
  551. /*--------------------------------------------------------------------------*/
  552. /* */
  553. /* DirFindIndex() - */
  554. /* */
  555. /*--------------------------------------------------------------------------*/
  556. INT
  557. DirFindIndex(
  558. HWND hwndLB,
  559. HANDLE hDTA,
  560. LPSTR szFile
  561. )
  562. {
  563. register INT i;
  564. INT nSel;
  565. LPMYDTA lpmydta;
  566. lpmydta = (LPMYDTA)LocalLock(hDTA);
  567. nSel = (INT)lpmydta->my_nFileSizeLow;
  568. for (i = 0; i < nSel; i++) {
  569. SendMessage(hwndLB, LB_GETTEXT, (WORD)i, (LPARAM)&lpmydta);
  570. if (!lstrcmpi(szFile, (LPSTR)lpmydta->my_cFileName))
  571. goto DFIExit;
  572. }
  573. i = -1; // not found, return this
  574. DFIExit:
  575. LocalUnlock(hDTA);
  576. return i;
  577. }
  578. /*--------------------------------------------------------------------------*/
  579. /* */
  580. /* DirGetAnchorFocus() - */
  581. /* */
  582. /*--------------------------------------------------------------------------*/
  583. VOID
  584. DirGetAnchorFocus(
  585. register HWND hwndLB,
  586. HANDLE hDTA,
  587. LPSTR szAnchor,
  588. LPSTR szCaret,
  589. LPSTR szTopIndex
  590. )
  591. {
  592. register INT iSel, iCount;
  593. LPMYDTA lpmydta;
  594. hDTA; // fix compiler warning
  595. iSel = (INT)SendMessage(hwndLB, LB_GETANCHORINDEX, 0, 0L);
  596. iCount = (INT)SendMessage(hwndLB, LB_GETCOUNT, 0, 0L);
  597. if (iCount == 1) {
  598. SendMessage(hwndLB, LB_GETTEXT, (WORD)iSel, (LPARAM)&lpmydta);
  599. if (!lpmydta) {
  600. *szAnchor = 0L;
  601. *szCaret = 0L;
  602. *szTopIndex = 0L;
  603. return;
  604. }
  605. }
  606. if (iSel >= 0 && iSel < iCount) {
  607. SendMessage(hwndLB, LB_GETTEXT, (WORD)iSel, (LPARAM)&lpmydta);
  608. lstrcpy(szAnchor, (LPSTR)lpmydta->my_cFileName);
  609. } else
  610. *szAnchor = 0L;
  611. iSel = (INT)SendMessage(hwndLB, LB_GETCARETINDEX, 0, 0L);
  612. if (iSel >= 0 && iSel < iCount) {
  613. SendMessage(hwndLB, LB_GETTEXT, (WORD)iSel, (LPARAM)&lpmydta);
  614. lstrcpy(szCaret, (LPSTR)lpmydta->my_cFileName);
  615. } else
  616. *szCaret = 0L;
  617. iSel = (WORD)SendMessage(hwndLB, LB_GETTOPINDEX, 0, 0L);
  618. if (iSel >= 0 && iSel < iCount) {
  619. SendMessage(hwndLB, LB_GETTEXT, (WORD)iSel, (LPARAM)&lpmydta);
  620. lstrcpy(szTopIndex, (LPSTR)lpmydta->my_cFileName);
  621. } else
  622. *szTopIndex = 0L;
  623. }
  624. /*--------------------------------------------------------------------------*/
  625. /* */
  626. /* SetSelection() - */
  627. /* */
  628. /*--------------------------------------------------------------------------*/
  629. BOOL
  630. SetSelection(
  631. HWND hwndLB,
  632. HANDLE hDTA,
  633. LPSTR pSel
  634. )
  635. {
  636. INT i;
  637. CHAR szFile[MAXPATHLEN];
  638. BOOL bDidSomething = FALSE;
  639. while (pSel = GetNextFile(pSel, szFile, sizeof(szFile))) {
  640. i = DirFindIndex(hwndLB, hDTA, (LPSTR)szFile);
  641. if (i != -1) {
  642. SendMessage(hwndLB, LB_SETSEL, TRUE, (DWORD)i);
  643. bDidSomething = TRUE;
  644. }
  645. }
  646. return bDidSomething;
  647. }
  648. /*** FIX30: Why do we use LONG buffer ptrs here? ***/
  649. /*--------------------------------------------------------------------------*/
  650. /* */
  651. /* GetPict() - */
  652. /* */
  653. /*--------------------------------------------------------------------------*/
  654. /* This gets the number of consecutive chrs of the same kind. This is used
  655. * to parse the time picture. Returns 0 on error.
  656. */
  657. INT
  658. GetPict(
  659. CHAR ch,
  660. LPSTR szStr
  661. )
  662. {
  663. register INT count;
  664. count = 0;
  665. while (ch == *szStr++)
  666. count++;
  667. return(count);
  668. }
  669. /*--------------------------------------------------------------------------*/
  670. /* */
  671. /* CreateDate() - */
  672. /* */
  673. /*--------------------------------------------------------------------------*/
  674. /* This picks up the values in wValArray, converts them
  675. * in a string containing the formatted date.
  676. * wValArray should contain Month-Day-Year (in that order).
  677. */
  678. INT
  679. CreateDate(
  680. WORD *wValArray,
  681. LPSTR szOutStr
  682. )
  683. {
  684. INT i;
  685. INT cchPictPart;
  686. WORD wDigit;
  687. WORD wIndex;
  688. WORD wTempVal;
  689. register LPSTR pszPict;
  690. register LPSTR pszInStr;
  691. pszPict = szShortDate;
  692. pszInStr = szOutStr;
  693. for (i=0; i < 3; i++) {
  694. cchPictPart = GetPict(*pszPict, pszPict);
  695. switch (*pszPict) {
  696. case 'M':
  697. wIndex = 0;
  698. goto CDDoIt;
  699. case 'D':
  700. wIndex = 1;
  701. goto CDDoIt;
  702. case 'Y':
  703. wIndex = 2;
  704. if (cchPictPart == 4) {
  705. *pszInStr++ = '1';
  706. *pszInStr++ = '9';
  707. }
  708. CDDoIt:
  709. /* This assumes that the values are of two digits only. */
  710. wTempVal = wValArray[wIndex];
  711. wDigit = wTempVal / (WORD)10;
  712. if (wDigit)
  713. *pszInStr++ = (CHAR)(wDigit + '0');
  714. else if (cchPictPart > 1)
  715. *pszInStr++ = '0';
  716. #if 0
  717. else {
  718. *pszInStr++ = ' ';
  719. *pszInStr++ = ' ';
  720. }
  721. #endif
  722. *pszInStr++ = (CHAR)((wTempVal % 10) + '0');
  723. pszPict += cchPictPart;
  724. /* Add the separator. */
  725. if (*pszPict)
  726. *pszInStr++ = *pszPict;
  727. break;
  728. }
  729. pszPict++;
  730. }
  731. *pszInStr = 0L;
  732. return(lstrlen(szOutStr));
  733. }
  734. /*--------------------------------------------------------------------------*/
  735. /* */
  736. /* CreateTime() - */
  737. /* */
  738. /*--------------------------------------------------------------------------*/
  739. /* This picks up the values in wValArray, converts them
  740. * in a string containing the formatted time.
  741. * wValArray should contain Hour-Min-Sec (in that order).
  742. */
  743. INT
  744. CreateTime(
  745. WORD * wValArray,
  746. LPSTR szOutStr
  747. )
  748. {
  749. INT i;
  750. BOOL bAM;
  751. WORD wHourMinSec;
  752. register WORD wDigit;
  753. register LPSTR pszInStr;
  754. pszInStr = szOutStr;
  755. wDigit = wValArray[0];
  756. bAM = (wDigit < 12);
  757. if (!iTime) {
  758. if (wDigit >= 12)
  759. wDigit -= 12;
  760. if (!wDigit)
  761. wDigit = 12;
  762. }
  763. wValArray[0] = wDigit;
  764. for (i=0; i < 3; i++) {
  765. wHourMinSec = wValArray[i];
  766. /* This assumes that the values are of two digits only. */
  767. wDigit = wHourMinSec / (WORD)10;
  768. if (i > 0)
  769. *pszInStr++ = (CHAR)(wDigit + '0');
  770. else if (wDigit || iTLZero)
  771. *pszInStr++ = (CHAR)(wDigit + '0');
  772. #if 0
  773. else {
  774. /* NOTE: 2 blanks is the same width as one digit. */
  775. // wrong!
  776. *pszInStr++ = ' ';
  777. *pszInStr++ = ' ';
  778. }
  779. #endif
  780. *pszInStr++ = (CHAR)((wHourMinSec % 10) + '0');
  781. if (i < 2)
  782. *pszInStr++ = *szTime; /* Assumes time sep. is 1 char long */
  783. }
  784. // *pszInStr++ = ' ';
  785. if (bAM)
  786. lstrcpy(pszInStr, sz1159);
  787. else
  788. lstrcpy(pszInStr, sz2359);
  789. return lstrlen(szOutStr);
  790. }
  791. /*--------------------------------------------------------------------------*/
  792. /* */
  793. /* PutSize() - */
  794. /* */
  795. /*--------------------------------------------------------------------------*/
  796. INT
  797. APIENTRY
  798. PutSize(
  799. DWORD dwSize,
  800. LPSTR szOutStr
  801. )
  802. {
  803. // LPSTR szStr;
  804. // int cBlanks;
  805. // char szTemp[30];
  806. // Convert it into string
  807. return wsprintf(szOutStr, "%lu", dwSize);
  808. }
  809. /*--------------------------------------------------------------------------*/
  810. /* */
  811. /* PutDate() - */
  812. /* */
  813. /*--------------------------------------------------------------------------*/
  814. INT
  815. APIENTRY
  816. PutDate(
  817. LPFILETIME lpftDate,
  818. LPSTR szStr
  819. )
  820. {
  821. WORD wValArray[3];
  822. WORD wDate, wTime;
  823. if (FileTimeToDosDateTime(lpftDate, &wDate, &wTime)) {
  824. wValArray[0] = (WORD)((wDate & MONTHMASK) >> 5); /* Month */
  825. wValArray[1] = (WORD)((wDate & DATEMASK)); /* Date */
  826. wValArray[2] = (WORD)((wDate >> 9) + 80); /* Year */
  827. return(CreateDate((WORD *)wValArray, szStr));
  828. } else {
  829. return 0;
  830. }
  831. }
  832. /*--------------------------------------------------------------------------*/
  833. /* */
  834. /* PutTime() - */
  835. /* */
  836. /*--------------------------------------------------------------------------*/
  837. INT
  838. APIENTRY
  839. PutTime(
  840. LPFILETIME lpftTime,
  841. LPSTR szStr
  842. )
  843. {
  844. WORD wValArray[3];
  845. WORD wDate, wTime;
  846. if (FileTimeToDosDateTime(lpftTime, &wDate, &wTime)) {
  847. wValArray[0] = (wTime >> 0x0B);
  848. wValArray[1] = (WORD)((wTime & MINUTEMASK) >> 5);
  849. wValArray[2] = (WORD)((wTime & SECONDSMASK) << 1);
  850. return(CreateTime((WORD *)wValArray, szStr));
  851. } else {
  852. return 0;
  853. }
  854. }
  855. /*--------------------------------------------------------------------------*/
  856. /* */
  857. /* PutAttributes() - */
  858. /* */
  859. /*--------------------------------------------------------------------------*/
  860. INT
  861. APIENTRY
  862. PutAttributes(
  863. register DWORD dwAttribute,
  864. register LPSTR pszStr
  865. )
  866. {
  867. WORD i;
  868. INT cch = 0;
  869. for (i=0; i < 4; i++) {
  870. if (dwAttribute & 1) { // BUG hardcoded.
  871. *pszStr++ = szAttr[i];
  872. cch++;
  873. } else {
  874. #if 0
  875. *pszStr++ = '-';
  876. *pszStr++ = '-';
  877. cch += 2;
  878. #endif
  879. }
  880. if (i == 2)
  881. dwAttribute >>= 3; /* Skip next two bits */
  882. else
  883. dwAttribute >>= 1; /* Goto next bit */
  884. }
  885. *pszStr = 0;
  886. return(cch);
  887. }
  888. /*--------------------------------------------------------------------------*/
  889. /* */
  890. /* CreateLBLine() - */
  891. /* */
  892. /*--------------------------------------------------------------------------*/
  893. /* This creates a character string that contains all the required
  894. * details of a file; (Name, Size, Date, Time, Attr)
  895. */
  896. VOID
  897. CreateLBLine(
  898. register WORD wLineFormat,
  899. LPMYDTA lpmydta,
  900. LPSTR szBuffer
  901. )
  902. {
  903. register LPSTR pch;
  904. DWORD dwAttr;
  905. pch = szBuffer;
  906. dwAttr = lpmydta->my_dwAttrs;
  907. /* Copy the file name. */
  908. lstrcpy(pch, lpmydta->my_cFileName);
  909. pch += lstrlen(pch);
  910. *pch = 0L;
  911. /* Should we show the size? */
  912. if (wLineFormat & VIEW_SIZE) {
  913. *pch++ = TABCHAR;
  914. if (!(dwAttr & ATTR_DIR))
  915. pch += PutSize(lpmydta->my_nFileSizeLow, pch);
  916. else
  917. *pch = 0;
  918. }
  919. /* Should we show the date? */
  920. if (wLineFormat & VIEW_DATE) {
  921. *pch++ = TABCHAR;
  922. pch += PutDate(&lpmydta->my_ftLastWriteTime, pch);
  923. }
  924. /* Should we show the time? */
  925. if (wLineFormat & VIEW_TIME) {
  926. *pch++ = TABCHAR;
  927. pch += PutTime(&lpmydta->my_ftLastWriteTime, pch);
  928. }
  929. /* Should we show the attributes? */
  930. if (wLineFormat & VIEW_FLAGS) {
  931. *pch++ = TABCHAR;
  932. pch += PutAttributes(dwAttr, pch);
  933. }
  934. // *pch = 0L;
  935. }
  936. /*--------------------------------------------------------------------------*/
  937. /* */
  938. /* CompareDTA() - */
  939. /* */
  940. /*--------------------------------------------------------------------------*/
  941. INT
  942. CompareDTA(
  943. register LPMYDTA lpItem1,
  944. LPMYDTA lpItem2,
  945. WORD wSort
  946. )
  947. {
  948. register INT ret;
  949. if (lpItem1->my_dwAttrs & ATTR_PARENT) {
  950. ret = -1;
  951. goto CDDone;
  952. }
  953. if (lpItem2->my_dwAttrs & ATTR_PARENT) {
  954. ret = 1;
  955. goto CDDone;
  956. }
  957. if ((lpItem1->my_dwAttrs & ATTR_DIR) > (lpItem2->my_dwAttrs & ATTR_DIR)) {
  958. ret = -1;
  959. goto CDDone;
  960. } else if ((lpItem1->my_dwAttrs & ATTR_DIR) < (lpItem2->my_dwAttrs & ATTR_DIR)) {
  961. ret = 1;
  962. goto CDDone;
  963. }
  964. switch (wSort) {
  965. case IDD_TYPE:
  966. {
  967. LPSTR ptr1;
  968. LPSTR ptr2;
  969. // BUG: should use strrchr for long file names.
  970. for (ptr1 = lpItem1->my_cFileName; *ptr1 && *ptr1 != '.'; ptr1++)
  971. ;
  972. for (ptr2 = lpItem2->my_cFileName; *ptr2 && *ptr2 != '.'; ptr2++)
  973. ;
  974. ret = lstrcmpi(ptr1, ptr2);
  975. if (ret == 0)
  976. goto CompareNames;
  977. break;
  978. }
  979. case IDD_SIZE:
  980. if (lpItem1->my_nFileSizeLow > lpItem2->my_nFileSizeLow)
  981. ret = -1;
  982. else if (lpItem1->my_nFileSizeLow < lpItem2->my_nFileSizeLow)
  983. ret = 1;
  984. else
  985. goto CompareNames;
  986. break;
  987. case IDD_DATE:
  988. {
  989. DWORD d1High, d1Low;
  990. DWORD d2High, d2Low;
  991. d1High = lpItem1->my_ftLastWriteTime.dwHighDateTime;
  992. d2High = lpItem2->my_ftLastWriteTime.dwHighDateTime;
  993. if (d1High > d2High) {
  994. ret = -1;
  995. } else if (d1High < d2High) {
  996. ret = 1;
  997. } else {
  998. d1Low = lpItem1->my_ftLastWriteTime.dwLowDateTime;
  999. d2Low = lpItem2->my_ftLastWriteTime.dwLowDateTime;
  1000. if (d1Low > d2Low)
  1001. ret = -1;
  1002. else if (d1Low < d2Low)
  1003. ret = 1;
  1004. else
  1005. goto CompareNames;
  1006. }
  1007. break;
  1008. }
  1009. case IDD_NAME:
  1010. CompareNames:
  1011. ret = lstrcmpi(lpItem1->my_cFileName, lpItem2->my_cFileName);
  1012. break;
  1013. }
  1014. CDDone:
  1015. return ret;
  1016. }
  1017. // load the status buffers with the appropriate stuff and invalidates
  1018. // the status area causing it to repaint.
  1019. VOID
  1020. APIENTRY
  1021. UpdateStatus(
  1022. HWND hWnd
  1023. )
  1024. {
  1025. CHAR szTemp[128];
  1026. WCHAR szNumBuf1[40];
  1027. WCHAR szNumBuf2[40];
  1028. WORD wDrive;
  1029. HWND hwndDir;
  1030. RECT rc;
  1031. if (!bStatusBar)
  1032. return;
  1033. if (hWnd != (HWND)SendMessage(hwndMDIClient, WM_MDIGETACTIVE, 0, 0L))
  1034. return;
  1035. hwndDir = HasDirWindow(hWnd);
  1036. szStatusTree[0] = 0L;
  1037. if (hwndDir)
  1038. GetDirStatus(hwndDir, szStatusTree, szStatusDir);
  1039. else
  1040. szStatusDir[0] = 0L;
  1041. // force the status area to update
  1042. GetClientRect(hwndFrame, &rc);
  1043. rc.top = rc.bottom - dyStatus;
  1044. InvalidateRect(hwndFrame, &rc, FALSE);
  1045. }
  1046. HWND
  1047. GetDirSelData(
  1048. HWND hWnd,
  1049. DWORD *pdwSelSize,
  1050. INT *piSelCount,
  1051. DWORD *pdwTotalSize,
  1052. INT *piTotalCount
  1053. )
  1054. {
  1055. INT i;
  1056. LPMYDTA lpmydta;
  1057. HWND hwndLB;
  1058. INT countSel, countTotal;
  1059. LPINT lpSelItems, lpSelItemsT;
  1060. HANDLE hDTA;
  1061. if (!(hwndLB = GetDlgItem(hWnd, IDCW_LISTBOX))) { // fast scroll
  1062. return NULL;
  1063. }
  1064. *pdwSelSize = *pdwTotalSize = 0L;
  1065. *piSelCount = *piTotalCount = 0;
  1066. countSel = (INT)SendMessage(hwndLB, LB_GETSELCOUNT, 0, 0L);
  1067. lpSelItems = LocalAlloc(LMEM_FIXED, sizeof(INT) * countSel);
  1068. if (lpSelItems == NULL)
  1069. return NULL;
  1070. countSel = (INT)SendMessage(hwndLB, LB_GETSELITEMS, (WPARAM)countSel, (LPARAM)lpSelItems);
  1071. hDTA = (HANDLE)GetWindowLongPtr(hWnd, GWLP_HDTA);
  1072. if (hDTA == NULL)
  1073. return NULL;
  1074. lpmydta = (LPMYDTA)LocalLock(hDTA);
  1075. countTotal = (INT)lpmydta->my_nFileSizeLow;
  1076. lpSelItemsT = lpSelItems;
  1077. for (i = 0; i < countTotal; i++) {
  1078. lpmydta = GETDTAPTR(lpmydta, lpmydta->wSize);
  1079. if (lpmydta->my_dwAttrs & ATTR_PARENT)
  1080. continue;
  1081. if (countSel && *lpSelItems == lpmydta->nIndex) {
  1082. (*piSelCount)++;
  1083. *pdwSelSize += lpmydta->my_nFileSizeLow;
  1084. countSel--;
  1085. lpSelItems++;
  1086. }
  1087. (*piTotalCount)++;
  1088. *pdwTotalSize += lpmydta->my_nFileSizeLow;
  1089. }
  1090. LocalUnlock(hDTA);
  1091. LocalFree(lpSelItemsT);
  1092. return hwndLB;
  1093. }
  1094. VOID
  1095. GetDirStatus(
  1096. HWND hWnd,
  1097. LPSTR szMessage1,
  1098. LPSTR szMessage2
  1099. )
  1100. {
  1101. INT iSelCount, iCount;
  1102. DWORD dwSelSize, dwSize;
  1103. CHAR szNumBuf[40];
  1104. HWND hwndLB;
  1105. szMessage2[0] = 0;
  1106. hwndLB = GetDirSelData(hWnd, &dwSelSize, &iSelCount, &dwSize, &iCount);
  1107. if (LoadString(hAppInstance, IDS_STATUSMSG, szMessage, sizeof(szMessage)))
  1108. wsprintf(szMessage2, szMessage, iCount);
  1109. if ((HWND)GetWindowLongPtr(GetParent(hWnd), GWLP_LASTFOCUS) == hwndLB) {
  1110. if (LoadString(hAppInstance, IDS_STATUSMSG2, szMessage, sizeof(szMessage)))
  1111. wsprintf(szMessage1, szMessage, iSelCount);
  1112. }
  1113. }
  1114. // given a descendant of an MDI child (or an MDI child) return
  1115. // the MDI child in the descendant chain. returns NULL if not
  1116. // found.
  1117. HWND
  1118. APIENTRY
  1119. GetMDIChildFromDecendant(
  1120. HWND hwnd
  1121. )
  1122. {
  1123. HWND hwndT;
  1124. while (hwnd && ((hwndT = GetParent(hwnd)) != hwndMDIClient))
  1125. hwnd = hwndT;
  1126. return hwnd;
  1127. }
  1128. // setup the defTabStops[] array for subsequent TabbedTextOut() calls.
  1129. //
  1130. // in:
  1131. // iMaxWidthFileName the largest dx width of files to be
  1132. // displayed
  1133. //
  1134. // returns:
  1135. // total extent of the "File Details" view. used to
  1136. // set scroll extents
  1137. INT
  1138. APIENTRY
  1139. FixTabsAndThings(
  1140. HWND hwndLB,
  1141. WORD *pwTabs,
  1142. INT iMaxWidthFileName,
  1143. WORD wViewOpts
  1144. )
  1145. {
  1146. INT i;
  1147. HDC hdc;
  1148. HFONT hOld;
  1149. CHAR szBuf[30];
  1150. INT ixExtent = 0;
  1151. i = iMaxWidthFileName; // the widest filename
  1152. if (pwTabs == NULL)
  1153. return i;
  1154. hdc = GetDC(NULL);
  1155. hOld = SelectObject(hdc, hFont);
  1156. // max size digits field
  1157. if (wViewOpts & VIEW_SIZE) {
  1158. MGetTextExtent(hdc, "99999999", 8, &ixExtent, NULL);
  1159. i += ixExtent + dxText;
  1160. *pwTabs++ = (WORD)i; // Size
  1161. }
  1162. if (wViewOpts & VIEW_DATE) {
  1163. FILETIME filetime;
  1164. DosDateTimeToFileTime((WORD)((19 << 9) | (12 << 5) | 30), (WORD)0xFFFF, &filetime);
  1165. PutDate(&filetime, szBuf);
  1166. // max date digits
  1167. MGetTextExtent(hdc, szBuf, lstrlen(szBuf), &ixExtent, NULL);
  1168. i += ixExtent + dxText;
  1169. *pwTabs++ = (WORD)i; // Date
  1170. }
  1171. // max time digits
  1172. if (wViewOpts & VIEW_TIME) {
  1173. FILETIME filetime;
  1174. DosDateTimeToFileTime((WORD)((19 << 9) | (12 << 5) | 30), (WORD)0xFFFF, &filetime);
  1175. PutTime(&filetime, szBuf);
  1176. MGetTextExtent(hdc, szBuf, lstrlen(szBuf), &ixExtent, NULL);
  1177. i += ixExtent + dxText;
  1178. *pwTabs++ = (WORD)i; // Time
  1179. }
  1180. // max attris digits
  1181. if (wViewOpts & VIEW_FLAGS) {
  1182. PutAttributes(ATTR_ALL, szBuf);
  1183. MGetTextExtent(hdc, szBuf, lstrlen(szBuf), &ixExtent, NULL);
  1184. i += ixExtent + dxText;
  1185. *pwTabs++ = (WORD)i; // Attributes
  1186. }
  1187. if (hOld)
  1188. SelectObject(hdc, hOld);
  1189. ReleaseDC(NULL, hdc);
  1190. SendMessage(hwndLB, LB_SETHORIZONTALEXTENT,
  1191. i + dxFolder + 4 * dyBorderx2, 0L);
  1192. return i; // total extent
  1193. }
  1194. // sets the font and adjusts the dimension parameters for the
  1195. // new font
  1196. //
  1197. // in:
  1198. // hWnd hwnd of a dir window
  1199. // hwndLB and it's listbox
  1200. // hFont the font to set
  1201. //
  1202. // uses:
  1203. // dyFileName GLOBAL; set based on new font height
  1204. // GWL_VIEW window word of hWnd for either full or name view
  1205. // GWL_HDTA to compute the max extent given the new font
  1206. //
  1207. // sets:
  1208. // Listbox tabs array
  1209. // LB_SETCOLUMNWIDTH
  1210. // or
  1211. // LB_SETHORIZONTALEXTENT
  1212. VOID
  1213. APIENTRY
  1214. SetLBFont(
  1215. HWND hWnd,
  1216. HWND hwndLB,
  1217. HANDLE hNewFont
  1218. )
  1219. {
  1220. INT dxMaxExtent;
  1221. HANDLE hDTA;
  1222. WORD wViewFlags = (WORD)GetWindowLong(GetParent(hWnd), GWL_VIEW);
  1223. SendMessage(hwndLB, WM_SETFONT, (WPARAM)hNewFont, 0L);
  1224. // this is needed when changing the font. when creating
  1225. // the return from WM_MEASUREITEM will set the cell height
  1226. SendMessage(hwndLB, LB_SETITEMHEIGHT, 0, (LONG)dyFileName);
  1227. hDTA = (HANDLE)GetWindowLongPtr(hWnd, GWLP_HDTA);
  1228. dxMaxExtent = (INT)GetMaxExtent(hwndLB, hDTA);
  1229. // if we are in name only view we change the width
  1230. if ((VIEW_EVERYTHING & wViewFlags) == VIEW_NAMEONLY) {
  1231. SendMessage(hwndLB, LB_SETCOLUMNWIDTH, dxMaxExtent + dxFolder + dyBorderx2, 0L);
  1232. } else {
  1233. FixTabsAndThings(hwndLB,(WORD *)GetWindowLongPtr(hWnd, GWLP_TABARRAY),
  1234. dxMaxExtent, wViewFlags);
  1235. }
  1236. }
  1237. VOID
  1238. APIENTRY
  1239. UpdateSelection(
  1240. HWND hwndLB
  1241. )
  1242. {
  1243. INT count, i;
  1244. RECT rc;
  1245. count = (WORD)SendMessage(hwndLB, LB_GETCOUNT, 0, 0L);
  1246. for (i=0; i < count; i++) {
  1247. if ((BOOL)SendMessage(hwndLB, LB_GETSEL, i, 0L)) {
  1248. SendMessage(hwndLB, LB_GETITEMRECT, i, (LPARAM)&rc);
  1249. InvalidateRect(hwndLB, &rc, TRUE);
  1250. }
  1251. }
  1252. }
  1253. LONG
  1254. CreateFSCChangeDisplayMess(
  1255. HWND hWnd,
  1256. UINT wMsg,
  1257. WPARAM wParam,
  1258. LPARAM lParam
  1259. )
  1260. {
  1261. CHAR szCaret[MAXFILENAMELEN+1];
  1262. CHAR szAnchor[MAXFILENAMELEN+1];
  1263. CHAR szTopIndex[MAXFILENAMELEN+1];
  1264. CHAR szPath[256];
  1265. HCURSOR hCursor;
  1266. HWND hwndLB, hwndT;
  1267. HANDLE hDTA;
  1268. LPMYDTA lpmydta;
  1269. DWORD ws;
  1270. LPSTR pSel;
  1271. INT iSel, iTop=0;
  1272. RECT rc;
  1273. BOOL bResetFocus;
  1274. WORD *pwTabs;
  1275. hwndLB = GetDlgItem(hWnd, IDCW_LISTBOX);
  1276. switch (wMsg) {
  1277. case WM_FILESYSCHANGE:
  1278. if (cDisableFSC) {
  1279. // I need to be updated
  1280. SetWindowLong(GetParent(hWnd), GWL_FSCFLAG, TRUE);
  1281. break;
  1282. }
  1283. wParam = CD_PATH;
  1284. lParam = 0L;
  1285. /*** FALL THRU ***/
  1286. case FS_CHANGEDISPLAY:
  1287. // We dont want to reset the flag, if the operation is not CD_PATH.
  1288. // This is because, only the operation CD_PATH implies a true
  1289. // refresh. The operations CD_VEIW and CD_SORT are not refresh
  1290. // operations. They merely reformat the existing contents of a dir
  1291. // window. The flag is now reset in 'case CD_PATH:'.
  1292. //SetWindowLong(GetParent(hWnd), GWL_FSCFLAG, FALSE);
  1293. hCursor = SetCursor(LoadCursor(NULL, IDC_WAIT));
  1294. ShowCursor(TRUE);
  1295. pSel = NULL; // init this
  1296. bResetFocus = (GetFocus() == hwndLB);
  1297. hDTA = (HANDLE)GetWindowLongPtr(hWnd, GWLP_HDTA);
  1298. switch (wParam) {
  1299. case CD_SORT:
  1300. // change the sort order of the listbox
  1301. // we want to save the current selection and things here
  1302. // and restore them once the listbox has been rebuilt
  1303. // But first, save a list of the selected items FIX31
  1304. pSel = (LPSTR)DirGetSelection(hWnd, hwndLB, 0, NULL);
  1305. DirGetAnchorFocus(hwndLB, hDTA, szAnchor, szCaret, szTopIndex);
  1306. iTop = (INT)SendMessage(hwndLB, LB_GETTOPINDEX, 0, 0L);
  1307. SetWindowLong(GetParent(hWnd), GWL_SORT, LOWORD(lParam));
  1308. SendMessage(hwndLB, LB_RESETCONTENT, 0, 0L);
  1309. SendMessage(hwndLB, WM_SETREDRAW, FALSE, 0L);
  1310. FillDirList(hwndLB, hDTA);
  1311. goto ResetSelection;
  1312. case CD_VIEW:
  1313. {
  1314. WORD wCurView;
  1315. // change the view type (name only, vs full details)
  1316. // Warning! Convoluted Code! We want to destroy the
  1317. // listbox only if we are going between Name Only view
  1318. // and Details view.
  1319. wNewView = LOWORD(lParam);
  1320. wCurView = (WORD)GetWindowLong(GetParent(hWnd), GWL_VIEW);
  1321. if (wNewView == wCurView)
  1322. break; // NOP
  1323. // special case the long and partial view change
  1324. // this doesn't require us to recreate the listbox
  1325. if ((VIEW_EVERYTHING & wNewView) && (VIEW_EVERYTHING & wCurView)) {
  1326. SetWindowLong(GetParent(hWnd), GWL_VIEW, wNewView);
  1327. FixTabsAndThings(hwndLB,(WORD *)GetWindowLongPtr(hWnd, GWLP_TABARRAY),
  1328. GetMaxExtent(hwndLB, hDTA), wNewView);
  1329. InvalidateRect(hwndLB, NULL, TRUE);
  1330. break;
  1331. }
  1332. /* Things are a changing radically. Destroy the listbox. */
  1333. // But first, save a list of the selected items
  1334. pSel = (LPSTR)DirGetSelection(hWnd, hwndLB, 0, NULL);
  1335. DirGetAnchorFocus(hwndLB, hDTA, szAnchor, szCaret, szTopIndex);
  1336. iTop = (INT)SendMessage(hwndLB, LB_GETTOPINDEX, 0, 0L);
  1337. lstrcpy(szTopIndex, szCaret);
  1338. if ((HWND)GetWindowLongPtr(GetParent(hWnd), GWLP_LASTFOCUS) == hwndLB)
  1339. SetWindowLongPtr(GetParent(hWnd), GWLP_LASTFOCUS, 0L);
  1340. DestroyWindow(hwndLB);
  1341. /* Create a new one (preserving the Sort setting). */
  1342. wNewSort = (WORD)GetWindowLong(GetParent(hWnd), GWL_SORT);
  1343. dwNewAttribs = (DWORD)GetWindowLong(GetParent(hWnd), GWL_ATTRIBS);
  1344. goto CreateLB;
  1345. }
  1346. case CD_PATH | CD_ALLOWABORT:
  1347. case CD_PATH:
  1348. case CD_PATH_FORCE:
  1349. // bad things happens if we change the path
  1350. // while we are reading the tree. bounch this
  1351. // in that case. this causes the steal data
  1352. // code in the tree to barf because we would
  1353. // free the hDTA while it is being traversed
  1354. // (very bad thing)
  1355. // we set the GWL_FSCFLAG to true, if we could not refresh.
  1356. // else we set it to FALSE. However if the flag was previously
  1357. // TRUE we set lParam to NULL. lParam = NULL implies 'forced'
  1358. // refresh.
  1359. hwndT = HasTreeWindow(GetParent(hWnd));
  1360. if (hwndT && GetWindowLong(hwndT, GWL_READLEVEL)) {
  1361. SetWindowLong(GetParent(hWnd), GWL_FSCFLAG, TRUE);
  1362. break;
  1363. } else {
  1364. if (SetWindowLong(GetParent(hWnd), GWL_FSCFLAG, FALSE))
  1365. lParam = 0L;
  1366. }
  1367. // change the path of the current directory window (basically
  1368. // recreate the whole thing)
  1369. // if lParam == NULL this is a refresh, otherwise
  1370. // check for short circut case to avoid rereading
  1371. // the directory
  1372. GetMDIWindowText(GetParent(hWnd), szPath, sizeof(szPath));
  1373. if (lParam) {
  1374. // get out early if this is a NOP
  1375. if ((wParam != CD_PATH_FORCE) &&
  1376. !lstrcmpi(szPath, (LPSTR)lParam))
  1377. break;
  1378. lstrcpy(szPath, (LPSTR)lParam);
  1379. iLastSel = -1; // invalidate the last selection
  1380. }
  1381. // if this is a refresh save the current selection, anchor stuff, etc
  1382. if (!lParam) {
  1383. pSel = (LPSTR)DirGetSelection(hWnd, hwndLB, 0, NULL);
  1384. iTop = (INT)SendMessage(hwndLB, LB_GETTOPINDEX, 0, 0L);
  1385. DirGetAnchorFocus(hwndLB, hDTA, szAnchor, szCaret, szTopIndex);
  1386. }
  1387. // Create a new one (preserving the Sort setting)
  1388. wNewSort = (WORD)GetWindowLong(GetParent(hWnd), GWL_SORT);
  1389. wNewView = (WORD)GetWindowLong(GetParent(hWnd), GWL_VIEW);
  1390. dwNewAttribs = GetWindowLong(GetParent(hWnd), GWL_ATTRIBS);
  1391. if (hDTA) { // fast scroll case
  1392. LocalFree(hDTA);
  1393. hDTA = NULL;
  1394. SendMessage(hwndLB, LB_RESETCONTENT, 0, 0L);
  1395. }
  1396. goto CreateNewPath;
  1397. }
  1398. SetCursor(hCursor);
  1399. ShowCursor(FALSE);
  1400. break;
  1401. case WM_CREATE:
  1402. TRACE(BF_WM_CREATE, "CreateFSCChangeDisplayMess - WM_CREATE");
  1403. // wNewView, wNewSort and dwNewAddribs define the viewing
  1404. // parameters of the new window (GLOBALS)
  1405. // the window text of the parent window defines the
  1406. // filespec and the directory to open up
  1407. hCursor = SetCursor(LoadCursor(NULL, IDC_WAIT));
  1408. ShowCursor(TRUE);
  1409. wParam = 0; // don't allow abort in CreateDTABlock()
  1410. lParam = 1L; // allow DTA steal optimization
  1411. pSel = NULL; // no selection to restore
  1412. bResetFocus = FALSE; // no focus to restore
  1413. // get the dir to open from our parent window text
  1414. GetMDIWindowText(GetParent(hWnd), szPath, sizeof(szPath));
  1415. if ((pwTabs = (WORD *)LocalAlloc(LPTR,sizeof(WORD) * 4)) == NULL)
  1416. return -1L;
  1417. SetWindowLongPtr(hWnd, GWLP_TABARRAY, (ULONG_PTR)pwTabs);
  1418. CreateNewPath:
  1419. // at this point szPath has the directory to read. this
  1420. // either came from the WM_CREATE case or the
  1421. // FS_CHANGEDISPLAY (CD_PATH) directory reset
  1422. #ifdef DEBUG
  1423. {
  1424. char buf[80];
  1425. wsprintf(buf, "attribs %4.4X\r\n", dwNewAttribs);
  1426. OutputDebugString(buf);
  1427. }
  1428. #endif
  1429. if (!dwNewAttribs)
  1430. dwNewAttribs = ATTR_DEFAULT;
  1431. hDTA = CreateDTABlock(hWnd, szPath, dwNewAttribs, wParam & CD_ALLOWABORT ? TRUE : FALSE, lParam == 0L);
  1432. // check for user abort (fast scroll case)
  1433. if (hDTA == (HANDLE)-1) {
  1434. SetWindowLongPtr(hWnd, GWLP_HDTA, 0L);
  1435. goto FastScrollExit;
  1436. }
  1437. // for the FS_CHANGEDISPLAY case we set this now, to avoid
  1438. // multiple title repaints when the user is fast scrolling
  1439. if (wMsg != WM_CREATE)
  1440. SetMDIWindowText(GetParent(hWnd), szPath);
  1441. SetWindowLongPtr(hWnd, GWLP_HDTA, (LONG_PTR)hDTA);
  1442. if (!hDTA)
  1443. goto CDAbort;
  1444. if (wMsg != WM_CREATE)
  1445. goto SkipWindowCreate;
  1446. CreateLB:
  1447. if ((wNewView & VIEW_EVERYTHING) == VIEW_NAMEONLY)
  1448. ws = WS_DIRSTYLE | LBS_MULTICOLUMN | WS_HSCROLL | WS_VISIBLE | WS_BORDER | LBS_DISABLENOSCROLL;
  1449. else
  1450. ws = WS_DIRSTYLE | WS_HSCROLL | WS_VSCROLL | WS_VISIBLE | WS_BORDER | LBS_DISABLENOSCROLL;
  1451. GetClientRect(hWnd, &rc);
  1452. // the border stuff is for the non initial create case
  1453. // I don't know why
  1454. hwndLB = CreateWindowEx(0L, szListbox, NULL, ws,
  1455. dyBorder, dyBorder,
  1456. rc.right - 2*dyBorder, rc.bottom - 2*dyBorder,
  1457. hWnd, (HMENU)IDCW_LISTBOX,
  1458. hAppInstance, NULL);
  1459. if (!hwndLB) {
  1460. if (hDTA)
  1461. LocalFree(hDTA);
  1462. if (wMsg != WM_CREATE)
  1463. SendMessage(hWnd, WM_SYSCOMMAND, SC_CLOSE, 0L);
  1464. CDAbort:
  1465. ShowCursor(FALSE);
  1466. SetCursor(hCursor);
  1467. return -1L;
  1468. }
  1469. // set all the view/sort/include parameters here
  1470. SetWindowLong(GetParent(hWnd), GWL_VIEW, wNewView);
  1471. SetWindowLong(GetParent(hWnd), GWL_SORT, wNewSort);
  1472. SetWindowLong(GetParent(hWnd), GWL_ATTRIBS, dwNewAttribs);
  1473. // restore the last focus stuff if we are recreating here
  1474. if (!GetWindowLongPtr(GetParent(hWnd), GWLP_LASTFOCUS))
  1475. SetWindowLongPtr(GetParent(hWnd), GWLP_LASTFOCUS, (LONG_PTR)hwndLB);
  1476. // set the font and dimensions here
  1477. SkipWindowCreate:
  1478. SetLBFont(hWnd, hwndLB, hFont);
  1479. SendMessage(hwndLB, WM_SETREDRAW, FALSE, 0L);
  1480. FillDirList(hwndLB, hDTA);
  1481. if (pSel) {
  1482. BOOL bDidSomething;
  1483. ResetSelection:
  1484. /* Give the selected item the focus rect and anchor pt. */
  1485. bDidSomething = SetSelection(hwndLB, hDTA, pSel);
  1486. LocalFree((HANDLE)pSel);
  1487. if (!bDidSomething)
  1488. goto SelectFirst;
  1489. iSel = DirFindIndex(hwndLB, hDTA, szTopIndex);
  1490. if (iSel == -1)
  1491. iSel = 0;
  1492. SendMessage(hwndLB, LB_SETTOPINDEX, iSel, 0L);
  1493. iSel = DirFindIndex(hwndLB, hDTA, szAnchor);
  1494. if (iSel == -1)
  1495. iSel = 0;
  1496. SendMessage(hwndLB, LB_SETANCHORINDEX, iSel, 0L);
  1497. iSel = DirFindIndex(hwndLB, hDTA, szCaret);
  1498. if (iSel == -1)
  1499. iSel = 0;
  1500. /* SETCARETINDEX will scroll item into view */
  1501. SendMessage(hwndLB, LB_SETCARETINDEX, iSel, 0L);
  1502. } else {
  1503. INT iLBCount;
  1504. SelectFirst:
  1505. iLBCount = (INT)SendMessage(hwndLB, LB_GETCOUNT, 0, 0L);
  1506. if (iLastSel != -1 && (iLastSel <= iLBCount)) {
  1507. iSel = iLastSel;
  1508. // check the case of the last item being deleted
  1509. if (iSel == iLBCount)
  1510. iSel--;
  1511. SendMessage(hwndLB, LB_SETSEL, TRUE, (DWORD)iSel);
  1512. } else {
  1513. // Select the first non-directory item
  1514. iSel = 0;
  1515. while (iSel < iLBCount) {
  1516. SendMessage(hwndLB, LB_GETTEXT, iSel, (LPARAM)&lpmydta);
  1517. if (!lpmydta)
  1518. break;
  1519. if (!(lpmydta->my_dwAttrs & ATTR_PARENT)) {
  1520. iTop = iSel;
  1521. break;
  1522. }
  1523. iSel++;
  1524. }
  1525. LocalUnlock(hDTA);
  1526. if (iSel == iLBCount)
  1527. iSel = 0;
  1528. }
  1529. SendMessage(hwndLB, LB_SETTOPINDEX, iTop, 0L);
  1530. // and select this item if no tree window
  1531. if (!HasTreeWindow(GetParent(hWnd)))
  1532. SendMessage(hwndLB, LB_SETSEL, TRUE, (DWORD)iSel);
  1533. SendMessage(hwndLB, LB_SETANCHORINDEX, iSel, 0L);
  1534. /* SETCARETINDEX will scroll item into view */
  1535. SendMessage(hwndLB, LB_SETCARETINDEX, iSel, 0L);
  1536. }
  1537. if (bResetFocus)
  1538. if (SetDirFocus(hWnd))
  1539. SetFocus(hWnd);
  1540. SendMessage(hwndLB, WM_SETREDRAW, TRUE, 0L);
  1541. InvalidateRect(hwndLB, NULL, TRUE);
  1542. lFreeSpace = -1; // force status update
  1543. UpdateStatus(GetParent(hWnd));
  1544. FastScrollExit:
  1545. ShowCursor(FALSE);
  1546. SetCursor(hCursor);
  1547. break;
  1548. }
  1549. return 0L;
  1550. }
  1551. INT_PTR
  1552. APIENTRY
  1553. DirWndProc(
  1554. HWND hWnd,
  1555. UINT wMsg,
  1556. WPARAM wParam,
  1557. LPARAM lParam
  1558. )
  1559. {
  1560. INT iSel, i;
  1561. LPSTR pSel;
  1562. HWND hwndLB;
  1563. HANDLE hDTA;
  1564. LPMYDTA lpmydta;
  1565. CHAR szTemp[MAXPATHLEN] = {0};
  1566. CHAR szSourceFile[MAXPATHLEN];
  1567. static HWND hwndOwnerDraw = NULL;
  1568. STKCHK();
  1569. /* Here we generate OWNERDRAWBEGIN and OWNERDRAWEND messages
  1570. * to speed up the painting operations. We do the expensive stuff
  1571. * at the beginning instead of on every DRAWITEM message.
  1572. */
  1573. if (hwndOwnerDraw == hWnd && wMsg != WM_DRAWITEM) {
  1574. hwndOwnerDraw = NULL;
  1575. SendMessage(hWnd, WM_OWNERDRAWEND, 0, 0L);
  1576. } else if (wMsg == WM_DRAWITEM && hwndOwnerDraw != hWnd) {
  1577. SendMessage(hWnd, WM_OWNERDRAWBEGIN, wParam, lParam);
  1578. hwndOwnerDraw = hWnd;
  1579. }
  1580. hwndLB = GetDlgItem(hWnd, IDCW_LISTBOX);
  1581. switch (wMsg) {
  1582. // returns in lParam upper case ANSI directory string with
  1583. // a trailing backslash. if you want to do a SetCurrentDirecotor()
  1584. // you must first StripBackslash() the thing!
  1585. case FS_GETDIRECTORY:
  1586. MSG("DirWndProc", "FS_GETDIRECTORY");
  1587. GetMDIWindowText(GetParent(hWnd), (LPSTR)lParam, (INT)wParam); // get the string
  1588. StripFilespec((LPSTR)lParam); // Remove the trailing extention
  1589. AddBackslash((LPSTR)lParam); // terminate with a backslash
  1590. //AnsiUpper((LPSTR)lParam); // and upper case
  1591. break;
  1592. case FS_GETDRIVE:
  1593. MSG("DirWndProc", "FS_GETDRIVE");
  1594. // Returns the letter of the corresponding directory
  1595. GetWindowText(GetParent(hWnd), szTemp, sizeof(szTemp));
  1596. AnsiUpper(szTemp);
  1597. return szTemp[0]; // first character
  1598. case FS_GETFILESPEC:
  1599. MSG("DirWndProc", "FS_GETFILESPEC");
  1600. // returns the current filespec (from View.Include...). this is
  1601. // an uppercase ANSI string
  1602. GetMDIWindowText(GetParent(hWnd), (LPSTR)lParam, (INT)wParam);
  1603. StripPath((LPSTR)lParam);
  1604. //AnsiUpper((LPSTR)lParam); // and upper case
  1605. break;
  1606. case FS_SETSELECTION:
  1607. MSG("DirWndProc", "FS_SETSELECTION");
  1608. // wParam is the select(TRUE)/unselect(FALSE) param
  1609. // lParam is the filespec to match against
  1610. SendMessage(hwndLB, WM_SETREDRAW, FALSE, 0L);
  1611. DSSetSelection(hwndLB, wParam ? TRUE : FALSE, (LPSTR)lParam, FALSE);
  1612. SendMessage(hwndLB, WM_SETREDRAW, TRUE, 0L);
  1613. InvalidateRect(hwndLB, NULL, TRUE);
  1614. break;
  1615. case FS_GETSELECTION:
  1616. // return = pszDir
  1617. #define pfDir (BOOL *)lParam
  1618. #define fSingleSel (BOOL)wParam
  1619. MSG("DirWndProc", "FS_GETSELECTION");
  1620. return (INT_PTR)DirGetSelection(hWnd, hwndLB, fSingleSel, pfDir);
  1621. #undef pfDir
  1622. #undef fSingleSel
  1623. case WM_CREATE:
  1624. case WM_FILESYSCHANGE:
  1625. case FS_CHANGEDISPLAY:
  1626. TRACE(BF_WM_CREATE, "DirWndProc - WM_CREATE");
  1627. return CreateFSCChangeDisplayMess(hWnd, wMsg, wParam, lParam);
  1628. case WM_DESTROY:
  1629. MSG("DirWndProc", "WM_DESTROY");
  1630. {
  1631. HANDLE hMem;
  1632. HWND hwnd;
  1633. if (hwndLB == GetFocus())
  1634. if (hwnd = HasTreeWindow(GetParent(hWnd)))
  1635. SetFocus(hwnd);
  1636. if (hMem = (HANDLE)GetWindowLongPtr(hWnd, GWLP_TABARRAY))
  1637. LocalFree(hMem);
  1638. }
  1639. break;
  1640. case WM_CHARTOITEM:
  1641. MSG("DirWndProc", "WM_CHARTOITEM");
  1642. {
  1643. WORD j;
  1644. WORD cItems;
  1645. CHAR ch[2];
  1646. if ((ch[0] = GET_WM_CHARTOITEM_CHAR(wParam, lParam)) <= ' ')
  1647. return(-1L);
  1648. i = GET_WM_CHARTOITEM_POS(wParam, lParam);
  1649. cItems = (WORD)SendMessage(hwndLB, LB_GETCOUNT, 0, 0L);
  1650. szTemp[1] = 0L;
  1651. ch[0] &= 255;
  1652. ch[1] = '\0';
  1653. for (j=1; j <= cItems; j++) {
  1654. SendMessage(hwndLB, LB_GETTEXT, (i + j) % cItems, (LPARAM)&lpmydta);
  1655. szTemp[0] = lpmydta->my_cFileName[0];
  1656. /* Do it this way to be case insensitive. */
  1657. if (!lstrcmpi((LPSTR)ch, szTemp))
  1658. break;
  1659. }
  1660. if (j > cItems)
  1661. return -2L;
  1662. return(MAKELONG((i + j) % cItems, 0));
  1663. }
  1664. case WM_COMPAREITEM:
  1665. MSG("DirWndProc", "WM_COMPAREITEM");
  1666. {
  1667. #define lpci ((LPCOMPAREITEMSTRUCT)lParam)
  1668. return (LONG)CompareDTA((LPMYDTA)lpci->itemData1,
  1669. (LPMYDTA)lpci->itemData2,
  1670. (WORD)GetWindowLong(GetParent(hWnd), GWL_SORT));
  1671. }
  1672. case WM_NCDESTROY:
  1673. MSG("DirWndProc", "WM_NCDESTROY");
  1674. if (hDTA = (HANDLE)GetWindowLongPtr(hWnd, GWLP_HDTA)) {
  1675. LocalFree(hDTA);
  1676. }
  1677. break;
  1678. case WM_DRAGLOOP:
  1679. MSG("DirWndProc", "WM_DRAGDROP");
  1680. /* WM_DRAGLOOP is sent to the source window as the object is moved.
  1681. *
  1682. * wParam: TRUE if the object is currently over a droppable sink
  1683. * lParam: LPDROPSTRUCT
  1684. */
  1685. /* DRAGLOOP is used to turn the source bitmaps on/off as we drag. */
  1686. DSDragLoop(hwndLB, wParam, (LPDROPSTRUCT)lParam, FALSE);
  1687. break;
  1688. case WM_DRAGSELECT:
  1689. MSG("DirWndProc", "WM_DRAGSELECT");
  1690. /* WM_DRAGSELECT is sent to a sink whenever an new object is dragged
  1691. * inside of it.
  1692. *
  1693. * wParam: TRUE if the sink is being entered, FALSE if it's being
  1694. * exited.
  1695. * lParam: LPDROPSTRUCT
  1696. */
  1697. /* DRAGSELECT is used to turn our selection rectangle on or off. */
  1698. #define lpds ((LPDROPSTRUCT)lParam)
  1699. iSelHilite = LOWORD(lpds->dwControlData);
  1700. DSRectItem(hwndLB, iSelHilite, (BOOL)wParam, FALSE);
  1701. break;
  1702. case WM_DRAGMOVE:
  1703. MSG("DirWndProc", "WM_DRAGMOVE");
  1704. /* WM_DRAGMOVE is sent to a sink as the object is being dragged
  1705. * within it.
  1706. *
  1707. * wParam: Unused
  1708. * lParam: LPDROPSTRUCT
  1709. */
  1710. /* DRAGMOVE is used to move our selection rectangle among sub-items. */
  1711. #define lpds ((LPDROPSTRUCT)lParam)
  1712. /* Get the subitem we are over. */
  1713. iSel = LOWORD(lpds->dwControlData);
  1714. /* Is it a new one? */
  1715. if (iSel == iSelHilite)
  1716. break;
  1717. /* Yup, un-select the old item. */
  1718. DSRectItem(hwndLB, iSelHilite, FALSE, FALSE);
  1719. /* Select the new one. */
  1720. iSelHilite = iSel;
  1721. DSRectItem(hwndLB, iSel, TRUE, FALSE);
  1722. break;
  1723. case WM_OWNERDRAWBEGIN:
  1724. #define lpLBItem ((LPDRAWITEMSTRUCT)lParam)
  1725. MSG("DirWndProc", "WM_OWNERDRAWBEGIN");
  1726. /* Set the default bk and text colors. */
  1727. SetTextColor(lpLBItem->hDC, GetSysColor(COLOR_WINDOWTEXT));
  1728. SetBkColor(lpLBItem->hDC, GetSysColor(COLOR_WINDOW));
  1729. #undef lpLBItem
  1730. break;
  1731. case WM_OWNERDRAWEND:
  1732. MSG("DirWndProc", "WM_OWNERDRAWEND");
  1733. break;
  1734. case WM_DRAWITEM:
  1735. #define lpLBItem ((LPDRAWITEMSTRUCT)lParam)
  1736. MSG("DirWndProc", "WM_DRAWITEM");
  1737. {
  1738. WORD wViewFlags;
  1739. LPMYDTA lpmydta;
  1740. /* Don't do anything to empty listboxes. */
  1741. if (lpLBItem->itemID == -1)
  1742. break;
  1743. if (lpLBItem->itemData == (DWORD)0) {
  1744. LoadString(hAppInstance, IDS_NOFILES, szTemp, sizeof(szTemp));
  1745. TextOut(lpLBItem->hDC,
  1746. lpLBItem->rcItem.left,
  1747. lpLBItem->rcItem.top,
  1748. szTemp, lstrlen(szTemp));
  1749. } else {
  1750. lpmydta = (LPMYDTA)lpLBItem->itemData;
  1751. wViewFlags = (WORD)GetWindowLong(GetParent(hWnd), GWL_VIEW);
  1752. if (wViewFlags & VIEW_EVERYTHING) {
  1753. // if any of the wViewFlags bits set, we are in slow mode
  1754. CreateLBLine(wViewFlags, lpmydta, szTemp);
  1755. DrawItem(lpLBItem, szTemp, lpmydta->my_dwAttrs, (HWND)GetFocus()==lpLBItem->hwndItem,
  1756. (WORD *)GetWindowLongPtr(hWnd, GWLP_TABARRAY));
  1757. } else
  1758. DrawItemFast(hWnd, lpLBItem, lpmydta,
  1759. (HWND)GetFocus()==lpLBItem->hwndItem);
  1760. }
  1761. }
  1762. #undef lpLBItem
  1763. break;
  1764. case WM_DROPOBJECT:
  1765. MSG("DirWndProc", "WM_DROPOBJECT");
  1766. {
  1767. WORD ret;
  1768. LPSTR pFrom;
  1769. DWORD dwAttrib = 0; // init this to not a dir
  1770. WORD iSelSink;
  1771. #define lpds ((LPDROPSTRUCT)lParam)
  1772. // Do nothing - but remove selection rectangle
  1773. DSRectItem(hwndLB, iSelHilite, FALSE, FALSE);
  1774. return(TRUE);
  1775. /* WM_DROPOBJECT is sent to a sink when the user releases an
  1776. * acceptable object over it
  1777. *
  1778. * wParam: TRUE if over the non-client area, FALSE if over the
  1779. * client area.
  1780. * lParam: LPDROPSTRUCT
  1781. */
  1782. // this is the listbox index of the destination
  1783. iSelSink = LOWORD(lpds->dwControlData);
  1784. /* Are we dropping onto ourselves? (i.e. a selected item in the
  1785. * source listbox OR an unused area of the source listbox) If
  1786. * so, don't do anything. */
  1787. if (hWnd == lpds->hwndSource) {
  1788. if ((iSelSink == 0xFFFF) || SendMessage(hwndLB, LB_GETSEL, iSelSink, 0L))
  1789. return TRUE;
  1790. }
  1791. // set the destination, assume move/copy case below (c:\foo\)
  1792. SendMessage(hWnd, FS_GETDIRECTORY, sizeof(szTemp), (LPARAM)szTemp);
  1793. // Are we dropping on a unused portion of some listbox?
  1794. if (iSelSink == 0xFFFF)
  1795. goto NormalMoveCopy;
  1796. // check for drop on a directory
  1797. SendMessage(hwndLB, LB_GETTEXT, iSelSink, (LPARAM)&lpmydta);
  1798. lstrcpy(szSourceFile, lpmydta->my_cFileName);
  1799. dwAttrib = lpmydta->my_dwAttrs;
  1800. if (dwAttrib & ATTR_DIR) {
  1801. if (dwAttrib & ATTR_PARENT) { // special case the parent
  1802. StripBackslash(szTemp);
  1803. StripFilespec(szTemp);
  1804. } else {
  1805. lstrcat(szTemp, szSourceFile);
  1806. }
  1807. goto DirMoveCopy;
  1808. }
  1809. // dropping on a program?
  1810. if (!IsProgramFile(szSourceFile))
  1811. goto NormalMoveCopy; // no, normal stuff
  1812. // directory drop on a file? this is a NOP
  1813. if (lpds->wFmt == DOF_DIRECTORY) {
  1814. DSRectItem(hwndLB, iSelHilite, FALSE, FALSE);
  1815. break;
  1816. }
  1817. // We're dropping a file onto a program.
  1818. // Exec the program using the source file as the parameter.
  1819. // set the directory to that of the program to exec
  1820. SendMessage(hWnd, FS_GETDIRECTORY, sizeof(szTemp), (LPARAM)szTemp);
  1821. StripBackslash(szTemp);
  1822. FixAnsiPathForDos(szTemp);
  1823. SheChangeDir(szTemp);
  1824. // get the selected file
  1825. pSel = (LPSTR)SendMessage(lpds->hwndSource, FS_GETSELECTION, TRUE, 0L);
  1826. if (lstrlen(pSel) > MAXPATHLEN) // don't blow up below!
  1827. goto DODone;
  1828. if (bConfirmMouse) {
  1829. LoadString(hAppInstance, IDS_MOUSECONFIRM, szTitle, sizeof(szTitle));
  1830. LoadString(hAppInstance, IDS_EXECMOUSECONFIRM, szTemp, sizeof(szTemp));
  1831. wsprintf(szMessage, szTemp, (LPSTR)szSourceFile, (LPSTR)pSel);
  1832. if (MessageBox(hwndFrame, szMessage, szTitle, MB_YESNO | MB_ICONEXCLAMATION) != IDYES)
  1833. goto DODone;
  1834. }
  1835. // create an absolute path to the argument (search window alaready
  1836. // is absolute)
  1837. if (lpds->hwndSource == hwndSearch) {
  1838. szTemp[0] = 0L;
  1839. } else {
  1840. SendMessage(lpds->hwndSource, FS_GETDIRECTORY, sizeof(szTemp), (LPARAM)szTemp);
  1841. }
  1842. lstrcat(szTemp, pSel); // this is the parameter to the exec
  1843. // put a "." extension on if none found
  1844. if (*GetExtension(szTemp) == 0)
  1845. lstrcat(szTemp, ".");
  1846. FixAnsiPathForDos(szSourceFile);
  1847. FixAnsiPathForDos(szTemp);
  1848. ret = ExecProgram(szSourceFile, szTemp, NULL, FALSE);
  1849. if (ret)
  1850. MyMessageBox(hwndFrame, IDS_EXECERRTITLE, ret, MB_OK | MB_ICONEXCLAMATION | MB_SYSTEMMODAL);
  1851. DODone:
  1852. DSRectItem(hwndLB, iSelHilite, FALSE, FALSE);
  1853. LocalFree((HANDLE)pSel);
  1854. return TRUE;
  1855. NormalMoveCopy:
  1856. /* Make sure that we don't move into same dir. */
  1857. if (GetParent(hWnd) == (HWND)SendMessage(hwndMDIClient, WM_MDIGETACTIVE, 0, 0L))
  1858. return TRUE;
  1859. DirMoveCopy:
  1860. // the source filename is in the loword
  1861. pFrom = (LPSTR)(((LPDRAGOBJECTDATA)(lpds->dwData))->pch);
  1862. // SetSourceDir(lpds);
  1863. AddBackslash(szTemp);
  1864. lstrcat(szTemp, szStarDotStar); // put files in this dir
  1865. CheckEscapes(szTemp);
  1866. ret = DMMoveCopyHelper(pFrom, szTemp, fShowSourceBitmaps);
  1867. DSRectItem(hwndLB, iSelHilite, FALSE, FALSE);
  1868. if (ret)
  1869. return TRUE;
  1870. if (!fShowSourceBitmaps)
  1871. SendMessage(lpds->hwndSource, WM_FILESYSCHANGE, FSC_REFRESH, 0L);
  1872. // we got dropped on, but if this is a dir we don't need to refresh
  1873. if (!(dwAttrib & ATTR_DIR))
  1874. SendMessage(hWnd, WM_FILESYSCHANGE, FSC_REFRESH, 0L);
  1875. return TRUE;
  1876. }
  1877. #if 0
  1878. case WM_GETTEXT:
  1879. MSG("DirWndProc", "WM_GETTEXT");
  1880. {
  1881. HDC hDC;
  1882. RECT rc;
  1883. /* This is where we make sure that the Directory's caption fits
  1884. * inside the caption bar.
  1885. */
  1886. /* Get the full path name. */
  1887. DefWindowProc(hWnd, wMsg, wParam, lParam);
  1888. GetClientRect(hWnd, (LPRECT)&rc);
  1889. hDC = GetDC(hWnd);
  1890. CompactPath(hDC, (LPSTR)lParam, rc.right-rc.left-(dxText * 6));
  1891. ReleaseDC(hWnd, hDC);
  1892. return((LONG)lstrlen((LPSTR)lParam)); /* Don't call DefWindowProc()! */
  1893. }
  1894. #endif
  1895. case WM_LBTRACKPOINT:
  1896. MSG("DirWndProc", "WM_LBTRACKPOINT");
  1897. return DSTrackPoint(hWnd, hwndLB, wParam, lParam, FALSE);
  1898. case WM_MEASUREITEM:
  1899. MSG("DirWndProc", "WM_MEASUREITEM");
  1900. #define pLBMItem ((LPMEASUREITEMSTRUCT)lParam)
  1901. pLBMItem->itemHeight = dyFileName; // the same as in SetLBFont()
  1902. break;
  1903. case WM_QUERYDROPOBJECT:
  1904. MSG("DirWndProc", "WM_QUERYDROPOBJECT");
  1905. // lParam LPDROPSTRUCT
  1906. //
  1907. // return values:
  1908. // 0 don't accept (use ghost buster)
  1909. // 1 accept, use cursor from DragObject()
  1910. // hCursor accept, change to this cursor
  1911. //
  1912. /* Ensure that we are dropping on the client area of the listbox. */
  1913. #define lpds ((LPDROPSTRUCT)lParam)
  1914. /* Ensure that we can accept the format. */
  1915. switch (lpds->wFmt) {
  1916. case DOF_EXECUTABLE:
  1917. case DOF_DIRECTORY:
  1918. case DOF_DOCUMENT:
  1919. case DOF_MULTIPLE:
  1920. if (lpds->hwndSink == hWnd)
  1921. lpds->dwControlData = (DWORD)-1L;
  1922. return (INT_PTR)GetMoveCopyCursor();
  1923. }
  1924. return FALSE;
  1925. case WM_SETFOCUS:
  1926. // Fall through
  1927. case WM_LBUTTONDOWN:
  1928. MSG("DirWndProc", "WM_SETFOCUS/WM_LBUTTONDOWN");
  1929. SetFocus(hwndLB);
  1930. break;
  1931. case WM_COMMAND:
  1932. switch (GET_WM_COMMAND_CMD(wParam, lParam)) {
  1933. case LBN_DBLCLK:
  1934. MSG("DirWndProc", "LBN_DBLCLK");
  1935. /* Double-click... Open the blasted thing. */
  1936. SendMessage(hwndFrame, WM_COMMAND, GET_WM_COMMAND_MPS(IDM_OPEN, 0, 0));
  1937. break;
  1938. case LBN_SELCHANGE:
  1939. MSG("DirWndProc", "LBN_SELCHANGE");
  1940. for (i = 0; i < iNumExtensions; i++) {
  1941. (extensions[i].ExtProc)(hwndFrame, FMEVENT_SELCHANGE, 0L);
  1942. }
  1943. UpdateStatus(GetParent(hWnd));
  1944. break;
  1945. case LBN_SETFOCUS:
  1946. MSG("DirWndProc", "LBN_SETFOCUS");
  1947. // Make sure there are files in this window. If not, set
  1948. // the focus to the tree or drives window. Note: This
  1949. // message was caused by a mouse click and not an
  1950. // accelerator, because these were handled in the window
  1951. // routine that was losing the focus.
  1952. if (SetDirFocus(hWnd)) {
  1953. SetWindowLongPtr(GetParent(hWnd), GWLP_LASTFOCUS, (LPARAM)GET_WM_COMMAND_HWND(wParam, lParam));
  1954. UpdateSelection(GET_WM_COMMAND_HWND(wParam, lParam));
  1955. }
  1956. break;
  1957. case LBN_KILLFOCUS:
  1958. MSG("DirWndProc", "LBN_KILLFOCUS");
  1959. SetWindowLongPtr(GetParent(hWnd), GWLP_LASTFOCUS, 0L);
  1960. UpdateSelection(GET_WM_COMMAND_HWND(wParam, lParam));
  1961. SetWindowLongPtr(GetParent(hWnd), GWLP_LASTFOCUS, (LPARAM)GET_WM_COMMAND_HWND(wParam, lParam));
  1962. break;
  1963. }
  1964. break;
  1965. case WM_VKEYTOITEM:
  1966. MSG("DirWndProc", "WM_VKEYTOITEM");
  1967. switch (GET_WM_VKEYTOITEM_ITEM(wParam, lParam)) {
  1968. case VK_ESCAPE:
  1969. bCancelTree = TRUE;
  1970. return -2L;
  1971. case 0xBF: /* Ctrl-/ */
  1972. SendMessage(hwndFrame, WM_COMMAND, GET_WM_COMMAND_MPS(IDM_SELALL, 0, 0));
  1973. return -2;
  1974. case 0xDC: /* Ctrl-\ */
  1975. SendMessage(hwndFrame, WM_COMMAND, GET_WM_COMMAND_MPS(IDM_DESELALL, 0, 0));
  1976. return -2;
  1977. case VK_F6: // like excel
  1978. case VK_TAB:
  1979. {
  1980. HWND hwndTree, hwndDrives;
  1981. GetTreeWindows(GetParent(hWnd), &hwndTree, NULL, &hwndDrives);
  1982. if (GetKeyState(VK_SHIFT) < 0)
  1983. SetFocus(hwndTree ? hwndTree : hwndDrives);
  1984. else
  1985. SetFocus(hwndDrives);
  1986. break;
  1987. }
  1988. case VK_BACK:
  1989. SendMessage(hWnd, FS_GETDIRECTORY, sizeof(szTemp), (LPARAM)szTemp);
  1990. // are we already at the root?
  1991. if (lstrlen(szTemp) <= 3)
  1992. return -1;
  1993. StripBackslash(szTemp);
  1994. StripFilespec(szTemp);
  1995. CreateDirWindow(szTemp, TRUE, GetParent(hWnd));
  1996. return -2;
  1997. default:
  1998. {
  1999. HWND hwndDrives;
  2000. // check for Ctrl-[DRIVE LETTER] and pass on to drives
  2001. // window
  2002. if ((GetKeyState(VK_CONTROL) < 0) && (hwndDrives = HasDrivesWindow(GetParent(hWnd)))) {
  2003. return SendMessage(hwndDrives, wMsg, wParam, lParam);
  2004. }
  2005. break;
  2006. }
  2007. }
  2008. return -1;
  2009. case WM_SIZE:
  2010. MSG("DirWndProc", "WM_SIZE");
  2011. if (!IsIconic(GetParent(hWnd))) {
  2012. INT iMax;
  2013. MoveWindow(hwndLB, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);
  2014. iMax = (INT)SendMessage(hwndLB, LB_GETCARETINDEX, 0, 0L);
  2015. if (iMax >= 0) // scroll item into view
  2016. /* SETCARETINDEX will scroll item into view */
  2017. SendMessage(hwndLB, LB_SETCARETINDEX, iMax, 0L);
  2018. //MakeItemVisible(iMax, hwndLB);
  2019. }
  2020. break;
  2021. default:
  2022. DEFMSG("DirWndProc", (WORD)wMsg);
  2023. return DefWindowProc(hWnd, wMsg, wParam, lParam);
  2024. }
  2025. return 0L;
  2026. }
  2027. VOID
  2028. SortDirList(
  2029. HWND hWnd,
  2030. LPMYDTA lpmydta,
  2031. WORD count,
  2032. LPMYDTA *lplpmydta
  2033. )
  2034. {
  2035. INT i, j;
  2036. WORD wSort;
  2037. INT iMax, iMin, iMid;
  2038. wSort = (WORD)GetWindowLong(GetParent(GetParent(hWnd)), GWL_SORT);
  2039. for (i = 0; i < (INT)count; i++) {
  2040. // advance to next
  2041. lpmydta = GETDTAPTR(lpmydta, lpmydta->wSize);
  2042. if (i == 0) {
  2043. lplpmydta[i] = lpmydta;
  2044. } else {
  2045. // do a binary insert
  2046. iMin = 0;
  2047. iMax = i-1; // last index
  2048. do {
  2049. iMid = (iMax + iMin) / 2;
  2050. if (CompareDTA(lpmydta, lplpmydta[iMid], wSort) > 0)
  2051. iMin = iMid + 1;
  2052. else
  2053. iMax = iMid - 1;
  2054. } while (iMax > iMin);
  2055. if (iMax < 0)
  2056. iMax = 0;
  2057. if (CompareDTA(lpmydta, lplpmydta[iMax], wSort) > 0)
  2058. iMax++; // insert after this one
  2059. if (i != iMax) {
  2060. for (j = i; j > iMax; j--)
  2061. lplpmydta[j] = lplpmydta[j-1];
  2062. }
  2063. lplpmydta[iMax] = lpmydta;
  2064. }
  2065. }
  2066. }
  2067. BOOL
  2068. SetDirFocus(
  2069. HWND hwndDir
  2070. )
  2071. /*
  2072. Set the focus to whoever deserves it if not the directory window.
  2073. Return whether focus needs to be set to directory window.
  2074. */
  2075. {
  2076. DWORD dwTemp;
  2077. HWND hwndLB = GetDlgItem(hwndDir, IDCW_LISTBOX);
  2078. SendMessage (hwndLB,LB_GETTEXT,0,(LPARAM) &dwTemp);
  2079. if (!dwTemp) {
  2080. HWND hwndFocus,hwndTree,hwndDrives,hwndParent = GetParent(hwndDir);
  2081. GetTreeWindows(hwndParent,&hwndTree,NULL,&hwndDrives);
  2082. if ((hwndFocus = GetTreeFocus(hwndParent)) == hwndDir)
  2083. SetFocus(hwndTree ? hwndTree : hwndDrives);
  2084. else
  2085. SetFocus(hwndFocus);
  2086. return FALSE;
  2087. } else
  2088. return TRUE;
  2089. }