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.

589 lines
15 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 "dispatch.h"
  7. #include "plv.h"
  8. #include "plv_.h"
  9. #include "plvproc.h"
  10. #include "plvproc_.h"
  11. #include "dbg.h"
  12. #include "iconview.h"
  13. #include "repview.h"
  14. #include "exgdiw.h"
  15. #ifdef UNDER_CE // Windows CE specific
  16. #include "stub_ce.h" // Windows CE stub for unsupported APIs
  17. #endif // UNDER_CE
  18. #ifdef MSAA
  19. #include "accplv.h"
  20. #endif
  21. extern LPPLVDATA PLV_Initialize(VOID);
  22. extern VOID PLV_Destroy(LPPLVDATA lpPlv);
  23. extern INT PLV_SetScrollInfo(HWND hwnd, INT nMin, INT nMax, INT nPage, INT nPos);
  24. extern INT PLV_GetScrollTrackPos(HWND hwnd);
  25. LRESULT CALLBACK PlvWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  26. {
  27. LRESULT hres;
  28. hres = DispMessage(&msdiMain, hwnd, uMsg, wParam, lParam);
  29. return hres;
  30. }
  31. ////////////////////////////////////////////////////////
  32. // Function : MsgCreate
  33. // Type : static LRESULT
  34. // Purpose : Process WM_CREATE message.
  35. // Intialize PLVDATA and associate to window handle.
  36. // Args :
  37. // : HWND hwnd
  38. // : UINT uMsg
  39. // : WPARAM wParam
  40. // : LPARAM lParam
  41. // Return :
  42. // DATE :
  43. /////////////////////////////////////////////////////////
  44. static LRESULT MsgCreate(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  45. {
  46. LPPLVDATA lpPlvData = (LPPLVDATA)((LPCREATESTRUCT)lParam)->lpCreateParams;
  47. if(!lpPlvData) {
  48. return -1; // create error
  49. }
  50. lpPlvData->hwndSelf = hwnd;
  51. SetPlvDataToHWND(hwnd, lpPlvData);
  52. //show scroll bar always
  53. //----------------------------------------------------------------
  54. // if header window is not created yet, create it.
  55. //----------------------------------------------------------------
  56. if(!lpPlvData->hwndHeader) {
  57. lpPlvData->hwndHeader = RepView_CreateHeader(lpPlvData);
  58. }
  59. PLV_SetScrollInfo(hwnd, 0,0,0,0);
  60. return TRUE;
  61. UnrefForMsg();
  62. }
  63. //////////////////////////////////////////////////////////////////
  64. // Function : MsgPaint
  65. // Type : static LRESULT
  66. // Purpose :
  67. // Args :
  68. // : HWND hwnd
  69. // : UINT uMsg
  70. // : WPARAM wParam
  71. // : LPARAM lParam
  72. // Return :
  73. // DATE :
  74. //////////////////////////////////////////////////////////////////
  75. static LRESULT MsgPaint(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  76. {
  77. LPPLVDATA lpPlvData = GetPlvDataFromHWND(hwnd);
  78. //OutputDebugString("MsgPaint 1 START\n");
  79. DP(("MsgPaint COME\n"));
  80. if(!lpPlvData) {
  81. //OutputDebugString("MsgPaint 1 END\n");
  82. return 0;
  83. }
  84. DP(("MsgPaint lpPlvData->dwStyle [%d]n", lpPlvData->dwStyle));
  85. if(lpPlvData->dwStyle == PLVSTYLE_ICON) {
  86. //OutputDebugString("MsgPaint 1 Icon\n");
  87. IconView_Paint(hwnd, wParam, lParam);
  88. }
  89. else {
  90. //OutputDebugString("MsgPaint 1 Rep\n");
  91. RepView_Paint(hwnd, wParam, lParam);
  92. }
  93. DP(("MsgPaint END\n"));
  94. return 0;
  95. UnrefForMsg();
  96. }
  97. //////////////////////////////////////////////////////////////////
  98. // Function : MsgVScroll
  99. // Type : static LRESULT
  100. // Purpose :
  101. // Args :
  102. // : HWND hwnd
  103. // : UINT uMsg
  104. // : WPARAM wParam
  105. // : LPARAM lParam
  106. // Return :
  107. // DATE :
  108. //////////////////////////////////////////////////////////////////
  109. static LRESULT MsgVScroll(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  110. {
  111. LPPLVDATA lpPlvData = GetPlvDataFromHWND(hwnd);
  112. if(!lpPlvData) {
  113. return 0;
  114. }
  115. if(lpPlvData->dwStyle == PLVSTYLE_ICON) {
  116. IconView_VScroll(hwnd, wParam, lParam);
  117. }
  118. else {
  119. RepView_VScroll(hwnd, wParam, lParam);
  120. }
  121. return 0;
  122. UnrefForMsg();
  123. }
  124. ////////////////////////////////////////////////////////
  125. // Function : MsgDestroy
  126. // Type : static LRESULT
  127. // Purpose : Process WM_DESTORY message
  128. // Args :
  129. // : HWND hwnd
  130. // : UINT uMsg
  131. // : WPARAM wParam
  132. // : LPARAM lParam
  133. // Return :
  134. // DATE :
  135. /////////////////////////////////////////////////////////
  136. static LRESULT MsgDestroy(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  137. {
  138. LPPLVDATA lpPlvData = GetPlvDataFromHWND(hwnd);
  139. if(!lpPlvData) {
  140. return 0;
  141. }
  142. if(lpPlvData->hwndHeader) {
  143. ::DestroyWindow(lpPlvData->hwndHeader);
  144. lpPlvData->hwndHeader = NULL;
  145. }
  146. if(lpPlvData->hFontIcon) {
  147. ::DeleteObject(lpPlvData->hFontIcon);
  148. lpPlvData->hFontIcon = NULL;
  149. }
  150. if(lpPlvData->hFontRep) {
  151. ::DeleteObject(lpPlvData->hFontRep);
  152. lpPlvData->hFontRep = NULL;
  153. }
  154. if(lpPlvData->hFontHeader) {
  155. ::DeleteObject(lpPlvData->hFontHeader);
  156. lpPlvData->hFontHeader = NULL;
  157. }
  158. #ifdef MSAA
  159. lpPlvData->bReadyForWMGetObject = FALSE;
  160. if(lpPlvData->pAccPLV) {
  161. CoDisconnectObject((LPUNKNOWN) lpPlvData->pAccPLV, 0L);
  162. delete lpPlvData->pAccPLV;
  163. lpPlvData->pAccPLV = NULL;
  164. PLV_NotifyWinEvent(lpPlvData,
  165. EVENT_OBJECT_DESTROY,
  166. hwnd,
  167. OBJID_CLIENT,
  168. CHILDID_SELF);
  169. }
  170. #endif
  171. #if 1 // kwada
  172. PLV_Destroy(lpPlvData);
  173. #else
  174. MemFree(lpPlvData);
  175. #endif
  176. SetPlvDataToHWND(hwnd, (LPPLVDATA)NULL);
  177. return 0;
  178. UnrefForMsg();
  179. }
  180. //////////////////////////////////////////////////////////////////
  181. // Function : MsgSize
  182. // Type : static LRESULT
  183. // Purpose :
  184. // Args :
  185. // : HWND hwnd
  186. // : UINT uMsg
  187. // : WPARAM wParam
  188. // : LPARAM lParam
  189. // Return :
  190. // DATE :
  191. //////////////////////////////////////////////////////////////////
  192. static LRESULT MsgSize(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  193. {
  194. //INT nWidth = LOWORD(lParam);
  195. //INT nHeight = HIWORD(lParam);
  196. LPPLVDATA lpPlvData = GetPlvDataFromHWND(hwnd);
  197. if(!lpPlvData) {
  198. return 0;
  199. }
  200. RECT rc;
  201. Dbg(("MsgSize COME\n"));
  202. if(lpPlvData->hwndHeader && lpPlvData->dwStyle == PLVSTYLE_REPORT) {
  203. GetClientRect(lpPlvData->hwndSelf, &rc); // get PadListView's client rect
  204. HD_LAYOUT hdl;
  205. WINDOWPOS wp;
  206. hdl.prc = &rc;
  207. hdl.pwpos = &wp;
  208. //Calc header control window size
  209. if(Header_Layout(lpPlvData->hwndHeader, &hdl) == FALSE) {
  210. //OutputDebugString("Create Header Layout error\n");
  211. return NULL;
  212. }
  213. SetWindowPos(lpPlvData->hwndHeader, wp.hwndInsertAfter, wp.x, wp.y,
  214. wp.cx, wp.cy, wp.flags | SWP_SHOWWINDOW);
  215. }
  216. else {
  217. Dbg(("Header is NULL\n"));
  218. }
  219. if(lpPlvData->dwStyle == PLVSTYLE_ICON) {
  220. IconView_ResetScrollRange(lpPlvData);
  221. }
  222. else {
  223. RepView_ResetScrollRange(lpPlvData);
  224. }
  225. UpdateWindow(hwnd);
  226. return 0;
  227. UnrefForMsg();
  228. }
  229. static LRESULT MsgTimer(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  230. {
  231. static RECT rc;
  232. static POINT pt;
  233. if(wParam == TIMERID_MONITOR) {
  234. GetCursorPos(&pt);
  235. GetWindowRect(hwnd, &rc);
  236. if(!PtInRect(&rc, pt)) {
  237. KillTimer(hwnd, wParam);
  238. InvalidateRect(hwnd, NULL, FALSE);
  239. }
  240. }
  241. return 0;
  242. Unref(uMsg);
  243. Unref(lParam);
  244. }
  245. //////////////////////////////////////////////////////////////////
  246. // Function : MsgLMRButtonDown
  247. // Type : static LRESULT
  248. // Purpose :
  249. // Args :
  250. // : HWND hwnd
  251. // : UINT uMsg
  252. // : WPARAM wParam
  253. // : LPARAM lParam
  254. // Return :
  255. // DATE :
  256. //////////////////////////////////////////////////////////////////
  257. static LRESULT MsgLMRButtonDown(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  258. {
  259. LPPLVDATA lpPlvData = GetPlvDataFromHWND(hwnd);
  260. if(!lpPlvData) {
  261. return 0;
  262. }
  263. if(lpPlvData->dwStyle == PLVSTYLE_ICON) {
  264. IconView_ButtonDown(hwnd, uMsg, wParam, lParam);
  265. }
  266. else {
  267. RepView_ButtonDown(hwnd, uMsg, wParam, lParam);
  268. }
  269. return 0;
  270. UnrefForMsg();
  271. }
  272. //////////////////////////////////////////////////////////////////
  273. // Function : MsgLMRButtonDblClk
  274. // Type : static LRESULT
  275. // Purpose :
  276. // Args :
  277. // : HWND hwnd
  278. // : UINT uMsg
  279. // : WPARAM wParam
  280. // : LPARAM lParam
  281. // Return :
  282. // DATE :
  283. //////////////////////////////////////////////////////////////////
  284. static LRESULT MsgLMRButtonDblClk(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  285. {
  286. LPPLVDATA lpPlvData = GetPlvDataFromHWND(hwnd);
  287. if(!lpPlvData) {
  288. return 0;
  289. }
  290. if(lpPlvData->dwStyle == PLVSTYLE_ICON) {
  291. IconView_ButtonDown(hwnd, uMsg, wParam, lParam);
  292. }
  293. else {
  294. RepView_ButtonDown(hwnd, uMsg, wParam, lParam);
  295. }
  296. return 0;
  297. UnrefForMsg();
  298. }
  299. //////////////////////////////////////////////////////////////////
  300. // Function : MsgLMRButtonUp
  301. // Type : static LRESULT
  302. // Purpose :
  303. // Args :
  304. // : HWND hwnd
  305. // : UINT uMsg
  306. // : WPARAM wParam
  307. // : LPARAM lParam
  308. // Return :
  309. // DATE :
  310. //////////////////////////////////////////////////////////////////
  311. static LRESULT MsgLMRButtonUp(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  312. {
  313. LPPLVDATA lpPlvData = GetPlvDataFromHWND(hwnd);
  314. if(!lpPlvData) {
  315. return 0;
  316. }
  317. if(lpPlvData->dwStyle == PLVSTYLE_ICON) {
  318. IconView_ButtonUp(hwnd, uMsg, wParam, lParam);
  319. }
  320. else {
  321. RepView_ButtonUp(hwnd, uMsg, wParam, lParam);
  322. }
  323. return 0;
  324. UnrefForMsg();
  325. }
  326. //////////////////////////////////////////////////////////////////
  327. // Function : MsgMouseMove
  328. // Type : static LRESULT
  329. // Purpose :
  330. // Args :
  331. // : HWND hwnd
  332. // : UINT uMsg
  333. // : WPARAM wParam
  334. // : LPARAM lParam
  335. // Return :
  336. // DATE :
  337. //////////////////////////////////////////////////////////////////
  338. static LRESULT MsgMouseMove(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  339. {
  340. LPPLVDATA lpPlvData = GetPlvDataFromHWND(hwnd);
  341. if(!lpPlvData) {
  342. return 0;
  343. }
  344. if(lpPlvData->dwStyle == PLVSTYLE_ICON) {
  345. IconView_MouseMove(hwnd, wParam, lParam);
  346. }
  347. else {
  348. RepView_MouseMove(hwnd, wParam, lParam);
  349. }
  350. KillTimer(hwnd, TIMERID_MONITOR);
  351. SetTimer(hwnd, TIMERID_MONITOR, 100, NULL);
  352. return 0;
  353. UnrefForMsg();
  354. }
  355. static LRESULT MsgNcMouseMove(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  356. {
  357. InvalidateRect(hwnd, NULL, FALSE);
  358. return 0;
  359. UnrefForMsg();
  360. }
  361. //////////////////////////////////////////////////////////////////
  362. // Function : MsgCaptureChanged
  363. // Type : static LRESULT
  364. // Purpose :
  365. // Args :
  366. // : HWND hwnd
  367. // : UINT uMsg
  368. // : WPARAM wParam
  369. // : LPARAM lParam
  370. // Return :
  371. // DATE :
  372. //////////////////////////////////////////////////////////////////
  373. static LRESULT MsgCaptureChanged(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  374. {
  375. LPPLVDATA lpPlvData = GetPlvDataFromHWND(hwnd);
  376. if(!lpPlvData) {
  377. return 0;
  378. }
  379. if((HWND)wParam != hwnd) { // some other window captured mouse.
  380. lpPlvData->iCapture = CAPTURE_NONE;
  381. }
  382. return 0;
  383. UnrefForMsg();
  384. }
  385. ////////////////////////////////////////////////////////
  386. // Function : MsgNotify
  387. // Type : static LRESULT
  388. // Purpose : Process WM_NOTIFY message.
  389. // : currently for Tab Control window.
  390. // Args :
  391. // : HWND hwnd
  392. // : UINT uMsg
  393. // : WPARAM wParam
  394. // : LPARAM lParam
  395. // Return :
  396. // DATE :
  397. /////////////////////////////////////////////////////////
  398. /////////////////////////////
  399. //typedef struct tagNMHDR
  400. //{
  401. // HWND hwndFrom;
  402. // UINT idFrom;
  403. // UINT code; // NM_ code
  404. //} NMHDR;
  405. //typedef NMHDR FAR * LPNMHDR;
  406. /////////////////////////////
  407. static LRESULT MsgNotify(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  408. {
  409. INT idCtrl = (INT)wParam;
  410. switch(idCtrl) {
  411. case HEADER_ID:
  412. RepView_Notify(hwnd, uMsg, wParam, lParam);
  413. break;
  414. }
  415. return 0;
  416. UnrefForMsg();
  417. }
  418. static LRESULT MsgCommand(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  419. {
  420. return DispCommand(&cmdiMain, hwnd, wParam, lParam);
  421. UnrefForMsg();
  422. }
  423. static LRESULT MsgMeasureItem(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  424. {
  425. return 0;
  426. UnrefForMsg();
  427. }
  428. static LRESULT MsgDrawItem(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  429. {
  430. Dbg(("MsgDrawItem START\n"));
  431. LPPLVDATA lpPlvData = GetPlvDataFromHWND(hwnd);
  432. if(!lpPlvData) {
  433. return 0;
  434. }
  435. LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
  436. switch(lpdis->CtlType) {
  437. case ODT_HEADER:
  438. {
  439. static WCHAR wchBuf[256];
  440. #ifndef UNDER_CE // always Unicode
  441. if(::IsWindowUnicode(lpdis->hwndItem)) {
  442. #endif // UNDER_CE
  443. HDITEMW hdItem;
  444. ::ZeroMemory(&hdItem, sizeof(hdItem));
  445. hdItem.mask = HDI_TEXT | HDI_HEIGHT;
  446. wchBuf[0] = (WCHAR)0x00;
  447. hdItem.pszText = wchBuf;
  448. hdItem.cchTextMax = sizeof(wchBuf);
  449. ::SendMessageW(lpdis->hwndItem,
  450. HDM_GETITEMW,
  451. (WPARAM)lpdis->itemID,
  452. (LPARAM)&hdItem);
  453. DBGW((L"%d: %s\n", lpdis->itemID, wchBuf));
  454. #ifndef UNDER_CE // always Unicode
  455. }
  456. else {
  457. HDITEMA hdItem;
  458. static char szBuf[256];
  459. ::ZeroMemory(&hdItem, sizeof(hdItem));
  460. hdItem.mask = HDI_TEXT | HDI_HEIGHT;
  461. szBuf[0] = (CHAR)0x00;
  462. hdItem.pszText = szBuf;
  463. hdItem.cchTextMax = sizeof(szBuf);
  464. ::SendMessageA(lpdis->hwndItem,
  465. HDM_GETITEMA,
  466. (WPARAM)lpdis->itemID,
  467. (LPARAM)&hdItem);
  468. //Dbg(("%d: %s\n", lpdis->itemID, szBuf));
  469. MultiByteToWideChar(lpPlvData->codePage,
  470. MB_PRECOMPOSED,
  471. szBuf, -1,
  472. (WCHAR*)wchBuf, sizeof(wchBuf)/sizeof(WCHAR) );
  473. }
  474. #endif // UNDER_CE
  475. SIZE size;
  476. INT offsetX, offsetY;
  477. HFONT hFontPrev = NULL;
  478. if(lpPlvData->hFontHeader) {
  479. hFontPrev = (HFONT)::SelectObject(lpdis->hDC, lpPlvData->hFontHeader);
  480. }
  481. ::ExGetTextExtentPoint32W(lpdis->hDC,
  482. wchBuf,
  483. lstrlenW(wchBuf),
  484. &size);
  485. offsetX = GetSystemMetrics(SM_CXDLGFRAME);
  486. offsetY = (lpdis->rcItem.bottom - lpdis->rcItem.top - size.cy)/2;
  487. ::ExExtTextOutW(lpdis->hDC,
  488. lpdis->rcItem.left+offsetX,
  489. lpdis->rcItem.top+offsetY,
  490. ETO_CLIPPED,
  491. &lpdis->rcItem,
  492. wchBuf,
  493. lstrlenW(wchBuf),
  494. NULL);
  495. if(lpPlvData->hFontHeader) {
  496. ::SelectObject(lpdis->hDC, hFontPrev);
  497. }
  498. }
  499. break;
  500. default:
  501. break;
  502. }
  503. return TRUE;
  504. UnrefForMsg();
  505. }
  506. static LRESULT CmdDefault(HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl)
  507. {
  508. return 0;
  509. UnrefForCmd();
  510. }
  511. #ifdef MSAA
  512. static LRESULT MsgGetObject(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  513. {
  514. LPPLVDATA lpPlvData = GetPlvDataFromHWND(hwnd);
  515. if(!PLV_IsMSAAAvailable(lpPlvData))
  516. return E_FAIL;
  517. if(!lpPlvData->bReadyForWMGetObject)
  518. return E_FAIL;
  519. if(OBJID_CLIENT == lParam) {
  520. if(!lpPlvData->pAccPLV){
  521. lpPlvData->pAccPLV = new CAccPLV;
  522. if(!lpPlvData->pAccPLV)
  523. return (LRESULT)E_OUTOFMEMORY;
  524. HRESULT hr;
  525. hr = lpPlvData->pAccPLV->Initialize(hwnd);
  526. if(FAILED(hr)){
  527. delete lpPlvData->pAccPLV;
  528. lpPlvData->pAccPLV = NULL;
  529. return (LRESULT)hr;
  530. }
  531. PLV_NotifyWinEvent(lpPlvData,
  532. EVENT_OBJECT_CREATE,
  533. hwnd,
  534. OBJID_CLIENT,
  535. CHILDID_SELF);
  536. }
  537. return lpPlvData->pAccPLV->LresultFromObject(wParam);
  538. }
  539. return (HRESULT)0L;
  540. UnrefForMsg();
  541. }
  542. static LRESULT MsgShowWindow(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  543. {
  544. LPPLVDATA lpPlvData = GetPlvDataFromHWND(hwnd);
  545. if(PLV_IsMSAAAvailable(lpPlvData))
  546. {
  547. if(!lpPlvData->bReadyForWMGetObject)
  548. lpPlvData->bReadyForWMGetObject = TRUE;
  549. PLV_NotifyWinEvent(lpPlvData ,
  550. wParam ? EVENT_OBJECT_SHOW : EVENT_OBJECT_HIDE,
  551. hwnd,
  552. OBJID_CLIENT,
  553. CHILDID_SELF );
  554. }
  555. return DispDefault(msdiMain.edwp, hwnd, uMsg, wParam, lParam);
  556. }
  557. #endif