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.

767 lines
22 KiB

  1. #ifndef WIN32_LEAN_AND_MEAN
  2. #define WIN32_LEAN_AND_MEAN
  3. #endif
  4. #include <windows.h>
  5. #include "plv_.h"
  6. #include "plv.h"
  7. #include "dbg.h"
  8. #include "iconview.h"
  9. #include "ivmisc.h"
  10. #include "exgdiw.h"
  11. #include "exres.h"
  12. #ifdef UNDER_CE // Windows CE specific
  13. #include "stub_ce.h" // Windows CE stub for unsupported APIs
  14. #endif // UNDER_CE
  15. static POSVERSIONINFO ExGetOSVersion(VOID)
  16. {
  17. static BOOL fFirst = TRUE;
  18. static OSVERSIONINFO os;
  19. if ( fFirst ) {
  20. os.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  21. if (GetVersionEx( &os ) ) {
  22. fFirst = FALSE;
  23. }
  24. }
  25. return &os;
  26. }
  27. static BOOL ExIsWinNT(VOID)
  28. {
  29. BOOL fBool;
  30. fBool = (ExGetOSVersion()->dwPlatformId == VER_PLATFORM_WIN32_NT);
  31. return fBool;
  32. }
  33. #define IV_EDGET_NONE 0
  34. #define IV_EDGET_RAISED 1
  35. #define IV_EDGET_SUNKEN 2
  36. //////////////////////////////////////////////////////////////////
  37. // Function : RepView_RestoreScrollPos
  38. // Type : INT
  39. // Purpose :
  40. // Args :
  41. // : LPPLVDATA lpPlvData
  42. // Return :
  43. // DATE :
  44. //////////////////////////////////////////////////////////////////
  45. INT IconView_RestoreScrollPos(LPPLVDATA lpPlvData)
  46. {
  47. return IV_SetCurScrollPos(lpPlvData->hwndSelf, lpPlvData->nCurIconScrollPos);
  48. }
  49. //////////////////////////////////////////////////////////////////
  50. // Function : IconView_ResetScrollRange
  51. // Type : INT
  52. // Purpose : Reset scroll bar's range,
  53. // : if PadListView size was changed.
  54. // Args :
  55. // : LPPLVDATA lpPlvData
  56. // Return :
  57. // DATE : 970829
  58. //////////////////////////////////////////////////////////////////
  59. INT IconView_ResetScrollRange(LPPLVDATA lpPlvData)
  60. {
  61. static SCROLLINFO scrInfo;
  62. HWND hwnd = lpPlvData->hwndSelf;
  63. INT nRow = IV_GetRow(hwnd);
  64. INT nCol = IV_GetCol(hwnd);
  65. INT nMax = IV_GetMaxLine(hwnd);
  66. INT nPos = lpPlvData->nCurIconScrollPos;
  67. //----------------------------------------------------------------
  68. //important:
  69. //calc new cur top index
  70. //----------------------------------------------------------------
  71. lpPlvData->iCurIconTopIndex = nCol * nPos; //changed 970707
  72. scrInfo.cbSize = sizeof(scrInfo);
  73. scrInfo.fMask = SIF_PAGE | SIF_POS | SIF_RANGE;
  74. scrInfo.nMin = 0;
  75. scrInfo.nMax = nMax-1;
  76. scrInfo.nPage = nRow;
  77. scrInfo.nPos = nPos;
  78. scrInfo.nTrackPos = 0;
  79. //In normal case,
  80. //if (scrInfo.nMax - scrInfo.nMin + 1) <= scrInfo.nPage,
  81. // scroll bar is hidden. to prevent it,
  82. // in this case, set proper page, and DISABLE scrollbar.
  83. // Now we can show scroll bar always
  84. if((scrInfo.nMax - scrInfo.nMin +1) <= (INT)scrInfo.nPage) {
  85. scrInfo.nMin = 0;
  86. scrInfo.nMax = 1;
  87. scrInfo.nPage = 1;
  88. #ifndef UNDER_CE // Windows CE does not support EnableScrollBar
  89. SetScrollInfo(hwnd, SB_VERT, &scrInfo, TRUE);
  90. EnableScrollBar(hwnd, SB_VERT, ESB_DISABLE_BOTH);
  91. #else // UNDER_CE
  92. scrInfo.fMask |= SIF_DISABLENOSCROLL;
  93. SetScrollInfo(hwnd, SB_VERT, &scrInfo, TRUE);
  94. #endif // UNDER_CE
  95. }
  96. else {
  97. #ifndef UNDER_CE // Windows CE does not support EnableScrollBar
  98. EnableScrollBar(hwnd, SB_VERT, ESB_ENABLE_BOTH);
  99. #endif // UNDER_CE
  100. SetScrollInfo(hwnd, SB_VERT, &scrInfo, TRUE);
  101. }
  102. return 0;
  103. }
  104. //////////////////////////////////////////////////////////////////
  105. // Function : IconView_SetItemCount
  106. // Type : INT
  107. // Purpose :
  108. // Args :
  109. // : LPPLVDATA lpPlvData
  110. // : INT itemCount
  111. // : BOOL fDraw update scroll bar or not
  112. // Return :
  113. // DATE :
  114. //////////////////////////////////////////////////////////////////
  115. INT IconView_SetItemCount(LPPLVDATA lpPlvData, INT itemCount, BOOL fDraw)
  116. {
  117. //Dbg(("IconView_SetItemCount [%d]\n", itemCount));
  118. lpPlvData->iItemCount = itemCount;
  119. lpPlvData->nCurIconScrollPos = 0; //970707 ToshiaK, same as iCurTopIndex
  120. lpPlvData->iCurIconTopIndex = 0; //970707 ToshiaK, same as iCurTopIndex
  121. if(fDraw) {
  122. INT nMaxLine = IV_GetMaxLine(lpPlvData->hwndSelf);
  123. INT nPage = IV_GetRow(lpPlvData->hwndSelf);
  124. IV_SetScrollInfo(lpPlvData->hwndSelf, 0, nMaxLine, nPage, 0);
  125. }
  126. return 0;
  127. }
  128. INT IconView_SetTopIndex(LPPLVDATA lpPlvData, INT indexTop)
  129. {
  130. INT nCol = IV_GetCol(lpPlvData->hwndSelf);
  131. if(nCol <=0) {
  132. Dbg(("Internal ERROR Colmn 0\n"));
  133. return 0;
  134. }
  135. if(indexTop < lpPlvData->iItemCount) {
  136. lpPlvData->iCurIconTopIndex = (indexTop/nCol) * nCol;
  137. IV_SetCurScrollPos(lpPlvData->hwndSelf,
  138. lpPlvData->iCurIconTopIndex/nCol);
  139. InvalidateRect(lpPlvData->hwndSelf, NULL, TRUE);
  140. UpdateWindow(lpPlvData->hwndSelf);
  141. return indexTop;
  142. }
  143. else {
  144. Dbg(("Internal ERROR\n"));
  145. return -1;
  146. }
  147. }
  148. INT IconView_Paint(HWND hwnd, WPARAM wParam, LPARAM lParam)
  149. {
  150. static PAINTSTRUCT ps;
  151. static RECT rc;
  152. static HBRUSH hBrush;
  153. static HDC hDCMem;
  154. static HDC hDC;
  155. static HBITMAP hBitmap, hBitmapPrev;
  156. static DWORD dwOldTextColor, dwOldBkColor;
  157. static INT i, j;
  158. //Dbg(("IconView_Paint START\n"));
  159. hDC = BeginPaint(hwnd, &ps);
  160. LPPLVDATA lpPlvData = GetPlvDataFromHWND(hwnd);
  161. GetClientRect(hwnd, &rc);
  162. hDCMem = CreateCompatibleDC(hDC);
  163. hBitmap = CreateCompatibleBitmap(hDC, rc.right - rc.left, rc.bottom-rc.top);
  164. hBitmapPrev = (HBITMAP)SelectObject(hDCMem, hBitmap);
  165. //----------------------------------------------------------------
  166. //971111: #2586
  167. //----------------------------------------------------------------
  168. //hBrush = CreateSolidBrush(GetSysColor(COLOR_3DFACE));
  169. //dwOldBkColor = SetBkColor(hDCMem, GetSysColor(COLOR_3DFACE));
  170. hBrush = CreateSolidBrush(GetSysColor(COLOR_WINDOW));
  171. dwOldBkColor = SetBkColor(hDCMem, GetSysColor(COLOR_WINDOW));
  172. dwOldTextColor = SetTextColor(hDCMem, GetSysColor(COLOR_WINDOWTEXT));
  173. FillRect(hDCMem, &rc, hBrush);
  174. INT nRow = IV_GetRow(hwnd);
  175. INT nCol = IV_GetCol(hwnd);
  176. INT nMetricsCount;
  177. nMetricsCount = (nRow+1) * nCol;
  178. INT x, y;
  179. RECT rcChar;
  180. HFONT hFontOld = NULL;
  181. if(lpPlvData->hFontIcon) {
  182. hFontOld = (HFONT)SelectObject(hDCMem, lpPlvData->hFontIcon);
  183. }
  184. INT nItemWidth = IV_GetItemWidth(hwnd);
  185. INT nItemHeight = IV_GetItemHeight(hwnd);
  186. INT iCurIconTopIndex;
  187. //----------------------------------------------------------------
  188. //error no call back exists
  189. if(!lpPlvData->lpfnPlvIconItemCallback) {
  190. Dbg(("Call back does not exists\n"));
  191. goto LError;
  192. }
  193. if(nCol <=0 ){
  194. Dbg(("Column count is less than zero\n"));
  195. goto LError;
  196. }
  197. //Dbg(("Call back exist\n"));
  198. static PLVITEM plvItemTmp, plvItem;
  199. POINT pt;
  200. #ifndef UNDER_CE // Windows CE does not support GetCursorPos.
  201. GetCursorPos(&pt);
  202. ScreenToClient(hwnd, &pt);
  203. #else // UNDER_CE
  204. if(lpPlvData->iCapture != CAPTURE_NONE){
  205. pt.x = lpPlvData->ptCapture.x;
  206. pt.y = lpPlvData->ptCapture.y;
  207. }
  208. else{
  209. // set outer client point
  210. pt.x = -1;
  211. pt.y = -1;
  212. }
  213. #endif // UNDER_CE
  214. //Dbg(("iCurIconTopIndex [%d]\n", lpPlvData->iCurIconTopIndex));
  215. //Dbg(("iItemCount [%d]\n", lpPlvData->iItemCount));
  216. //----------------------------------------------------------------
  217. //970707 toshiak changed.
  218. //iCurIconTopIndex shold be a muliple of nCol;
  219. //----------------------------------------------------------------
  220. iCurIconTopIndex = (lpPlvData->iCurIconTopIndex / nCol) * nCol;
  221. for(i = 0, j = iCurIconTopIndex;
  222. i < nMetricsCount && j < lpPlvData->iItemCount;
  223. i++, j++) {
  224. x = IV_GetXMargin(hwnd) + nItemWidth * (i % nCol);
  225. y = IV_GetYMargin(hwnd) + nItemHeight * (i / nCol);
  226. rcChar.left = rc.left + x;
  227. rcChar.top = rc.top + y;
  228. rcChar.right = rcChar.left + nItemWidth;
  229. rcChar.bottom= rcChar.top + nItemHeight;
  230. if(rcChar.top > rc.bottom) {
  231. break;
  232. }
  233. plvItem = plvItemTmp;
  234. lpPlvData->lpfnPlvIconItemCallback(lpPlvData->iconItemCallbacklParam,
  235. j,
  236. &plvItem);
  237. if(plvItem.lpwstr) {
  238. INT edgeFlag;
  239. if(lpPlvData->iCapture == CAPTURE_LBUTTON) {
  240. if(PtInRect(&rcChar, lpPlvData->ptCapture) &&
  241. PtInRect(&rcChar, pt)) {
  242. edgeFlag = IV_EDGET_SUNKEN;
  243. }
  244. else {
  245. edgeFlag = IV_EDGET_NONE;
  246. }
  247. }
  248. else {
  249. if(PtInRect(&rcChar, pt)) {
  250. edgeFlag = IV_EDGET_RAISED;
  251. }
  252. else {
  253. edgeFlag = IV_EDGET_NONE;
  254. }
  255. }
  256. INT sunken = 0;
  257. switch(edgeFlag) {
  258. case IV_EDGET_SUNKEN:
  259. sunken = 1;
  260. DrawEdge(hDCMem, &rcChar, EDGE_SUNKEN, BF_SOFT | BF_RECT);
  261. break;
  262. case IV_EDGET_RAISED:
  263. sunken = 0;
  264. DrawEdge(hDCMem, &rcChar, EDGE_RAISED, BF_SOFT | BF_RECT);
  265. break;
  266. case IV_EDGET_NONE:
  267. default:
  268. break;
  269. }
  270. SIZE size;
  271. if(ExGetTextExtentPoint32W(hDCMem, plvItem.lpwstr, 1, &size)) {
  272. ExExtTextOutW(hDCMem,
  273. rcChar.left + (nItemWidth - size.cx)/2 + sunken,
  274. rcChar.top + (nItemHeight - size.cy)/2 + sunken,
  275. ETO_CLIPPED,
  276. &rcChar,
  277. plvItem.lpwstr,
  278. 1,
  279. NULL);
  280. }
  281. }
  282. }
  283. LError:
  284. if(hFontOld){
  285. SelectObject(hDCMem, hFontOld);
  286. }
  287. // LIZHANG: if there is no items, draw the explanation text
  288. if ( !lpPlvData->iItemCount && (lpPlvData->lpText || lpPlvData->lpwText ))
  289. {
  290. HFONT hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
  291. HFONT hOldFont = (HFONT)SelectObject( hDCMem, hFont );
  292. RECT rcTmp = rc;
  293. rcTmp.left = 20;
  294. rcTmp.top = 20;
  295. rcTmp.right -= 10;
  296. rcTmp.bottom -= 10;
  297. //COLORREF colOld = SetTextColor( hDCMem, GetSysColor(COLOR_WINDOW) );
  298. //COLORREF colBkOld = SetBkColor( hDCMem, GetSysColor(COLOR_3DFACE) );
  299. COLORREF colOld = SetTextColor( hDCMem, GetSysColor(COLOR_WINDOWTEXT));
  300. COLORREF colBkOld = SetBkColor( hDCMem, GetSysColor(COLOR_WINDOW) );
  301. #ifndef UNDER_CE // always Unicode
  302. if(ExIsWinNT()) {
  303. if(lpPlvData->lpwText) {
  304. DrawTextW(hDCMem,
  305. lpPlvData->lpwText,
  306. lstrlenW(lpPlvData->lpwText),
  307. &rcTmp,
  308. DT_VCENTER|DT_WORDBREAK );
  309. }
  310. }
  311. else {
  312. DrawText( hDCMem,
  313. lpPlvData->lpText,
  314. lstrlen(lpPlvData->lpText),
  315. &rcTmp,
  316. DT_VCENTER|DT_WORDBREAK );
  317. }
  318. #else // UNDER_CE
  319. if(lpPlvData->lpwText) {
  320. DrawTextW(hDCMem,
  321. lpPlvData->lpwText,
  322. lstrlenW(lpPlvData->lpwText),
  323. &rcTmp,
  324. DT_VCENTER|DT_WORDBREAK );
  325. }
  326. #endif // UNDER_CE
  327. SetTextColor( hDCMem, colOld );
  328. SetBkColor( hDCMem, colBkOld );
  329. SelectObject( hDCMem, hOldFont );
  330. }
  331. BitBlt(hDC, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top,
  332. hDCMem, 0, 0, SRCCOPY);
  333. DeleteObject(hBrush);
  334. SetBkColor(hDCMem, dwOldBkColor);
  335. SetTextColor(hDCMem, dwOldTextColor);
  336. SelectObject(hDCMem, hBitmapPrev );
  337. DeleteObject(hBitmap);
  338. DeleteDC( hDCMem );
  339. EndPaint(hwnd, &ps);
  340. return 0;
  341. Unref3(hwnd, wParam, lParam);
  342. }
  343. INT IconView_ButtonDown(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  344. {
  345. LPPLVDATA lpPlvData = GetPlvDataFromHWND(hwnd);
  346. if(!lpPlvData) {
  347. Dbg(("Internal ERROR\n"));
  348. return 0;
  349. }
  350. switch(uMsg) {
  351. case WM_LBUTTONDOWN:
  352. case WM_MBUTTONDOWN:
  353. case WM_RBUTTONDOWN:
  354. case WM_LBUTTONDBLCLK:
  355. case WM_MBUTTONDBLCLK:
  356. case WM_RBUTTONDBLCLK:
  357. SetCapture(hwnd);
  358. #ifdef UNDER_CE // LBUTTON + ALT key handling
  359. //Standard way for RBUTTON handling is combination w/ LBUTTON + ALT key
  360. if(uMsg == WM_LBUTTONDOWN && GetAsyncKeyState(VK_MENU)){
  361. uMsg = WM_RBUTTONDOWN;
  362. }
  363. #endif // UNDER_CE
  364. switch(uMsg) {
  365. case WM_LBUTTONDOWN:
  366. case WM_LBUTTONDBLCLK:
  367. lpPlvData->iCapture = CAPTURE_LBUTTON;
  368. break;
  369. case WM_MBUTTONDOWN:
  370. case WM_MBUTTONDBLCLK:
  371. lpPlvData->iCapture = CAPTURE_MBUTTON;
  372. break;
  373. case WM_RBUTTONDOWN:
  374. case WM_RBUTTONDBLCLK:
  375. lpPlvData->iCapture = CAPTURE_RBUTTON;
  376. break;
  377. }
  378. #ifndef UNDER_CE // Windows CE does not support GetCursorPos.
  379. GetCursorPos(&lpPlvData->ptCapture);
  380. //remember left button down place
  381. ScreenToClient(hwnd, &lpPlvData->ptCapture);
  382. #else // UNDER_CE
  383. lpPlvData->ptCapture.x = (SHORT)LOWORD(lParam);
  384. lpPlvData->ptCapture.y = (SHORT)HIWORD(lParam);
  385. #endif // UNDER_CE
  386. switch(uMsg) {
  387. case WM_LBUTTONDOWN:
  388. case WM_LBUTTONDBLCLK:
  389. InvalidateRect(hwnd, NULL, FALSE);
  390. break;
  391. }
  392. #ifdef UNDER_CE // Windows CE used ButtonDown Event for ToolTip
  393. if(lpPlvData->uMsg != 0) {
  394. if(uMsg == WM_LBUTTONDOWN) {
  395. PLVINFO plvInfo;
  396. INT index = IV_GetInfoFromPoint(lpPlvData,
  397. lpPlvData->ptCapture,
  398. &plvInfo);
  399. plvInfo.code = PLVN_ITEMDOWN;
  400. SendMessage(GetParent(hwnd), lpPlvData->uMsg, 0, (LPARAM)&plvInfo);
  401. }
  402. }
  403. #endif // UNDER_CE
  404. break;
  405. }
  406. return 0;
  407. Unref2(wParam, lParam);
  408. }
  409. INT IconView_ButtonUp(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  410. {
  411. LPPLVDATA lpPlvData = GetPlvDataFromHWND(hwnd);
  412. static POINT pt;
  413. static PLVINFO plvInfo;
  414. static INT index, downIndex;
  415. if(!lpPlvData) {
  416. Dbg(("Internal ERROR\n"));
  417. return 0;
  418. }
  419. switch(uMsg) {
  420. case WM_MBUTTONUP:
  421. case WM_LBUTTONUP:
  422. case WM_RBUTTONUP:
  423. Dbg(("WM_LBUTTONUP COMES\n"));
  424. #ifdef UNDER_CE // LBUTTON + ALT key handling
  425. //Standard way for RBUTTON handling is combination w/ LBUTTON + ALT key
  426. if(uMsg == WM_LBUTTONUP && GetAsyncKeyState(VK_MENU)){
  427. uMsg = WM_RBUTTONUP;
  428. }
  429. #endif // UNDER_CE
  430. InvalidateRect(hwnd, NULL, FALSE);
  431. pt.x = LOWORD(lParam);
  432. pt.y = HIWORD(lParam);
  433. #if 0
  434. Dbg(("x %d, y %d\n", pt.x, pt.y));
  435. Dbg(("capture x[%d] y[%d] \n",
  436. lpPlvData->ptCapture.x,
  437. lpPlvData->ptCapture.y));
  438. #endif
  439. downIndex = IV_GetInfoFromPoint(lpPlvData, lpPlvData->ptCapture, NULL);
  440. index = IV_GetInfoFromPoint(lpPlvData, pt, &plvInfo);
  441. ReleaseCapture();
  442. #if 0
  443. Dbg(("mouse down index [%d]\n", downIndex));
  444. Dbg(("mouse up index [%d]\n", index));
  445. #endif
  446. if(index != -1) {
  447. Dbg(("code [%d]\n", plvInfo.code));
  448. Dbg(("index [%d]\n", plvInfo.index));
  449. Dbg(("left[%d] top[%d] right[%d] bottom[%d] \n",
  450. plvInfo.itemRect.left,
  451. plvInfo.itemRect.top,
  452. plvInfo.itemRect.right,
  453. plvInfo.itemRect.bottom));
  454. if(index == downIndex) {
  455. if(lpPlvData->uMsg != 0) {
  456. if(uMsg == WM_LBUTTONUP) {
  457. plvInfo.code = PLVN_ITEMCLICKED;
  458. SendMessage(GetParent(hwnd), lpPlvData->uMsg, index, (LPARAM)&plvInfo);
  459. }
  460. else if(uMsg == WM_RBUTTONUP) {
  461. plvInfo.code = PLVN_R_ITEMCLICKED;
  462. SendMessage(GetParent(hwnd), lpPlvData->uMsg, index, (LPARAM)&plvInfo);
  463. }
  464. }
  465. }
  466. }
  467. #ifdef UNDER_CE // Windows CE used ButtonUp Event for ToolTip
  468. if(lpPlvData->uMsg != 0) {
  469. if(uMsg == WM_LBUTTONUP) {
  470. PLVINFO plvInfo;
  471. INT index = IV_GetInfoFromPoint(lpPlvData,
  472. lpPlvData->ptCapture,
  473. &plvInfo);
  474. plvInfo.code = PLVN_ITEMUP;
  475. SendMessage(GetParent(hwnd), lpPlvData->uMsg, 0, (LPARAM)&plvInfo);
  476. }
  477. }
  478. #endif // UNDER_CE
  479. lpPlvData->iCapture = CAPTURE_NONE;
  480. lpPlvData->ptCapture.x = 0;
  481. lpPlvData->ptCapture.y = 0;
  482. break;
  483. }
  484. return 0;
  485. Unref(wParam);
  486. }
  487. INT IconView_MouseMove(HWND hwnd, WPARAM wParam, LPARAM lParam)
  488. {
  489. LPPLVDATA lpPlvData = GetPlvDataFromHWND(hwnd);
  490. if(!lpPlvData) {
  491. Dbg(("Internal ERROR\n"));
  492. return 0;
  493. }
  494. static POINT pt;
  495. static PLVINFO plvInfo;
  496. pt.x = LOWORD(lParam);
  497. pt.y = HIWORD(lParam);
  498. //Dbg(("x %d, y %d\n", pt.x, pt.y));
  499. INT index = IV_GetInfoFromPoint(lpPlvData, pt, &plvInfo);
  500. //Dbg(("mouse up index [%d]\n", index));
  501. InvalidateRect(hwnd, NULL, NULL);
  502. //----------------------------------------------------------------
  503. //970929:
  504. //if(index != -1 && !lpPlvData->fCapture) {
  505. //----------------------------------------------------------------
  506. if(index != -1 && (lpPlvData->iCapture == CAPTURE_NONE)) {
  507. #if 0
  508. Dbg(("style [%d]\n", plvInfo.style));
  509. Dbg(("code [%d]\n", plvInfo.code));
  510. Dbg(("index [%d]\n", plvInfo.index));
  511. Dbg(("left[%d] top[%d] right[%d] bottom[%d] \n",
  512. plvInfo.itemRect.left,
  513. plvInfo.itemRect.top,
  514. plvInfo.itemRect.right,
  515. plvInfo.itemRect.bottom));
  516. #endif
  517. if(lpPlvData->uMsg != 0) {
  518. plvInfo.code = PLVN_ITEMPOPED;
  519. SendMessage(GetParent(hwnd), lpPlvData->uMsg, 0, (LPARAM)&plvInfo);
  520. #ifdef MSAA
  521. static oldindex = 0;
  522. index++; // convert to 1 origin child id
  523. if((index > 0)&&(index != oldindex)) {
  524. PLV_NotifyWinEvent(lpPlvData,
  525. EVENT_OBJECT_FOCUS,
  526. hwnd,
  527. OBJID_CLIENT,
  528. index); // child id
  529. oldindex = index;
  530. }
  531. #endif
  532. }
  533. }
  534. return 0;
  535. Unref(wParam);
  536. }
  537. //////////////////////////////////////////////////////////////////
  538. // Function : IconView_VScroll
  539. // Type : INT
  540. // Purpose :
  541. // Args :
  542. // : HWND hwnd
  543. // : WPARAM wParam
  544. // : LPARAM lParam
  545. // Return :
  546. // DATE :
  547. //////////////////////////////////////////////////////////////////
  548. INT IconView_VScroll(HWND hwnd, WPARAM wParam, LPARAM lParam)
  549. {
  550. //----------------------------------------------------------------
  551. // get current top index.
  552. // calc scroll position.
  553. // get new top index and set it.
  554. // redraw window rectangle.
  555. //----------------------------------------------------------------
  556. INT nScrollCode = (int) LOWORD(wParam); // scroll bar value
  557. #ifdef _DEBUG
  558. INT nArgPos = (short int) HIWORD(wParam); // scroll box position
  559. #endif
  560. //HWND hwndScrollBar = (HWND) lParam; // handle of scroll bar
  561. INT nPos;
  562. INT nRow, nCol, nMax;
  563. switch(nScrollCode) {
  564. case SB_LINEDOWN:
  565. Dbg(("SB_LINEDOWN COME nArgPos[%d]\n", nArgPos));
  566. nRow = IV_GetRow(hwnd);
  567. nMax = IV_GetMaxLine(hwnd);
  568. nPos = IV_GetCurScrollPos(hwnd);
  569. if(nPos + nRow > nMax - 1) {
  570. return 0;
  571. }
  572. nPos++;
  573. IV_SetCurScrollPos(hwnd, nPos);
  574. break;
  575. case SB_LINEUP:
  576. Dbg(("SB_LINEUP COME nArgPos[%d]\n", nArgPos));
  577. IV_GetRowColumn(hwnd, &nRow, &nCol);
  578. nPos = IV_GetCurScrollPos(hwnd);
  579. if(nPos <= 0) {
  580. return 0;
  581. }
  582. nPos--;
  583. IV_SetCurScrollPos(hwnd, nPos);
  584. break;
  585. case SB_PAGEDOWN:
  586. Dbg(("SB_PAGEDOWN COME nArgPos[%d]\n", nArgPos));
  587. IV_GetRowColumn(hwnd, &nRow, &nCol);
  588. nMax = IV_GetMaxLine(hwnd);
  589. nPos = IV_GetCurScrollPos(hwnd);
  590. Dbg(("nMax [%d] nPos %d nRow[%d] nCol[%d]\n", nMax, nPos, nRow, nCol));
  591. nPos = min(nPos+nRow, nMax - nRow);
  592. Dbg(("-->nPos [%d] \n", nPos));
  593. IV_SetCurScrollPos(hwnd, nPos);
  594. break;
  595. case SB_PAGEUP: //Track�̏オ�N���b�N���ꂽ
  596. Dbg(("SB_PAGEUP COME nArgPos[%d]\n", nArgPos));
  597. IV_GetRowColumn(hwnd, &nRow, &nCol);
  598. nPos = IV_GetCurScrollPos(hwnd);
  599. nPos = max(0, nPos - nRow);
  600. IV_SetCurScrollPos(hwnd, nPos);
  601. break;
  602. case SB_TOP:
  603. Dbg(("SB_TOP COME nArgPos[%d]\n", nArgPos));
  604. break;
  605. case SB_BOTTOM:
  606. Dbg(("SB_BOTTOM COME nArgPos[%d]\n", nArgPos));
  607. break;
  608. case SB_THUMBTRACK: //Track��Drag��
  609. Dbg(("SB_THUMBTRACK COME nArgPos[%d]\n", nArgPos));
  610. nPos = IV_GetScrollTrackPos(hwnd);
  611. //Dbg(("Current Pos %d\n", nPos));
  612. IV_GetRowColumn(hwnd, &nRow, &nCol);
  613. IV_SetCurScrollPos(hwnd, nPos);
  614. break;
  615. case SB_THUMBPOSITION: //Scroll Bar��Drag���I������
  616. Dbg(("SB_THUMBPOSITION COME nArgPos[%d]\n", nArgPos));
  617. nPos = IV_GetScrollTrackPos(hwnd);
  618. Dbg(("Current Pos %d\n", nPos));
  619. IV_GetRowColumn(hwnd, &nRow, &nCol);
  620. IV_SetCurScrollPos(hwnd, nPos);
  621. break;
  622. case SB_ENDSCROLL:
  623. Dbg(("SB_ENDSCROLL COME nArgPos[%d]\n", nArgPos));
  624. break;
  625. }
  626. InvalidateRect(hwnd, NULL, FALSE);
  627. return 0;
  628. Unref3(hwnd, wParam, lParam);
  629. }
  630. INT IconView_SetCurSel(LPPLVDATA lpPlvData, INT index)
  631. {
  632. INT i, j;
  633. HWND hwnd;
  634. //Dbg(("IconView_SetCurSel Index [%d][0x%08x]START\n", index, index));
  635. hwnd = lpPlvData->hwndSelf;
  636. RECT rc;
  637. GetClientRect(hwnd, &rc);
  638. INT nRow = IV_GetRow(hwnd);
  639. INT nCol = IV_GetCol(hwnd);
  640. if(nCol <= 0) {
  641. return 0;
  642. }
  643. INT nMetricsCount;
  644. nMetricsCount = (nRow+1) * nCol;
  645. INT x, y;
  646. RECT rcChar;
  647. INT nItemWidth = IV_GetItemWidth(hwnd);
  648. INT nItemHeight = IV_GetItemHeight(hwnd);
  649. INT iCurIconTopIndex;
  650. static PLVITEM plvItemTmp, plvItem;
  651. POINT pt;
  652. iCurIconTopIndex = (lpPlvData->iCurIconTopIndex / nCol) * nCol;
  653. for(i = 0, j = iCurIconTopIndex;
  654. i < nMetricsCount && j < lpPlvData->iItemCount;
  655. i++, j++) {
  656. if(index == j) {
  657. x = IV_GetXMargin(hwnd) + nItemWidth * (i % nCol);
  658. y = IV_GetYMargin(hwnd) + nItemHeight * (i / nCol);
  659. rcChar.left = rc.left + x;
  660. rcChar.top = rc.top + y;
  661. pt.x = rcChar.left + (nItemWidth * 3)/4;
  662. pt.y = rcChar.top + (nItemHeight * 3)/4;
  663. ClientToScreen(hwnd, &pt);
  664. SetCursorPos(pt.x, pt.y);
  665. break;
  666. }
  667. }
  668. return 0;
  669. }
  670. //////////////////////////////////////////////////////////////////
  671. // Function : IconView_GetWidthByColumn
  672. // Type : INT
  673. // Purpose :
  674. // Args :
  675. // : LPPLVDATA lpPlv
  676. // : INT col
  677. // Return :
  678. // DATE :
  679. //////////////////////////////////////////////////////////////////
  680. INT IconView_GetWidthByColumn(LPPLVDATA lpPlv, INT col)
  681. {
  682. if(col < 0) {
  683. col = 0;
  684. }
  685. INT nItemWidth = IV_GetItemWidth(lpPlv->hwndSelf);
  686. INT nVScroll = GetSystemMetrics(SM_CXVSCROLL);
  687. INT nEdge = GetSystemMetrics(SM_CXEDGE);
  688. Dbg(("nItemWidth [%d] nVScroll[%d] nEdge[%d]\n", nItemWidth, nVScroll, nEdge));
  689. Dbg(("Total Width [%d]\n", col*nItemWidth + nVScroll + nEdge*2));
  690. return col*nItemWidth + nVScroll + nEdge*2;
  691. }
  692. //////////////////////////////////////////////////////////////////
  693. // Function : IconView_GetHeightByRow
  694. // Type : INT
  695. // Purpose :
  696. // Args :
  697. // : LPPLVDATA lpPlv
  698. // : INT row
  699. // Return :
  700. // DATE :
  701. //////////////////////////////////////////////////////////////////
  702. INT IconView_GetHeightByRow(LPPLVDATA lpPlv, INT row)
  703. {
  704. if(row < 0) {
  705. row = 0;
  706. }
  707. INT nItemHeight = IV_GetItemHeight(lpPlv->hwndSelf);
  708. INT nEdge = GetSystemMetrics(SM_CXEDGE);
  709. Dbg(("nItemHeight [%d] [%d] nEdge[%d]\n", nItemHeight, nEdge));
  710. Dbg(("Total Height[%d]\n", row*nItemHeight + nEdge*2));
  711. return row*nItemHeight + nEdge*2;
  712. }