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.

859 lines
25 KiB

  1. #ifndef WIN32_LEAN_AND_MEAN
  2. #define WIN32_LEAN_AND_MEAN
  3. #endif
  4. #include <windows.h>
  5. #include <windowsx.h>
  6. #include <commctrl.h>
  7. #include "plv_.h"
  8. #include "plv.h"
  9. #include "dbg.h"
  10. #include "repview.h"
  11. #include "rvmisc.h"
  12. #include "exgdiw.h"
  13. // temporary
  14. #if 0
  15. #include "resource.h"
  16. #endif
  17. #ifdef UNDER_CE // Windows CE specific
  18. #include "stub_ce.h" // Windows CE stub for unsupported APIs
  19. #endif // UNDER_CE
  20. static POSVERSIONINFO ExGetOSVersion(VOID)
  21. {
  22. static BOOL fFirst = TRUE;
  23. static OSVERSIONINFO os;
  24. if ( fFirst ) {
  25. os.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  26. if (GetVersionEx( &os ) ) {
  27. fFirst = FALSE;
  28. }
  29. }
  30. return &os;
  31. }
  32. static BOOL ExIsWinNT(VOID)
  33. {
  34. BOOL fBool;
  35. fBool = (ExGetOSVersion()->dwPlatformId == VER_PLATFORM_WIN32_NT);
  36. return fBool;
  37. }
  38. //----------------------------------------------------------------
  39. // Header control window ID
  40. //----------------------------------------------------------------
  41. HWND RepView_CreateHeader(LPPLVDATA lpPlvData)
  42. {
  43. if(!lpPlvData) {
  44. return NULL;
  45. }
  46. static RECT rc;
  47. // HD_ITEM hdItem;
  48. InitCommonControls();
  49. HWND hwnd;
  50. #ifndef UNDER_CE // always Unicode
  51. if(ExIsWinNT()) {
  52. #endif // UNDER_CE
  53. hwnd = CreateWindowExW(0,
  54. WC_HEADERW,
  55. L"",
  56. WS_CHILD | WS_VISIBLE | HDS_BUTTONS |HDS_HORZ,
  57. 0, 0, 0, 0, //rc.left, rc.top, rc.right - rc.left, 30,
  58. lpPlvData->hwndSelf,
  59. (HMENU)HEADER_ID,
  60. lpPlvData->hInst,
  61. NULL);
  62. #ifndef UNDER_CE // always Unicode
  63. }
  64. else {
  65. hwnd = CreateWindowExA(0,
  66. WC_HEADER,
  67. "",
  68. WS_CHILD | WS_VISIBLE | HDS_BUTTONS |HDS_HORZ,
  69. 0, 0, 0, 0, //rc.left, rc.top, rc.right - rc.left, 30,
  70. lpPlvData->hwndSelf,
  71. (HMENU)HEADER_ID,
  72. lpPlvData->hInst,
  73. NULL);
  74. }
  75. #endif // UNDER_CE
  76. if(hwnd == NULL) {
  77. //wsprintf(szBuf, "Create Header tError %d\n", GetLastError());
  78. //OutputDebugString(szBuf);
  79. //OutputDebugString("Create Header error\n");
  80. return NULL;
  81. }
  82. SendMessage(hwnd,
  83. WM_SETFONT,
  84. (WPARAM)(HFONT)GetStockObject(DEFAULT_GUI_FONT),
  85. MAKELPARAM(FALSE, 0));
  86. GetClientRect(lpPlvData->hwndSelf, &rc); // get PadListView's client rect
  87. static HD_LAYOUT hdl;
  88. static WINDOWPOS wp;
  89. hdl.prc = &rc;
  90. hdl.pwpos = &wp;
  91. //Calc header control window size
  92. if(Header_Layout(hwnd, &hdl) == FALSE) {
  93. //OutputDebugString("Create Header Layout error\n");
  94. return NULL;
  95. }
  96. #if 0 // test test
  97. HD_ITEM hdi; // Header item.
  98. hdi.mask = HDI_FORMAT | HDI_WIDTH | HDI_TEXT;
  99. hdi.fmt = HDF_LEFT | HDF_STRING;
  100. hdi.pszText = "poipoi"; //:zItemHead[i]; // The text for the item.
  101. hdi.cxy = 75; // The initial width.
  102. hdi.cchTextMax = lstrlen(hdi.pszText); // The length of the string.
  103. Header_InsertItem(hwnd, 0, &hdi);
  104. #endif
  105. SetWindowPos(hwnd, wp.hwndInsertAfter, wp.x, wp.y,
  106. wp.cx, wp.cy, wp.flags | SWP_SHOWWINDOW);
  107. //wp.cx, wp.cy, wp.flags | SWP_HIDEWINDOW);
  108. return hwnd;
  109. }
  110. //////////////////////////////////////////////////////////////////
  111. // Function : RepView_RestoreScrollPos
  112. // Type : INT
  113. // Purpose :
  114. // Args :
  115. // : LPPLVDATA lpPlvData
  116. // Return :
  117. // DATE :
  118. //////////////////////////////////////////////////////////////////
  119. INT RepView_RestoreScrollPos(LPPLVDATA lpPlvData)
  120. {
  121. return RV_SetCurScrollPos(lpPlvData->hwndSelf, lpPlvData->nCurScrollPos);
  122. }
  123. //////////////////////////////////////////////////////////////////
  124. // Function : RepView_ResetScrollPos
  125. // Type : INT
  126. // Purpose :
  127. // Args :
  128. // : LPPLVDATA lpPlvData
  129. // Return :
  130. // DATE :
  131. //////////////////////////////////////////////////////////////////
  132. INT RepView_ResetScrollRange(LPPLVDATA lpPlvData)
  133. {
  134. static SCROLLINFO scrInfo;
  135. if(!lpPlvData) {
  136. return 0;
  137. }
  138. HWND hwnd = lpPlvData->hwndSelf;
  139. INT nRow = RV_GetRow(hwnd);
  140. //INT nCol = RV_GetCol(hwnd);
  141. INT nMax = RV_GetMaxLine(hwnd);
  142. INT nPos = lpPlvData->nCurScrollPos;
  143. //lpPlv->iCurTopIndex = nPos;
  144. scrInfo.cbSize = sizeof(scrInfo);
  145. scrInfo.fMask = SIF_PAGE | SIF_POS | SIF_RANGE;
  146. scrInfo.nMin = 0;
  147. scrInfo.nMax = nMax-1;
  148. scrInfo.nPage = nRow;
  149. scrInfo.nPos = nPos;
  150. scrInfo.nTrackPos = 0;
  151. //In normal case,
  152. //if (scrInfo.nMax - scrInfo.nMin + 1) <= scrInfo.nPage,
  153. // scroll bar is hidden. to prevent it,
  154. // in this case, set proper page, and DISABLE scrollbar.
  155. // Now we can show scroll bar always
  156. if((scrInfo.nMax - scrInfo.nMin +1) <= (INT)scrInfo.nPage) {
  157. scrInfo.nMin = 0;
  158. scrInfo.nMax = 1;
  159. scrInfo.nPage = 1;
  160. #ifndef UNDER_CE // Windows CE does not support EnableScrollBar
  161. SetScrollInfo(hwnd, SB_VERT, &scrInfo, TRUE);
  162. EnableScrollBar(hwnd, SB_VERT, ESB_DISABLE_BOTH);
  163. #else // UNDER_CE
  164. scrInfo.fMask |= SIF_DISABLENOSCROLL;
  165. SetScrollInfo(hwnd, SB_VERT, &scrInfo, TRUE);
  166. #endif // UNDER_CE
  167. }
  168. else {
  169. #ifndef UNDER_CE // Windows CE does not support EnableScrollBar
  170. EnableScrollBar(hwnd, SB_VERT, ESB_ENABLE_BOTH);
  171. #endif // UNDER_CE
  172. SetScrollInfo(hwnd, SB_VERT, &scrInfo, TRUE);
  173. }
  174. return 0;
  175. }
  176. //////////////////////////////////////////////////////////////////
  177. // Function : RepView_SetItemCount
  178. // Type : INT
  179. // Purpose :
  180. // Args :
  181. // : LPPLVDATA lpPlvData
  182. // : INT itemCount
  183. // : BOOL fDraw update scroll bar or not
  184. // Return :
  185. // DATE :
  186. //////////////////////////////////////////////////////////////////
  187. INT RepView_SetItemCount(LPPLVDATA lpPlvData, INT itemCount, BOOL fDraw)
  188. {
  189. lpPlvData->iItemCount = itemCount;
  190. lpPlvData->iCurTopIndex = 0; //970707 ToshiaK, change curTopindex to 0
  191. lpPlvData->nCurScrollPos = 0; //970707 ToshiaK, same as iCurTopIndex
  192. if(fDraw) {
  193. INT nMaxLine = lpPlvData->iItemCount; //RV_GetMaxLine(lpPlvData->hwndSelf);
  194. INT nPage = RV_GetRow(lpPlvData->hwndSelf);
  195. RV_SetScrollInfo(lpPlvData->hwndSelf, 0, nMaxLine, nPage, 0);
  196. }
  197. return 0;
  198. }
  199. //////////////////////////////////////////////////////////////////
  200. // Function : RepView_SetTopIndex
  201. // Type : INT
  202. // Purpose :
  203. // Args :
  204. // : LPPLVDATA lpPlvData
  205. // : INT indexTop
  206. // Return :
  207. // DATE :
  208. //////////////////////////////////////////////////////////////////
  209. INT RepView_SetTopIndex(LPPLVDATA lpPlvData, INT indexTop)
  210. {
  211. INT nCol = RV_GetCol(lpPlvData->hwndSelf);
  212. if(nCol <=0) {
  213. return 0;
  214. }
  215. if(indexTop < lpPlvData->iItemCount) {
  216. lpPlvData->iCurTopIndex = indexTop;
  217. RV_SetCurScrollPos(lpPlvData->hwndSelf, lpPlvData->iCurTopIndex);
  218. RECT rc;
  219. GetClientRect(lpPlvData->hwndSelf, &rc);
  220. rc.top += RV_GetHeaderHeight(lpPlvData);
  221. InvalidateRect(lpPlvData->hwndSelf, &rc, TRUE);
  222. UpdateWindow(lpPlvData->hwndSelf);
  223. return indexTop;
  224. }
  225. else {
  226. return -1;
  227. }
  228. }
  229. //////////////////////////////////////////////////////////////////
  230. // Function : RepView_Paint
  231. // Type : INT
  232. // Purpose :
  233. // Args :
  234. // : HWND hwnd
  235. // : WPARAM wParam
  236. // : LPARAM lParam
  237. // Return :
  238. // DATE :
  239. //////////////////////////////////////////////////////////////////
  240. INT RepView_Paint(HWND hwnd, WPARAM wParam, LPARAM lParam)
  241. {
  242. //OutputDebugString("RepViewPaint start\n");
  243. LPPLVDATA lpPlvData = GetPlvDataFromHWND(hwnd);
  244. if(!lpPlvData) {
  245. return 0;
  246. }
  247. DP(("RepView_Paint START lpPlvData[0x%08x]\n", lpPlvData));
  248. DP(("RepView_Paint START lpPlvData->lpfnPlvRepItemCallback[0x%08x]\n", lpPlvData->lpfnPlvRepItemCallback));
  249. if(!lpPlvData->lpfnPlvRepItemCallback) {
  250. Dbg((" Error Callback\n"));
  251. //OutputDebugString("RepViewPaint end 1\n");
  252. return 0;
  253. }
  254. INT nCol = RV_GetColumn(lpPlvData);
  255. INT *pColWidth;
  256. if(nCol < 1) {
  257. return 0;
  258. }
  259. LPPLVITEM lpPlvItemList = (LPPLVITEM)MemAlloc(sizeof(PLVITEM)*nCol);
  260. if(!lpPlvItemList) {
  261. return 0;
  262. }
  263. pColWidth = (INT *)MemAlloc(sizeof(INT)*nCol);
  264. if(!pColWidth) {
  265. DP(("RepView_Paint END\n"));
  266. //OutputDebugString("RepViewPaint end 2\n");
  267. MemFree(lpPlvItemList);
  268. return 0;
  269. }
  270. ZeroMemory(lpPlvItemList, sizeof(PLVITEM)*nCol);
  271. static PAINTSTRUCT ps;
  272. HDC hDC = BeginPaint(hwnd, &ps);
  273. static RECT rc;
  274. GetClientRect(hwnd, &rc);
  275. HDC hDCMem = CreateCompatibleDC(hDC);
  276. HBITMAP hBitmap = CreateCompatibleBitmap(hDC,
  277. rc.right - rc.left,
  278. rc.bottom - rc.top);
  279. HBITMAP hBitmapPrev = (HBITMAP)SelectObject(hDCMem, hBitmap);
  280. //----------------------------------------------------------------
  281. //971111: #2586: Back color is COLOR_WINDOW
  282. //----------------------------------------------------------------
  283. //HBRUSH hBrush = CreateSolidBrush(GetSysColor(COLOR_3DFACE));
  284. //DWORD dwOldBkColor = SetBkColor(hDCMem, GetSysColor(COLOR_3DFACE));
  285. HBRUSH hBrush = CreateSolidBrush(GetSysColor(COLOR_WINDOW));
  286. DWORD dwOldBkColor = SetBkColor(hDCMem, GetSysColor(COLOR_WINDOW));
  287. DWORD dwOldTextColor = SetTextColor(hDCMem, GetSysColor(COLOR_WINDOWTEXT));
  288. HDC hDCForBmp = CreateCompatibleDC(hDCMem); // for item columne bitmap;
  289. FillRect(hDCMem, &rc, hBrush);
  290. INT nRow = RV_GetRow(hwnd);
  291. INT y;
  292. static RECT rcItem;
  293. static PLVITEM plvItemTmp, plvItem;
  294. HFONT hFontOld = NULL;
  295. if(lpPlvData->hFontRep) {
  296. hFontOld = (HFONT)SelectObject(hDCMem, lpPlvData->hFontRep);
  297. }
  298. static POINT pt;
  299. #ifndef UNDER_CE // Windows CE does not support GetCursorPos.
  300. GetCursorPos(&pt);
  301. ScreenToClient(hwnd, &pt);
  302. #else // UNDER_CE
  303. if(lpPlvData->iCapture != CAPTURE_NONE){
  304. pt.x = lpPlvData->ptCapture.x;
  305. pt.y = lpPlvData->ptCapture.y;
  306. }
  307. else{
  308. // set outer client point
  309. pt.x = -1;
  310. pt.y = -1;
  311. }
  312. #endif // UNDER_CE
  313. static RECT rcHead;
  314. GetClientRect(lpPlvData->hwndHeader, &rcHead);
  315. INT nItemHeight = RV_GetItemHeight(hwnd);
  316. INT yOffsetHead = rcHead.bottom - rcHead.top;
  317. INT i, j, k;
  318. for(k = 0; k < nCol; k++) {
  319. HD_ITEM hdItem;
  320. hdItem.mask = HDI_WIDTH;
  321. hdItem.fmt = 0;
  322. Header_GetItem(lpPlvData->hwndHeader, k, &hdItem);
  323. pColWidth[k] = hdItem.cxy;
  324. }
  325. // DP(("lpPlvData->iCurTopIndex [%d]\n", lpPlvData->iCurTopIndex));
  326. // DP(("nRow %d\n", nRow));
  327. // DP(("lpPlvData->iItemCount [%d]\n", lpPlvData->iItemCount));
  328. //----------------------------------------------------------------
  329. // for each index item( each line that will be displayed )
  330. //----------------------------------------------------------------
  331. //Dbg(("iCurTopIndex = %d\n", lpPlvData->iCurTopIndex));
  332. //Dbg(("iItemCount = %d\n", lpPlvData->iItemCount));
  333. for(i = 0, j = lpPlvData->iCurTopIndex;
  334. i < nRow && j < lpPlvData->iItemCount;
  335. i++, j++) {
  336. //----------------------------------------------------------------
  337. // get line's vertical offset.
  338. //----------------------------------------------------------------
  339. y = RV_GetYMargin(hwnd) + nItemHeight * i;
  340. ZeroMemory(lpPlvItemList, sizeof(PLVITEM)*nCol);
  341. //----------------------------------------------------------------
  342. //changed data query call back spec in 970705: by toshiak
  343. // get line's all column data with one function call.
  344. //----------------------------------------------------------------
  345. lpPlvData->lpfnPlvRepItemCallback(lpPlvData->repItemCallbacklParam,
  346. j, //line index.
  347. nCol, //column Count.
  348. lpPlvItemList);
  349. INT xOffset = 0;
  350. //Dbg(("j = %d\n", j));
  351. for(k = 0; k < nCol; k++) {
  352. //Dbg(("k = %d\n", k));
  353. rcItem.left = xOffset;
  354. rcItem.right = rcItem.left + pColWidth[k];
  355. rcItem.top = rc.top + yOffsetHead + y;
  356. rcItem.bottom= rcItem.top + nItemHeight;
  357. if(rcItem.top > rc.bottom) {
  358. break;
  359. }
  360. if(rcItem.left > rc.right) {
  361. break;
  362. }
  363. RV_DrawItem(lpPlvData, hDCMem, hDCForBmp, pt, k, &rcItem, &lpPlvItemList[k]);
  364. xOffset += pColWidth[k];
  365. }
  366. //----------------------------------------------------------------
  367. //000531:Satori #1641
  368. //Call DeleteObject() here.
  369. //----------------------------------------------------------------
  370. for(k = 0; k < nCol; k++) {
  371. if(lpPlvItemList[k].fmt == PLVFMT_BITMAP && lpPlvItemList[k].hBitmap != NULL) {
  372. DeleteObject(lpPlvItemList[k].hBitmap);
  373. }
  374. }
  375. }
  376. if(hFontOld){
  377. SelectObject(hDCMem, hFontOld);
  378. }
  379. if(pColWidth) {
  380. MemFree(pColWidth);
  381. }
  382. if(lpPlvItemList) {
  383. MemFree(lpPlvItemList);
  384. }
  385. // LIZHANG: if there is no items, draw the explanation text
  386. if ( !lpPlvData->iItemCount && (lpPlvData->lpText || lpPlvData->lpwText))
  387. {
  388. HFONT hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
  389. HFONT hOldFont = (HFONT)SelectObject( hDCMem, hFont );
  390. RECT rcTmp = rc;
  391. rcTmp.left = 20;
  392. rcTmp.top = 20;
  393. rcTmp.right -= 10;
  394. rcTmp.bottom -= 10;
  395. //----------------------------------------------------------------
  396. //971111: #2586
  397. //COLORREF colOld = SetTextColor( hDCMem, GetSysColor(COLOR_WINDOW) );
  398. //COLORREF colBkOld = SetBkColor( hDCMem, GetSysColor(COLOR_3DFACE) );
  399. //----------------------------------------------------------------
  400. COLORREF colOld = SetTextColor( hDCMem, GetSysColor(COLOR_WINDOWTEXT));
  401. COLORREF colBkOld = SetBkColor( hDCMem, GetSysColor(COLOR_WINDOW) );
  402. #ifndef UNDER_CE // always Unicode
  403. if(ExIsWinNT()) {
  404. #endif // UNDER_CE
  405. if(lpPlvData->lpwText) {
  406. DrawTextW( hDCMem,
  407. lpPlvData->lpwText,
  408. lstrlenW(lpPlvData->lpwText),
  409. &rcTmp,
  410. DT_VCENTER|DT_WORDBREAK );
  411. }
  412. #ifndef UNDER_CE // always Unicode
  413. }
  414. else {
  415. if(lpPlvData->lpText) {
  416. DrawText( hDCMem,
  417. lpPlvData->lpText,
  418. lstrlen(lpPlvData->lpText),
  419. &rcTmp,DT_VCENTER|DT_WORDBREAK );
  420. }
  421. }
  422. #endif // UNDER_CE
  423. SetTextColor( hDCMem, colOld );
  424. SetBkColor( hDCMem, colBkOld );
  425. SelectObject( hDCMem, hOldFont );
  426. }
  427. BitBlt(hDC,
  428. rc.left,
  429. rc.top,
  430. rc.right - rc.left,
  431. rc.bottom - rc.top,
  432. hDCMem, 0, 0, SRCCOPY);
  433. // LIZHANG 7/6/97 added this line to repaint header control
  434. InvalidateRect(lpPlvData->hwndHeader,NULL,FALSE);
  435. DeleteObject(hBrush);
  436. SetBkColor(hDCMem, dwOldBkColor);
  437. SetTextColor(hDCMem, dwOldTextColor);
  438. SelectObject(hDCMem, hBitmapPrev );
  439. DeleteObject(hBitmap);
  440. DeleteDC(hDCForBmp);
  441. DeleteDC( hDCMem );
  442. EndPaint(hwnd, &ps);
  443. //OutputDebugString("RepViewPaint end 3\n");
  444. return 0;
  445. Unref3(hwnd, wParam, lParam);
  446. }
  447. INT RepView_Notify(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  448. {
  449. //Dbg(("Header Notify come\n"));
  450. LPPLVDATA lpPlvData = GetPlvDataFromHWND(hwnd);
  451. if(!lpPlvData) {
  452. return 0;
  453. }
  454. HD_NOTIFY *lpNtfy = (HD_NOTIFY *)lParam;
  455. switch(lpNtfy->hdr.code) {
  456. case HDN_ITEMCLICKW:
  457. case HDN_ITEMCLICKA:
  458. {
  459. //Dbg(("lpNtfy->iItem [%d]\n", lpNtfy->iItem));
  460. //Dbg(("lpNtfy->iButton [%d]\n", lpNtfy->iButton));
  461. static PLVINFO plvInfo;
  462. ZeroMemory(&plvInfo, sizeof(plvInfo));
  463. plvInfo.code = PLVN_HDCOLUMNCLICKED;
  464. plvInfo.colIndex = lpNtfy->iItem;
  465. SendMessage(GetParent(hwnd), lpPlvData->uMsg, 0, (LPARAM)&plvInfo);
  466. }
  467. break;
  468. case HDN_ITEMDBLCLICK:
  469. case HDN_DIVIDERDBLCLICK:
  470. case HDN_BEGINTRACK:
  471. break;
  472. case HDN_ENDTRACKA:
  473. case HDN_ENDTRACKW:
  474. {
  475. RECT rc, rcHead;
  476. GetClientRect(hwnd, &rc);
  477. GetClientRect(lpNtfy->hdr.hwndFrom, &rcHead);
  478. rc.top += rcHead.bottom - rcHead.top;
  479. InvalidateRect(hwnd, &rc, FALSE);
  480. }
  481. break;
  482. case HDN_TRACK:
  483. break;
  484. }
  485. return 0;
  486. Unref(uMsg);
  487. Unref(wParam);
  488. }
  489. INT RepView_ButtonDown(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  490. {
  491. LPPLVDATA lpPlvData = GetPlvDataFromHWND(hwnd);
  492. if(!lpPlvData) {
  493. return 0;
  494. }
  495. switch(uMsg) {
  496. case WM_LBUTTONDOWN:
  497. case WM_MBUTTONDOWN:
  498. case WM_RBUTTONDOWN:
  499. case WM_LBUTTONDBLCLK:
  500. case WM_MBUTTONDBLCLK:
  501. case WM_RBUTTONDBLCLK:
  502. //Dbg(("WM_LBUTTONDOWN COME\n"));
  503. SetCapture(hwnd);
  504. #ifdef UNDER_CE // LBUTTON + ALT key handling
  505. //Standard way for RBUTTON handling is combination w/ LBUTTON + ALT key
  506. if(uMsg == WM_LBUTTONDOWN && GetAsyncKeyState(VK_MENU)){
  507. uMsg = WM_RBUTTONDOWN;
  508. }
  509. #endif // UNDER_CE
  510. switch(uMsg) {
  511. case WM_LBUTTONDOWN:
  512. case WM_LBUTTONDBLCLK:
  513. lpPlvData->iCapture = CAPTURE_LBUTTON;
  514. break;
  515. case WM_MBUTTONDOWN:
  516. case WM_MBUTTONDBLCLK:
  517. lpPlvData->iCapture = CAPTURE_MBUTTON;
  518. break;
  519. case WM_RBUTTONDOWN:
  520. case WM_RBUTTONDBLCLK:
  521. lpPlvData->iCapture = CAPTURE_RBUTTON;
  522. break;
  523. }
  524. #ifndef UNDER_CE // Windows CE does not support GetCursorPos.
  525. GetCursorPos(&lpPlvData->ptCapture);
  526. //remember left button down place
  527. ScreenToClient(hwnd, &lpPlvData->ptCapture);
  528. #else // UNDER_CE
  529. lpPlvData->ptCapture.x = (SHORT)LOWORD(lParam);
  530. lpPlvData->ptCapture.y = (SHORT)HIWORD(lParam);
  531. #endif // UNDER_CE
  532. RECT rc;
  533. GetClientRect(hwnd, &rc);
  534. rc.top += RV_GetHeaderHeight(lpPlvData);
  535. InvalidateRect(hwnd, &rc, FALSE);
  536. //UpdateWindow(lpPlvData->hwndSelf);
  537. break;
  538. }
  539. return 0;
  540. Unref2(wParam, lParam);
  541. }
  542. INT RepView_ButtonUp(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  543. {
  544. LPPLVDATA lpPlvData = GetPlvDataFromHWND(hwnd);
  545. static POINT pt;
  546. static PLVINFO plvInfo;
  547. static INT index, downIndex;
  548. if(!lpPlvData) {
  549. return 0;
  550. }
  551. switch(uMsg) {
  552. case WM_LBUTTONUP:
  553. case WM_RBUTTONUP:
  554. case WM_MBUTTONUP:
  555. //Dbg(("WM_LBUTTONUP COMES\n"));
  556. #ifdef UNDER_CE // LBUTTON + ALT key handling
  557. //Standard way for RBUTTON handling is combination w/ LBUTTON + ALT key
  558. if(uMsg == WM_LBUTTONUP && GetAsyncKeyState(VK_MENU)){
  559. uMsg = WM_RBUTTONUP;
  560. }
  561. #endif // UNDER_CE
  562. RECT rc;
  563. lpPlvData->iCapture = CAPTURE_NONE;
  564. ReleaseCapture();
  565. GetClientRect(lpPlvData->hwndSelf, &rc);
  566. rc.top += RV_GetHeaderHeight(lpPlvData);
  567. InvalidateRect(lpPlvData->hwndSelf, &rc, TRUE);
  568. pt.x = LOWORD(lParam);
  569. pt.y = HIWORD(lParam);
  570. //Dbg(("x %d, y %d\n", pt.x, pt.y));
  571. //Dbg(("capture x[%d] y[%d] \n",lpPlvData->ptCapture.x,lpPlvData->ptCapture.y));
  572. downIndex = RV_GetInfoFromPoint(lpPlvData, lpPlvData->ptCapture, NULL);
  573. index = RV_GetInfoFromPoint(lpPlvData, pt, &plvInfo);
  574. //Dbg(("mouse down index [%d]\n", downIndex));
  575. //Dbg(("mouse up index [%d]\n", index));
  576. if(index != -1) {
  577. Dbg(("code [%d]\n", plvInfo.code));
  578. Dbg(("index [%d]\n", plvInfo.index));
  579. Dbg(("left[%d] top[%d] right[%d] bottom[%d] \n",
  580. plvInfo.itemRect.left,
  581. plvInfo.itemRect.top,
  582. plvInfo.itemRect.right,
  583. plvInfo.itemRect.bottom));
  584. if(index == downIndex) {
  585. if(lpPlvData->uMsg != 0) {
  586. if(uMsg == WM_LBUTTONUP) {
  587. plvInfo.code = PLVN_ITEMCLICKED;
  588. SendMessage(GetParent(hwnd), lpPlvData->uMsg, 0, (LPARAM)&plvInfo);
  589. }
  590. else if(uMsg == WM_RBUTTONUP) {
  591. plvInfo.code = PLVN_R_ITEMCLICKED;
  592. SendMessage(GetParent(hwnd), lpPlvData->uMsg, 0, (LPARAM)&plvInfo);
  593. }
  594. }
  595. }
  596. }
  597. lpPlvData->ptCapture.x = 0;
  598. lpPlvData->ptCapture.y = 0;
  599. break;
  600. }
  601. return 0;
  602. Unref(wParam);
  603. }
  604. //////////////////////////////////////////////////////////////////
  605. // Function : RepView_MouseMove
  606. // Type : INT
  607. // Purpose :
  608. // Args :
  609. // : HWND hwnd
  610. // : WPARAM wParam
  611. // : LPARAM lParam
  612. // Return :
  613. // DATE :
  614. //////////////////////////////////////////////////////////////////
  615. INT RepView_MouseMove(HWND hwnd, WPARAM wParam, LPARAM lParam)
  616. {
  617. LPPLVDATA lpPlvData = GetPlvDataFromHWND(hwnd);
  618. if(!lpPlvData) {
  619. return 0;
  620. }
  621. static RECT rc;
  622. static POINT pt;
  623. static PLVINFO plvInfo;
  624. pt.x = LOWORD(lParam);
  625. pt.y = HIWORD(lParam);
  626. //Dbg(("x %d, y %d\n", pt.x, pt.y));
  627. INT index = RV_GetInfoFromPoint(lpPlvData, pt, &plvInfo);
  628. //Dbg(("mouse up index [%d]\n", index));
  629. GetClientRect(lpPlvData->hwndSelf, &rc);
  630. rc.top += RV_GetHeaderHeight(lpPlvData);
  631. InvalidateRect(hwnd, &rc, FALSE);
  632. if(index != -1 && (lpPlvData->iCapture == CAPTURE_NONE)) {
  633. if(lpPlvData->uMsg != 0) {
  634. if(plvInfo.colIndex == 0) { //poped image is only when column index == 0.
  635. plvInfo.code = PLVN_ITEMPOPED;
  636. SendMessage(GetParent(hwnd), lpPlvData->uMsg, 0, (LPARAM)&plvInfo);
  637. }
  638. #ifdef MSAA
  639. static oldindex = 0;
  640. index = PLV_ChildIDFromPoint(lpPlvData,pt);
  641. if((index > 0)&&(index != oldindex)){
  642. PLV_NotifyWinEvent(lpPlvData,
  643. EVENT_OBJECT_FOCUS,
  644. hwnd,
  645. OBJID_CLIENT,
  646. index); // child id
  647. oldindex = index;
  648. }
  649. #endif
  650. }
  651. }
  652. return 0;
  653. Unref(wParam);
  654. }
  655. //////////////////////////////////////////////////////////////////
  656. // Function : RepView_VScroll
  657. // Type : INT
  658. // Purpose :
  659. // Args :
  660. // : HWND hwnd
  661. // : WPARAM wParam
  662. // : LPARAM lParam
  663. // Return :
  664. // DATE :
  665. //////////////////////////////////////////////////////////////////
  666. INT RepView_VScroll(HWND hwnd, WPARAM wParam, LPARAM lParam)
  667. {
  668. //----------------------------------------------------------------
  669. // get current top index.
  670. // calc scroll position.
  671. // get new top index and set it.
  672. // redraw window rectangle.
  673. //----------------------------------------------------------------
  674. LPPLVDATA lpPlvData = GetPlvDataFromHWND(hwnd);
  675. if(!lpPlvData) {
  676. return 0;
  677. }
  678. INT nScrollCode = (int) LOWORD(wParam); // scroll bar value
  679. #ifdef _DEBUG
  680. INT nArgPos = (short int) HIWORD(wParam); // scroll box position
  681. #endif
  682. //HWND hwndScrollBar = (HWND) lParam; // handle of scroll bar
  683. INT nPos;
  684. INT nRow, nCol, nMax;
  685. switch(nScrollCode) {
  686. case SB_LINEDOWN:
  687. Dbg(("SB_LINEDOWN COME nArgPos[%d]\n", nArgPos));
  688. nRow = RV_GetRow(hwnd);
  689. nMax = RV_GetMaxLine(hwnd);
  690. nPos = RV_GetCurScrollPos(hwnd);
  691. if(nPos + nRow > nMax - 1) {
  692. return 0;
  693. }
  694. nPos++;
  695. RV_SetCurScrollPos(hwnd, nPos);
  696. break;
  697. case SB_LINEUP:
  698. Dbg(("SB_LINEUP COME nArgPos[%d]\n", nArgPos));
  699. RV_GetRowColumn(hwnd, &nRow, &nCol);
  700. nPos = RV_GetCurScrollPos(hwnd);
  701. if(nPos <= 0) {
  702. return 0;
  703. }
  704. nPos--;
  705. RV_SetCurScrollPos(hwnd, nPos);
  706. break;
  707. case SB_PAGEDOWN:
  708. Dbg(("SB_PAGEDOWN COME nArgPos[%d]\n", nArgPos));
  709. RV_GetRowColumn(hwnd, &nRow, &nCol);
  710. nMax = RV_GetMaxLine(hwnd);
  711. nPos = RV_GetCurScrollPos(hwnd);
  712. nPos = min(nPos+nRow, nMax - nRow);
  713. RV_SetCurScrollPos(hwnd, nPos);
  714. break;
  715. case SB_PAGEUP: //Track�̏オ�N���b�N���ꂽ
  716. Dbg(("SB_PAGEUP COME nArgPos[%d]\n", nArgPos));
  717. RV_GetRowColumn(hwnd, &nRow, &nCol);
  718. nPos = RV_GetCurScrollPos(hwnd);
  719. nPos = max(0, nPos - nRow);
  720. RV_SetCurScrollPos(hwnd, nPos);
  721. break;
  722. case SB_TOP:
  723. Dbg(("SB_TOP COME nArgPos[%d]\n", nArgPos));
  724. break;
  725. case SB_BOTTOM:
  726. Dbg(("SB_BOTTOM COME nArgPos[%d]\n", nArgPos));
  727. break;
  728. case SB_THUMBTRACK: //Track��Drag��
  729. Dbg(("SB_THUMBTRACK COME nArgPos[%d]\n", nArgPos));
  730. nPos = RV_GetScrollTrackPos(hwnd);
  731. Dbg(("Current Pos %d\n", nPos));
  732. RV_GetRowColumn(hwnd, &nRow, &nCol);
  733. RV_SetCurScrollPos(hwnd, nPos);
  734. break;
  735. case SB_THUMBPOSITION: //Scroll Bar��Drag���I������
  736. Dbg(("SB_THUMBPOSITION COME nArgPos[%d]\n", nArgPos));
  737. nPos = RV_GetScrollTrackPos(hwnd);
  738. Dbg(("Current Pos %d\n", nPos));
  739. RV_GetRowColumn(hwnd, &nRow, &nCol);
  740. RV_SetCurScrollPos(hwnd, nPos);
  741. break;
  742. case SB_ENDSCROLL:
  743. Dbg(("SB_ENDSCROLL COME nArgPos[%d]\n", nArgPos));
  744. break;
  745. }
  746. RECT rc;
  747. GetClientRect(lpPlvData->hwndSelf, &rc);
  748. rc.top += RV_GetHeaderHeight(lpPlvData);
  749. InvalidateRect(lpPlvData->hwndSelf, &rc, TRUE);
  750. return 0;
  751. Unref3(hwnd, wParam, lParam);
  752. }
  753. INT RepView_SetCurSel(LPPLVDATA lpPlvData, INT index)
  754. {
  755. DP(("RepView_Paint START lpPlvData[0x%08x]\n", lpPlvData));
  756. INT nCol = RV_GetColumn(lpPlvData);
  757. if(!lpPlvData) {
  758. return 0;
  759. }
  760. if(nCol < 1) {
  761. return 0;
  762. }
  763. HWND hwnd = lpPlvData->hwndSelf;
  764. static RECT rc;
  765. GetClientRect(hwnd, &rc);
  766. INT nRow = RV_GetRow(hwnd);
  767. INT y;
  768. static RECT rcItem;
  769. static POINT pt;
  770. static RECT rcHead;
  771. GetClientRect(lpPlvData->hwndHeader, &rcHead);
  772. INT nItemHeight = RV_GetItemHeight(hwnd);
  773. INT yOffsetHead = rcHead.bottom - rcHead.top;
  774. INT i, j;
  775. Dbg(("yOffsetHead [%d] nItemHeight[%d]\n", yOffsetHead, nItemHeight));
  776. //----------------------------------------------------------------
  777. // for each index item( each line that will be displayed )
  778. //----------------------------------------------------------------
  779. for(i = 0, j = lpPlvData->iCurTopIndex;
  780. i < nRow && j < lpPlvData->iItemCount;
  781. i++, j++) {
  782. //----------------------------------------------------------------
  783. // get line's vertical offset.
  784. //----------------------------------------------------------------
  785. if(j == index) {
  786. y = RV_GetYMargin(hwnd) + nItemHeight * i;
  787. Dbg(("y %d\n", y));
  788. INT xOffset = 0;
  789. rcItem.left = xOffset;
  790. rcItem.top = rc.top + yOffsetHead + y;
  791. pt.x = rcItem.left + (nItemHeight * 3)/4;
  792. pt.y = rcItem.top + (nItemHeight * 3)/4;
  793. Dbg(("pt.x[%d] pt.y[%d]\n", pt.x, pt.y));
  794. ClientToScreen(hwnd, &pt);
  795. SetCursorPos(pt.x, pt.y);
  796. break;
  797. }
  798. }
  799. return 0;
  800. }