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.

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