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.

1615 lines
47 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 "plv.h"
  7. #include "plv_.h"
  8. #include "plvproc.h"
  9. #include "dbg.h"
  10. #include "strutil.h"
  11. #include "repview.h"
  12. #include "iconview.h"
  13. #ifdef UNDER_CE // Windows CE specific
  14. #include "stub_ce.h" // Windows CE stub for unsupported APIs
  15. #endif // UNDER_CE
  16. #ifdef MSAA
  17. #pragma message("->plv.cpp:MSAA supported.")
  18. #include "accplv.h"
  19. #include "ivmisc.h"
  20. #include "rvmisc.h"
  21. #endif // MSAA
  22. #ifdef UNDER_CE
  23. #ifdef FE_JAPANESE
  24. #define MS_MINCHO_J TEXT("\xff2d\xff33 \x660e\x671d") // �l�r ����
  25. #define MS_GOTHIC_J TEXT("\xff2d\xff33 \x30b4\x30b7\x30c3\x30af") // �l�r �S�V�b�N
  26. #elif FE_KOREAN
  27. #define GULIM_KO TEXT("\xad74\xb9bc") // Gulim
  28. #define BATANG_KO TEXT("\xbc14\xd0d5") // Batang
  29. #endif
  30. #else // UNDER_CE
  31. #ifdef FE_KOREAN
  32. #define GULIM_KO "\xb1\xbc\xb8\xb2" // Gulim
  33. #define BATANG_KO "\xb9\xd9\xc5\xc1" // Batang
  34. #endif
  35. #endif
  36. // Safe String
  37. #define STRSAFE_NO_DEPRECATE
  38. #include "strsafe.h"
  39. extern LPPLVDATA PLV_Initialize(VOID);
  40. extern VOID PLV_Destroy(LPPLVDATA lpPlv);
  41. extern INT PLV_SetScrollInfo(HWND hwnd, INT nMin, INT nMax, INT nPage, INT nPos);
  42. extern INT PLV_GetScrollTrackPos(HWND hwnd);
  43. #ifdef UNDER_CE // In Windows CE, all window classes are process global.
  44. static LPCTSTR MakeClassName(HINSTANCE hInst, LPTSTR lpszBuf)
  45. {
  46. // make module unique name
  47. TCHAR szFileName[MAX_PATH];
  48. GetModuleFileName(hInst, szFileName, MAX_PATH);
  49. LPTSTR lpszFName = _tcsrchr(szFileName, TEXT('\\'));
  50. if(lpszFName) *lpszFName = TEXT('_');
  51. StringCchCopy(lpszBuf, MAX_PATH, WC_PADLISTVIEW);
  52. StringCchCat(lpszBuf, MAX_PATH, lpszFName);
  53. return lpszBuf;
  54. }
  55. BOOL PadListView_UnregisterClass(HINSTANCE hInst)
  56. {
  57. TCHAR szClassName[MAX_PATH];
  58. return UnregisterClass(MakeClassName(hInst, szClassName), hInst);
  59. }
  60. #endif // UNDER_CE
  61. //----------------------------------------------------------------
  62. // Public API Declare
  63. //----------------------------------------------------------------
  64. //////////////////////////////////////////////////////////////////
  65. // Function : PadListView_RegisterClass
  66. // Type : static ATOM
  67. // Purpose :
  68. // Args :
  69. // : HINSTANCE hInst
  70. // : LPSTR lpstrClass
  71. // : WNDPROC lpfnWndProc
  72. // Return :
  73. // DATE :
  74. //////////////////////////////////////////////////////////////////
  75. #ifndef UNDER_CE
  76. static BOOL PadListView_RegisterClass(HINSTANCE hInst, LPSTR lpstrClass, WNDPROC lpfnWndProc)
  77. #else // UNDER_CE
  78. static BOOL PadListView_RegisterClass(HINSTANCE hInst, LPTSTR lpstrClass, WNDPROC lpfnWndProc)
  79. #endif // UNDER_CE
  80. {
  81. ATOM ret;
  82. #ifndef UNDER_CE // Windows CE does not support EX
  83. static WNDCLASSEX wc;
  84. #else // UNDER_CE
  85. WNDCLASS wc;
  86. #endif // UNDER_CE
  87. //----------------------------------------------------------------
  88. //check specified class is already exist or not
  89. //----------------------------------------------------------------
  90. #ifndef UNDER_CE // Windows CE does not support EX
  91. if(GetClassInfoEx(hInst, lpstrClass, &wc)){
  92. #else // UNDER_CE
  93. if(GetClassInfo(hInst, lpstrClass, &wc)){
  94. #endif // UNDER_CE
  95. //lpstrClass is already registerd.
  96. return TRUE;
  97. }
  98. ZeroMemory(&wc, sizeof(wc));
  99. #ifndef UNDER_CE // Windows CE does not support EX
  100. wc.cbSize = sizeof(wc);
  101. #endif // UNDER_CE
  102. wc.style = CS_HREDRAW | CS_VREDRAW; /* Class style(s). */
  103. wc.lpfnWndProc = (WNDPROC)lpfnWndProc;
  104. wc.cbClsExtra = 0; /* No per-class extra data.*/
  105. wc.cbWndExtra = sizeof(LPVOID); /* No per-window extra data. */
  106. wc.hInstance = hInst; /* Application that owns the class. */
  107. wc.hIcon = NULL; //LoadIcon(hInstance, MAKEINTRESOURCE(SCROLL32_ICON));
  108. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  109. //wc.hbrBackground = (HBRUSH)(COLOR_3DFACE+1);
  110. //wc.hbrBackground = (HBRUSH)(COLOR_3DFACE+1);
  111. //wc.hbrBackground = GetStockObject(WHITE_BRUSH);
  112. wc.lpszMenuName = NULL; //g_szClass; /* Name of menu resource in .RC file. */
  113. wc.lpszClassName = lpstrClass; /* Name used in call to CreateWindow. */
  114. #ifndef UNDER_CE // Windows CE does not support EX
  115. wc.hIconSm = NULL;
  116. ret = RegisterClassEx(&wc);
  117. #else // UNDER_CE
  118. ret = RegisterClass(&wc);
  119. #endif // UNDER_CE
  120. return ret ? TRUE: FALSE;
  121. }
  122. //////////////////////////////////////////////////////////////////
  123. // Function : PadListView_CreateWindow
  124. // Type : HWND
  125. // Purpose :
  126. // Args :
  127. // : HINSTANCE hInst
  128. // : HWND hwndParent
  129. // : INT x
  130. // : INT y
  131. // : INT width
  132. // : INT height
  133. // : UINT uNotifyMsg
  134. // Return :
  135. // DATE :
  136. //////////////////////////////////////////////////////////////////
  137. HWND WINAPI PadListView_CreateWindow(HINSTANCE hInst,
  138. HWND hwndParent,
  139. INT wID,
  140. INT x,
  141. INT y,
  142. INT width,
  143. INT height,
  144. UINT uNotifyMsg)
  145. {
  146. HWND hwnd;
  147. #ifndef UNDER_CE // In Windows CE, all window classes are process global.
  148. BOOL ret = PadListView_RegisterClass(hInst, WC_PADLISTVIEW, PlvWndProc);
  149. #else // UNDER_CE
  150. TCHAR szClassName[MAX_PATH];
  151. MakeClassName(hInst, szClassName);
  152. BOOL ret = PadListView_RegisterClass(hInst, szClassName, PlvWndProc);
  153. #endif // UNDER_CE
  154. if(!ret) {
  155. Dbg(("Failed to Regiset class[%s]\n", WC_PADLISTVIEW));
  156. return NULL;
  157. }
  158. LPPLVDATA lpPlvData = PLV_Initialize();
  159. if(!lpPlvData) {
  160. Dbg(("Internal ERROR\n"));
  161. return NULL;
  162. }
  163. lpPlvData->hInst = hInst;
  164. lpPlvData->uMsg = uNotifyMsg;
  165. hwnd = CreateWindowEx(WS_EX_CLIENTEDGE,
  166. #ifndef UNDER_CE // All CE window class is process global.
  167. WC_PADLISTVIEW,
  168. WC_PADLISTVIEW,
  169. #else // UNDER_CE
  170. szClassName,
  171. szClassName,
  172. #endif // UNDER_CE
  173. WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
  174. x, y,
  175. width,
  176. height,
  177. hwndParent,
  178. (HMENU)(UINT_PTR)wID,
  179. hInst,
  180. (LPVOID)lpPlvData);
  181. if(!hwnd) {
  182. Dbg(("Create Window Failed \n"));
  183. return NULL;
  184. }
  185. return hwnd;
  186. }
  187. //////////////////////////////////////////////////////////////////
  188. // Function : PadListView_GetItemCount
  189. // Type : INT
  190. // Purpose :
  191. // Args :
  192. // : HWND hwnd
  193. // Return :
  194. // DATE :
  195. //////////////////////////////////////////////////////////////////
  196. INT WINAPI PadListView_GetItemCount(HWND hwnd)
  197. {
  198. LPPLVDATA lpPlvData = GetPlvDataFromHWND(hwnd);
  199. if(!lpPlvData) {
  200. Dbg(("Internal ERROR\n"));
  201. return 0;
  202. }
  203. return lpPlvData->iItemCount;
  204. }
  205. //////////////////////////////////////////////////////////////////
  206. // Function : PadListView_SetItemCount
  207. // Type : INT
  208. // Purpose : Set total Item's count to PadListView.
  209. // : it effect's scroll bar.
  210. // Args :
  211. // : HWND hwnd
  212. // : INT itemCount
  213. // Return :
  214. // DATE :
  215. //////////////////////////////////////////////////////////////////
  216. INT WINAPI PadListView_SetItemCount(HWND hwnd, INT itemCount)
  217. {
  218. LPPLVDATA lpPlvData = GetPlvDataFromHWND(hwnd);
  219. if(!lpPlvData) {
  220. Dbg(("Internal ERROR\n"));
  221. return 0;
  222. }
  223. if(lpPlvData->dwStyle == PLVSTYLE_ICON) {
  224. IconView_SetItemCount(lpPlvData, itemCount, TRUE);
  225. RepView_SetItemCount(lpPlvData, itemCount, FALSE);
  226. }
  227. else if(lpPlvData->dwStyle == PLVSTYLE_REPORT) {
  228. IconView_SetItemCount(lpPlvData, itemCount, FALSE);
  229. RepView_SetItemCount(lpPlvData, itemCount, TRUE);
  230. }
  231. PadListView_Update(hwnd);
  232. return 0;
  233. Unref(itemCount);
  234. }
  235. //////////////////////////////////////////////////////////////////
  236. // Function : PadListView_SetExplanationText
  237. // Type : INT
  238. // Purpose : set the PadListView's text .
  239. // Args :
  240. // : HWND hwnd
  241. // : LPSTR lpText
  242. // Return :
  243. // DATE :
  244. //////////////////////////////////////////////////////////////////
  245. extern INT WINAPI PadListView_SetExplanationText(HWND hwnd, LPSTR lpText)
  246. {
  247. LPPLVDATA lpPlvData = GetPlvDataFromHWND(hwnd);
  248. lpPlvData->lpText = lpText; // lpText must point to a static data
  249. PadListView_Update(hwnd);
  250. return 0;
  251. }
  252. //////////////////////////////////////////////////////////////////
  253. // Function : PadListView_SetExplanationTextW
  254. // Type : INT
  255. // Purpose : set the PadListView's text .
  256. // Args :
  257. // : HWND hwnd
  258. // : LPWSTR lpText
  259. // Return :
  260. // DATE :
  261. //////////////////////////////////////////////////////////////////
  262. extern INT WINAPI PadListView_SetExplanationTextW(HWND hwnd, LPWSTR lpwText)
  263. {
  264. LPPLVDATA lpPlvData = GetPlvDataFromHWND(hwnd);
  265. lpPlvData->lpwText = lpwText; // lpText must point to a static data
  266. PadListView_Update(hwnd);
  267. return 0;
  268. }
  269. //////////////////////////////////////////////////////////////////
  270. // Function : PadListView_SetTopIndex
  271. // Type : INT
  272. // Purpose :
  273. // Args :
  274. // : HWND hwnd
  275. // : INT indexTop
  276. // Return :
  277. // DATE :
  278. //////////////////////////////////////////////////////////////////
  279. INT WINAPI PadListView_SetTopIndex(HWND hwnd, INT indexTop)
  280. {
  281. LPPLVDATA lpPlvData = GetPlvDataFromHWND(hwnd);
  282. if(!lpPlvData) {
  283. Dbg(("Internal ERROR\n"));
  284. return 0;
  285. }
  286. if(lpPlvData->dwStyle == PLVSTYLE_ICON) {
  287. return IconView_SetTopIndex(lpPlvData, indexTop);
  288. }
  289. else if(lpPlvData->dwStyle == PLVSTYLE_REPORT) {
  290. return RepView_SetTopIndex(lpPlvData, indexTop);
  291. }
  292. else {
  293. Dbg(("Internal ERROR\n"));
  294. }
  295. return 0;
  296. }
  297. //////////////////////////////////////////////////////////////////
  298. // Function : PadListView_GetTopIndex
  299. // Type : INT
  300. // Purpose :
  301. // Args :
  302. // : HWND hwnd
  303. // Return :
  304. // DATE :
  305. //////////////////////////////////////////////////////////////////
  306. INT WINAPI PadListView_GetTopIndex(HWND hwnd)
  307. {
  308. LPPLVDATA lpPlvData = GetPlvDataFromHWND(hwnd);
  309. if(!lpPlvData) {
  310. Dbg(("Internal ERROR\n"));
  311. return 0;
  312. }
  313. if(lpPlvData->dwStyle == PLVSTYLE_ICON) {
  314. return lpPlvData->iCurIconTopIndex;
  315. }
  316. else {
  317. return lpPlvData->iCurTopIndex;
  318. }
  319. }
  320. //////////////////////////////////////////////////////////////////
  321. // Function : PadListView_SetIconItemCallback
  322. // Type : INT
  323. // Purpose : Set user defined Function that gets each Item's string
  324. // Args :
  325. // : HWND hwnd
  326. // : LPARAM lParam
  327. // : LPFNPLVITEMCALLBACK lpfnPlvItemCallback
  328. // Return :
  329. // DATE :
  330. //////////////////////////////////////////////////////////////////
  331. INT WINAPI PadListView_SetIconItemCallback(HWND hwnd, LPARAM lParam, LPFNPLVICONITEMCALLBACK lpfnPlvIconItemCallback)
  332. {
  333. LPPLVDATA lpPlvData = GetPlvDataFromHWND(hwnd);
  334. if(!lpPlvData) {
  335. Dbg(("Internal ERROR\n"));
  336. return 0;
  337. }
  338. lpPlvData->iconItemCallbacklParam = lParam;
  339. lpPlvData->lpfnPlvIconItemCallback = lpfnPlvIconItemCallback;
  340. return 0;
  341. }
  342. //////////////////////////////////////////////////////////////////
  343. // Function : PadListView_SetReportItemCallback
  344. // Type : INT
  345. // Purpose : Set user defined Function that gets each column's string
  346. // : in Report view.
  347. // Args :
  348. // : HWND hwnd
  349. // : LPFNPLVCOLITEMCALLBACK lpfnColItemCallback
  350. // Return :
  351. // DATE :
  352. //////////////////////////////////////////////////////////////////
  353. INT WINAPI PadListView_SetReportItemCallback(HWND hwnd, LPARAM lParam, LPFNPLVREPITEMCALLBACK lpfnPlvRepItemCallback)
  354. {
  355. LPPLVDATA lpPlvData = GetPlvDataFromHWND(hwnd);
  356. if(!lpPlvData) {
  357. Dbg(("Internal ERROR\n"));
  358. return 0;
  359. }
  360. lpPlvData->repItemCallbacklParam = lParam;
  361. lpPlvData->lpfnPlvRepItemCallback = lpfnPlvRepItemCallback;
  362. return 0;
  363. }
  364. typedef struct tagFONTINFO {
  365. LPTSTR lpstrFontName;
  366. BOOL fFound;
  367. LPLOGFONT lpLogFont;
  368. }FONTINFO, *LPFONTINFO;
  369. static INT CALLBACK EnumFontFamProc(ENUMLOGFONT *lpElf,
  370. NEWTEXTMETRIC *lpNtm,
  371. INT iFontType,
  372. LPARAM lParam)
  373. {
  374. //Dbg(("EnumFontFamProc font[%s]\n", lpElf->elfLogFont.lfFaceName));
  375. #ifndef UNDER_CE // always Unicode
  376. if(0 == StrcmpA(lpElf->elfLogFont.lfFaceName, ((FONTINFO *)lParam)->lpstrFontName)) {
  377. #else // UNDER_CE
  378. if(0 == lstrcmp(lpElf->elfLogFont.lfFaceName, ((FONTINFO *)lParam)->lpstrFontName)) {
  379. #endif // UNDER_CE
  380. *((LPFONTINFO)lParam)->lpLogFont = lpElf->elfLogFont;
  381. ((LPFONTINFO)lParam)->fFound = TRUE;
  382. return 0;
  383. }
  384. return 1;
  385. Unref(lpNtm);
  386. Unref(iFontType);
  387. }
  388. static INT GetLogFont(HDC hDC, LPTSTR lpstrFaceName, LOGFONT *plf)
  389. {
  390. static FONTINFO fontInfo;
  391. if(!lpstrFaceName) {
  392. Dbg(("GetLogFont Error lpstrFaceName is NULL\n"));
  393. return -1;
  394. }
  395. if(lstrlen(lpstrFaceName) >= LF_FACESIZE) {
  396. Dbg(("GetLogFont Error length invalid\n"));
  397. return -1;
  398. }
  399. if(!plf) {
  400. Dbg(("GetLogFont Error plf is NULL\n"));
  401. return -1;
  402. }
  403. ZeroMemory(&fontInfo, sizeof(fontInfo));
  404. fontInfo.lpstrFontName = lpstrFaceName;
  405. fontInfo.lpLogFont = plf;
  406. EnumFontFamilies(hDC, NULL, (FONTENUMPROC)EnumFontFamProc, (LPARAM)&fontInfo);
  407. if(fontInfo.fFound) {
  408. return 0;
  409. }
  410. else {
  411. return -1;
  412. }
  413. }
  414. typedef struct tagFONTINFOEX {
  415. LPTSTR lpstrFontName;
  416. INT charSet;
  417. BOOL fFound;
  418. LPLOGFONT lpLogFont;
  419. }FONTINFOEX, *LPFONTINFOEX;
  420. static INT CALLBACK EnumFontFamProcEx(ENUMLOGFONT *lpElf,
  421. NEWTEXTMETRIC *lpNtm,
  422. INT iFontType,
  423. LPARAM lParam)
  424. {
  425. //Dbg(("EnumFontFamProc font[%s]\n", lpElf->elfLogFont.lfFaceName));
  426. if(0 == StrcmpA(lpElf->elfLogFont.lfFaceName, ((FONTINFOEX *)lParam)->lpstrFontName)) {
  427. if((BYTE)((FONTINFOEX *)lParam)->charSet == lpElf->elfLogFont.lfCharSet) {
  428. *((LPFONTINFOEX)lParam)->lpLogFont = lpElf->elfLogFont;
  429. ((LPFONTINFOEX)lParam)->fFound = TRUE;
  430. return 0;
  431. }
  432. }
  433. return 1;
  434. Unref(lpNtm);
  435. Unref(iFontType);
  436. }
  437. static INT GetLogFontEx(HDC hDC,
  438. LPTSTR lpstrFaceName,
  439. INT charSet,
  440. LOGFONT *plf)
  441. {
  442. Dbg(("!!!!!! GetLogFont charSet[%d]\n", charSet));
  443. static FONTINFOEX fontInfo;
  444. if(!lpstrFaceName) {
  445. Dbg(("GetLogFont Error lpstrFaceName is NULL\n"));
  446. return -1;
  447. }
  448. if(lstrlen(lpstrFaceName) >= LF_FACESIZE) {
  449. Dbg(("GetLogFont Error length invalid\n"));
  450. return -1;
  451. }
  452. if(!plf) {
  453. Dbg(("GetLogFont Error plf is NULL\n"));
  454. return -1;
  455. }
  456. ZeroMemory(&fontInfo, sizeof(fontInfo));
  457. fontInfo.lpstrFontName = lpstrFaceName;
  458. fontInfo.charSet = charSet;
  459. fontInfo.lpLogFont = plf;
  460. static LOGFONT logFont;
  461. ZeroMemory(&logFont, sizeof(logFont));
  462. logFont.lfCharSet = (BYTE)charSet,
  463. #ifndef UNDER_CE
  464. StrcpyA(logFont.lfFaceName, lpstrFaceName);
  465. #else // UNDER_CE
  466. lstrcpy(logFont.lfFaceName, lpstrFaceName);
  467. #endif // UNDER_CE
  468. #ifndef UNDER_CE // Windows CE does not support EnumFontFamiliesEx
  469. EnumFontFamiliesEx(hDC,
  470. &logFont,
  471. (FONTENUMPROC)EnumFontFamProcEx,
  472. (LPARAM)&fontInfo,
  473. 0);
  474. #else // UNDER_CE
  475. EnumFontFamilies(hDC,
  476. logFont.lfFaceName,
  477. (FONTENUMPROC)EnumFontFamProcEx,
  478. (LPARAM)&fontInfo);
  479. #endif // UNDER_CE
  480. if(fontInfo.fFound) {
  481. return 0;
  482. }
  483. else {
  484. return -1;
  485. }
  486. }
  487. //////////////////////////////////////////////////////////////////
  488. // Function : PadListView_SetIconFont
  489. // Type : INT
  490. // Purpose : Set specifed Font for ICON View.
  491. // Args :
  492. // : HWND hwnd
  493. // : LPSTR lpstrFontName
  494. // : INT point
  495. // Return :
  496. // DATE :
  497. //////////////////////////////////////////////////////////////////
  498. #define ABS(a) (a > 0 ? a: -a)
  499. //for do not use stack.
  500. static TEXTMETRIC g_tm;
  501. static LOGFONT g_logFont;
  502. INT WINAPI PadListView_SetIconFont(HWND hwnd, LPTSTR lpstrFontName, INT point)
  503. {
  504. Dbg(("PadListView_SetIconFont START font[%s] point[%d]\n", lpstrFontName, point));
  505. LPPLVDATA lpPlvData = GetPlvDataFromHWND(hwnd);
  506. if(!lpPlvData) {
  507. Dbg(("PadListView_SetIconFont ERROR\n"));
  508. return 0;
  509. }
  510. HFONT hFont;
  511. HDC hDC = GetDC(hwnd);
  512. INT dpi = GetDeviceCaps(hDC, LOGPIXELSY);
  513. if(-1 == GetLogFont(hDC, lpstrFontName, &g_logFont)) {
  514. Dbg(("GetLogFont Error [%s]\n", lpstrFontName));
  515. #ifndef UNDER_CE
  516. #ifdef FE_JAPANESE
  517. if(0 == lstrcmp(lpstrFontName, "�l�r ����")) {
  518. GetLogFont(hDC, "MS Mincho", &g_logFont);
  519. }
  520. else if(0 == lstrcmp(lpstrFontName, "�l�r �S�V�b�N")) {
  521. GetLogFont(hDC, "MS Gothic", &g_logFont);
  522. }
  523. #elif FE_KOREAN
  524. if(0 == lstrcmp(lpstrFontName, GULIM_KO)) {
  525. GetLogFont(hDC, "Gulim", &g_logFont);
  526. }
  527. else if(0 == lstrcmp(lpstrFontName, BATANG_KO)) {
  528. GetLogFont(hDC, "Batang", &g_logFont);
  529. }
  530. #else
  531. return (-1);
  532. #endif
  533. #else // UNDER_CE
  534. #ifdef FE_JAPANESE
  535. if(0 == lstrcmp(lpstrFontName, MS_MINCHO_J)) {
  536. GetLogFont(hDC, TEXT("MS Mincho"), &g_logFont);
  537. }
  538. else if(0 == lstrcmp(lpstrFontName, MS_GOTHIC_J)) {
  539. GetLogFont(hDC, TEXT("MS Gothic"), &g_logFont);
  540. }
  541. #elif FE_KOREAN
  542. if(0 == lstrcmp(lpstrFontName, GULIM_KO)) {
  543. GetLogFont(hDC, TEXT("Gulim"), &g_logFont);
  544. }
  545. else if(0 == lstrcmp(lpstrFontName, BATANG_KO)) {
  546. GetLogFont(hDC, TEXT("Batang"), &g_logFont);
  547. }
  548. #else
  549. return (-1);
  550. #endif
  551. #endif // UNDER_CE
  552. }
  553. ReleaseDC(hwnd, hDC);
  554. //----------------------------------------------------------------
  555. //Set new size
  556. //----------------------------------------------------------------
  557. g_logFont.lfHeight = - (point * dpi)/72;
  558. g_logFont.lfWidth = 0; // Calcurated automatically by lfHeight.
  559. hFont = CreateFontIndirect(&g_logFont);
  560. if(!hFont) {
  561. Dbg(("CreatFontIndirect Error\n"));
  562. return -1;
  563. }
  564. if(lpPlvData->hFontIcon) {
  565. DeleteObject(lpPlvData->hFontIcon);
  566. }
  567. lpPlvData->iFontPointIcon = point;
  568. lpPlvData->hFontIcon = hFont;
  569. //If font point changed, also changes itemWidth & itemHeight
  570. lpPlvData->nItemWidth = ABS(g_logFont.lfHeight) + XRECT_MARGIN*2;
  571. lpPlvData->nItemHeight = ABS(g_logFont.lfHeight) + YRECT_MARGIN*2;
  572. PadListView_Update(hwnd);
  573. Dbg(("PadListView_SetFont END\n"));
  574. #if 0
  575. HFONT hFont;
  576. //use global data logfont, TextMetrics
  577. ZeroMemory(&g_logFont, sizeof(g_logFont));
  578. ZeroMemory(&g_tm, sizeof(g_tm));
  579. HDC hDC = GetDC(hwnd);
  580. if(!hDC) {
  581. Dbg(("PadListView_SetIconFont ERROR\n"));
  582. return -1;
  583. }
  584. GetTextMetrics(hDC, &g_tm);
  585. INT dpi = GetDeviceCaps(hDC, LOGPIXELSY);
  586. ReleaseDC(hwnd, hDC);
  587. g_logFont.lfHeight = - (point * dpi)/72;
  588. g_logFont.lfCharSet = DEFAULT_CHARSET; //g_tm.tmCharSet;
  589. g_logFont.lfPitchAndFamily = g_tm.tmPitchAndFamily;
  590. Dbg(("g_logFont.lfHeight = %d\n", g_logFont.lfHeight));
  591. Dbg(("g_logFont.lfCharSet = %d\n", g_logFont.lfCharSet));
  592. Dbg(("g_logFont.lfPitchAndFamily = %d\n", g_logFont.lfPitchAndFamily));
  593. StrcpyA(g_logFont.lfFaceName, lpstrFontName);
  594. hFont = CreateFontIndirect(&g_logFont);
  595. if(!hFont) {
  596. Dbg(("CreatFontIndirect Error\n"));
  597. return -1;
  598. }
  599. if(lpPlvData->hFontIcon) {
  600. DeleteObject(lpPlvData->hFontIcon);
  601. }
  602. lpPlvData->iFontPointIcon = point;
  603. lpPlvData->hFontIcon = hFont;
  604. //If font point changed, also changes itemWidth & itemHeight
  605. lpPlvData->nItemWidth = ABS(g_logFont.lfHeight) + XRECT_MARGIN*2;
  606. lpPlvData->nItemHeight = ABS(g_logFont.lfHeight) + YRECT_MARGIN*2;
  607. PadListView_Update(hwnd);
  608. Dbg(("PadListView_SetFont END\n"));
  609. #endif
  610. return 0;
  611. }
  612. //////////////////////////////////////////////////////////////////
  613. // Function : PadListView_SetReportFont
  614. // Type : INT
  615. // Purpose :
  616. // Args :
  617. // : HWND hwnd
  618. // : LPSTR lpstrFontName
  619. // : INT point
  620. // Return :
  621. // DATE :
  622. //////////////////////////////////////////////////////////////////
  623. INT WINAPI PadListView_SetReportFont(HWND hwnd, LPTSTR lpstrFontName, INT point)
  624. {
  625. Dbg(("PadListView_SetReportFont START\n"));
  626. LPPLVDATA lpPlvData = GetPlvDataFromHWND(hwnd);
  627. if(!lpPlvData) {
  628. Dbg(("PadListView_SetReportFont ERROR\n"));
  629. return 0;
  630. }
  631. HFONT hFont;
  632. ZeroMemory(&g_logFont, sizeof(g_logFont));
  633. HDC hDC = GetDC(hwnd);
  634. INT dpi = GetDeviceCaps(hDC, LOGPIXELSY);
  635. if(-1 == GetLogFont(hDC, lpstrFontName, &g_logFont)) {
  636. Dbg(("GetLogFont Error [%s]\n", lpstrFontName));
  637. #ifndef UNDER_CE
  638. #ifdef FE_JAPANESE
  639. if(0 == lstrcmp(lpstrFontName, "�l�r ����")) {
  640. GetLogFont(hDC, "MS Mincho", &g_logFont);
  641. }
  642. else if(0 == lstrcmp(lpstrFontName, "�l�r �S�V�b�N")) {
  643. GetLogFont(hDC, "MS Gothic", &g_logFont);
  644. }
  645. #elif FE_KOREAN
  646. if(0 == lstrcmp(lpstrFontName, GULIM_KO)) {
  647. GetLogFont(hDC, "Gulim", &g_logFont);
  648. }
  649. else if(0 == lstrcmp(lpstrFontName, BATANG_KO)) {
  650. GetLogFont(hDC, "Batang", &g_logFont);
  651. }
  652. #else
  653. return (-1);
  654. #endif
  655. #else // UNDER_CE
  656. #ifdef FE_JAPANESE
  657. if(0 == lstrcmp(lpstrFontName, MS_MINCHO_J)) {
  658. GetLogFont(hDC, TEXT("MS Mincho"), &g_logFont);
  659. }
  660. else if(0 == lstrcmp(lpstrFontName, MS_GOTHIC_J)) {
  661. GetLogFont(hDC, TEXT("MS Gothic"), &g_logFont);
  662. }
  663. #elif FE_KOREAN
  664. if(0 == lstrcmp(lpstrFontName, GULIM_KO)) {
  665. GetLogFont(hDC, TEXT("Gulim"), &g_logFont);
  666. }
  667. else if(0 == lstrcmp(lpstrFontName, BATNANG_KO)) {
  668. GetLogFont(hDC, TEXT("Batang"), &g_logFont);
  669. }
  670. #else
  671. return (-1);
  672. #endif
  673. #endif // UNDER_CE
  674. }
  675. ReleaseDC(hwnd, hDC);
  676. g_logFont.lfHeight = - (point * dpi)/72;
  677. g_logFont.lfWidth = 0;
  678. hFont = CreateFontIndirect(&g_logFont);
  679. if(!hFont) {
  680. Dbg(("CreatFontIndirect Error\n"));
  681. return -1;
  682. }
  683. if(lpPlvData->hFontRep) {
  684. DeleteObject(lpPlvData->hFontRep);
  685. }
  686. lpPlvData->iFontPointRep = point;
  687. lpPlvData->hFontRep = hFont;
  688. //If font point changed, also changes itemWidth & itemHeight
  689. lpPlvData->nRepItemWidth = ABS(g_logFont.lfHeight) + PLV_REPRECT_XMARGIN*2;
  690. lpPlvData->nRepItemHeight = ABS(g_logFont.lfHeight) + PLV_REPRECT_YMARGIN*2;
  691. PadListView_Update(hwnd);
  692. return 0;
  693. #if 0
  694. HFONT hFont;
  695. HDC hDC = GetDC(hwnd);
  696. if(!hDC) {
  697. Dbg(("PadListView_SetReportFont ERROR\n"));
  698. return -1;
  699. }
  700. ZeroMemory(&g_tm, sizeof(g_tm));
  701. GetTextMetrics(hDC, &g_tm);
  702. INT dpi = GetDeviceCaps(hDC, LOGPIXELSY);
  703. ReleaseDC(hwnd, hDC);
  704. ZeroMemory(&g_logFont, sizeof(g_logFont));
  705. g_logFont.lfHeight = - (point * dpi)/72;
  706. g_logFont.lfCharSet = DEFAULT_CHARSET; //g_tm.tmCharSet;
  707. g_logFont.lfPitchAndFamily = g_tm.tmPitchAndFamily;
  708. Dbg(("g_logFont.lfHeight = %d\n", g_logFont.lfHeight));
  709. Dbg(("g_logFont.lfCharSet = %d\n", g_logFont.lfCharSet));
  710. Dbg(("g_logFont.lfPitchAndFamily = %d\n", g_logFont.lfPitchAndFamily));
  711. StrcpyA(g_logFont.lfFaceName, lpstrFontName);
  712. hFont = CreateFontIndirect(&g_logFont);
  713. if(!hFont) {
  714. Dbg(("CreatFontIndirect Error\n"));
  715. return -1;
  716. }
  717. if(lpPlvData->hFontRep) {
  718. DeleteObject(lpPlvData->hFontRep);
  719. }
  720. lpPlvData->iFontPointRep = point;
  721. lpPlvData->hFontRep = hFont;
  722. //If font point changed, also changes itemWidth & itemHeight
  723. lpPlvData->nRepItemWidth = ABS(g_logFont.lfHeight) + PLV_REPRECT_XMARGIN*2;
  724. lpPlvData->nRepItemHeight = ABS(g_logFont.lfHeight) + PLV_REPRECT_YMARGIN*2;
  725. PadListView_Update(hwnd);
  726. Dbg(("PadListView_SetFont END\n"));
  727. return 0;
  728. #endif
  729. }
  730. //
  731. ///
  732. //990126:toshiaK
  733. //////////////////////////////////////////////////////////////////
  734. // Function : PadListView_SetIconFontEx
  735. // Type : INT
  736. // Purpose : Set specifed Font for ICON View.
  737. // Args :
  738. // : HWND hwnd
  739. // : LPSTR lpstrFontName
  740. // : INT charSet
  741. // : INT point
  742. // Return :
  743. // DATE :
  744. //////////////////////////////////////////////////////////////////
  745. INT WINAPI PadListView_SetIconFontEx(HWND hwnd,
  746. LPTSTR lpstrFontName,
  747. INT charSet,
  748. INT point)
  749. {
  750. Dbg(("PadListView_SetIconFontEx START font[%s] point[%d]\n", lpstrFontName, point));
  751. LPPLVDATA lpPlvData = GetPlvDataFromHWND(hwnd);
  752. if(!lpPlvData) {
  753. Dbg(("PadListView_SetIconFont ERROR\n"));
  754. return 0;
  755. }
  756. HFONT hFont;
  757. HDC hDC = GetDC(hwnd);
  758. INT dpi = GetDeviceCaps(hDC, LOGPIXELSY);
  759. if(-1 == GetLogFontEx(hDC, lpstrFontName, charSet, &g_logFont)) {
  760. ReleaseDC(hwnd, hDC);
  761. return -1;
  762. }
  763. ReleaseDC(hwnd, hDC);
  764. //----------------------------------------------------------------
  765. //Set new size
  766. //----------------------------------------------------------------
  767. g_logFont.lfHeight = - (point * dpi)/72;
  768. g_logFont.lfWidth = 0; // Calcurated automatically by lfHeight.
  769. hFont = CreateFontIndirect(&g_logFont);
  770. if(!hFont) {
  771. Dbg(("CreatFontIndirect Error\n"));
  772. return -1;
  773. }
  774. if(lpPlvData->hFontIcon) {
  775. DeleteObject(lpPlvData->hFontIcon);
  776. }
  777. lpPlvData->iFontPointIcon = point;
  778. lpPlvData->hFontIcon = hFont;
  779. //If font point changed, also changes itemWidth & itemHeight
  780. lpPlvData->nItemWidth = ABS(g_logFont.lfHeight) + XRECT_MARGIN*2;
  781. lpPlvData->nItemHeight = ABS(g_logFont.lfHeight) + YRECT_MARGIN*2;
  782. PadListView_Update(hwnd);
  783. Dbg(("PadListView_SetFont END\n"));
  784. return 0;
  785. }
  786. //////////////////////////////////////////////////////////////////
  787. // Function : PadListView_SetReportFontEx
  788. // Type : INT
  789. // Purpose :
  790. // Args :
  791. // : HWND hwnd
  792. // : LPSTR lpstrFontName
  793. // : INT charSet
  794. // : INT point
  795. // Return :
  796. // DATE :
  797. //////////////////////////////////////////////////////////////////
  798. INT WINAPI PadListView_SetReportFontEx(HWND hwnd,
  799. LPTSTR lpstrFontName,
  800. INT charSet,
  801. INT point)
  802. {
  803. Dbg(("PadListView_SetReportFontEx START\n"));
  804. LPPLVDATA lpPlvData = GetPlvDataFromHWND(hwnd);
  805. if(!lpPlvData) {
  806. Dbg(("PadListView_SetReportFont ERROR\n"));
  807. return 0;
  808. }
  809. HFONT hFont;
  810. ZeroMemory(&g_logFont, sizeof(g_logFont));
  811. HDC hDC = GetDC(hwnd);
  812. INT dpi = GetDeviceCaps(hDC, LOGPIXELSY);
  813. if(-1 == GetLogFontEx(hDC, lpstrFontName, charSet, &g_logFont)) {
  814. ReleaseDC(hwnd, hDC);
  815. return -1;
  816. }
  817. ReleaseDC(hwnd, hDC);
  818. g_logFont.lfHeight = - (point * dpi)/72;
  819. g_logFont.lfWidth = 0;
  820. hFont = CreateFontIndirect(&g_logFont);
  821. if(!hFont) {
  822. Dbg(("CreatFontIndirect Error\n"));
  823. return -1;
  824. }
  825. if(lpPlvData->hFontRep) {
  826. DeleteObject(lpPlvData->hFontRep);
  827. }
  828. lpPlvData->iFontPointRep = point;
  829. lpPlvData->hFontRep = hFont;
  830. //If font point changed, also changes itemWidth & itemHeight
  831. lpPlvData->nRepItemWidth = ABS(g_logFont.lfHeight) + PLV_REPRECT_XMARGIN*2;
  832. lpPlvData->nRepItemHeight = ABS(g_logFont.lfHeight) + PLV_REPRECT_YMARGIN*2;
  833. PadListView_Update(hwnd);
  834. return 0;
  835. }
  836. //////////////////////////////////////////////////////////////////
  837. // Function : PadListView_SetStyle
  838. // Type : INT
  839. // Purpose : set the PadListView's style.
  840. // style is PLVSTYLE_LIST or PLVSTYLE_REPORT
  841. // Args :
  842. // : HWND hwnd
  843. // : INT style
  844. // Return :
  845. // DATE :
  846. //////////////////////////////////////////////////////////////////
  847. INT WINAPI PadListView_SetStyle(HWND hwnd, INT style)
  848. {
  849. LPPLVDATA lpPlvData = GetPlvDataFromHWND(hwnd);
  850. if(!lpPlvData) {
  851. Dbg(("PadListView_SetStyle ERROR\n"));
  852. return -1;
  853. }
  854. if(style != PLVSTYLE_ICON &&
  855. style != PLVSTYLE_REPORT) {
  856. Dbg(("Internal ERROR\n"));
  857. return -1;
  858. }
  859. lpPlvData->dwStyle = style;
  860. if(style == PLVSTYLE_ICON) {
  861. if(lpPlvData->hwndHeader) {
  862. //Hide header control
  863. SetWindowPos(lpPlvData->hwndHeader, NULL, 0, 0, 0, 0,
  864. SWP_NOZORDER | SWP_NOMOVE | SWP_NOSIZE | SWP_HIDEWINDOW);
  865. }
  866. IconView_RestoreScrollPos(lpPlvData);
  867. }
  868. else if(style == PLVSTYLE_REPORT) {
  869. if(lpPlvData->hwndHeader) {
  870. RECT rc;
  871. GetClientRect(lpPlvData->hwndSelf, &rc); // get PadListView's client rect
  872. HD_LAYOUT hdl;
  873. WINDOWPOS wp;
  874. hdl.prc = &rc;
  875. hdl.pwpos = &wp;
  876. //Calc header control window size
  877. if(Header_Layout(lpPlvData->hwndHeader, &hdl) == FALSE) {
  878. //OutputDebugString("Create Header Layout error\n");
  879. return NULL;
  880. }
  881. SetWindowPos(lpPlvData->hwndHeader, wp.hwndInsertAfter, wp.x, wp.y,
  882. wp.cx, wp.cy, wp.flags | SWP_SHOWWINDOW);
  883. }
  884. RepView_RestoreScrollPos(lpPlvData);
  885. }
  886. PadListView_Update(hwnd);
  887. return 0;
  888. }
  889. //////////////////////////////////////////////////////////////////
  890. // Function : PadListView_GetStyle
  891. // Type : INT
  892. // Purpose :
  893. // Args :
  894. // : HWND hwnd
  895. // Return :
  896. // DATE :
  897. //////////////////////////////////////////////////////////////////
  898. INT WINAPI PadListView_GetStyle(HWND hwnd)
  899. {
  900. LPPLVDATA lpPlvData = GetPlvDataFromHWND(hwnd);
  901. if(!lpPlvData) {
  902. Dbg(("PadListView_SetFont ERROR\n"));
  903. return -1;
  904. }
  905. return (INT)lpPlvData->dwStyle;
  906. }
  907. //////////////////////////////////////////////////////////////////
  908. // Function : PadListView_Update
  909. // Type : INT
  910. // Purpose : Repaint PadListView.
  911. // Args :
  912. // : HWND hwnd
  913. // Return :
  914. // DATE :
  915. //////////////////////////////////////////////////////////////////
  916. INT WINAPI PadListView_Update(HWND hwnd)
  917. {
  918. InvalidateRect(hwnd, NULL, TRUE);
  919. UpdateWindow(hwnd);
  920. return 0;
  921. }
  922. //////////////////////////////////////////////////////////////////
  923. // Function : PadListView_SetCurSel
  924. // Type : INT
  925. // Purpose : set cur selection. Move cursor to specified index.
  926. // :
  927. // Args :
  928. // : HWND hwnd
  929. // : LPSTR lpText
  930. // Return :
  931. // DATE :
  932. //////////////////////////////////////////////////////////////////
  933. INT WINAPI PadListView_SetCurSel(HWND hwnd, INT index)
  934. {
  935. LPPLVDATA lpPlvData = GetPlvDataFromHWND(hwnd);
  936. if(!lpPlvData) {
  937. return -1;
  938. }
  939. switch(lpPlvData->dwStyle) {
  940. case PLVSTYLE_ICON:
  941. IconView_SetCurSel(lpPlvData, index);
  942. break;
  943. case PLVSTYLE_REPORT:
  944. RepView_SetCurSel(lpPlvData, index);
  945. break;
  946. default:
  947. break;
  948. }
  949. return 0;
  950. }
  951. #if 0
  952. typedef struct _LV_COLUMNA
  953. {
  954. UINT mask; //LVCF_FMT, LVCF_WIDTH, LVCF_TEXT, LVCF_SUBITEM;
  955. int fmt;
  956. int cx;
  957. LPSTR pszText;
  958. int cchTextMax;
  959. int iSubItem;
  960. } LV_COLUMNA;
  961. #define HDI_WIDTH 0x0001
  962. #define HDI_HEIGHT HDI_WIDTH
  963. #define HDI_TEXT 0x0002
  964. #define HDI_FORMAT 0x0004
  965. #define HDI_LPARAM 0x0008
  966. #define HDI_BITMAP 0x0010
  967. #define HDF_LEFT 0
  968. #define HDF_RIGHT 1
  969. #define HDF_CENTER 2
  970. #define HDF_JUSTIFYMASK 0x0003
  971. #define HDF_RTLREADING 4
  972. #define LVCF_FMT 0x0001
  973. #define LVCF_WIDTH 0x0002
  974. #define LVCF_TEXT 0x0004
  975. #define LVCF_SUBITEM 0x0008
  976. #define LVCFMT_LEFT 0x0000
  977. #define LVCFMT_RIGHT 0x0001
  978. #define LVCFMT_CENTER 0x0002
  979. #define LVCFMT_JUSTIFYMASK 0x0003
  980. #endif
  981. //////////////////////////////////////////////////////////////////
  982. // Function : PadListView_InsertColumn
  983. // Type : INT
  984. // Purpose :
  985. // Args :
  986. // : HWND hwnd
  987. // : INT index
  988. // : PLV_COLUMN * lpPlvCol
  989. // Return :
  990. // DATE :
  991. //////////////////////////////////////////////////////////////////
  992. INT WINAPI PadListView_InsertColumn(HWND hwnd, INT index, PLV_COLUMN *lpPlvCol)
  993. {
  994. LPPLVDATA lpPlvData = GetPlvDataFromHWND(hwnd);
  995. if(!lpPlvData) {
  996. Dbg(("Internal ERROR\n"));
  997. return -1;
  998. }
  999. if(!lpPlvCol) {
  1000. Dbg(("Internal ERROR\n"));
  1001. return -1;
  1002. }
  1003. #ifndef UNDER_CE // always Unicode
  1004. if(::IsWindowUnicode(lpPlvData->hwndHeader)) {
  1005. #endif // UNDER_CE
  1006. static HD_ITEMW hdi;
  1007. #ifndef UNDER_CE // #ifndef UNICODE
  1008. static WCHAR wchBuf[256];
  1009. #endif // UNDER_CE
  1010. ZeroMemory(&hdi, sizeof(hdi));
  1011. if(lpPlvCol->mask & LVCF_FMT) { hdi.mask |= HDI_FORMAT; }
  1012. if(lpPlvCol->mask & LVCF_WIDTH) { hdi.mask |= HDI_WIDTH; }
  1013. if(lpPlvCol->mask & LVCF_TEXT) { hdi.mask |= HDI_TEXT; }
  1014. if(lpPlvCol->fmt & LVCFMT_LEFT) { hdi.fmt |= HDF_LEFT; }
  1015. if(lpPlvCol->fmt & LVCFMT_RIGHT) { hdi.fmt |= HDF_RIGHT; }
  1016. if(lpPlvCol->fmt & LVCFMT_CENTER) { hdi.fmt |= HDF_CENTER;}
  1017. if(lpPlvCol->fmt & LVCFMT_JUSTIFYMASK) { hdi.fmt |= HDF_JUSTIFYMASK;}
  1018. #ifndef UNDER_CE // #ifndef UNICODE
  1019. //----------------------------------------------------------------
  1020. //980728: for ActiveIME support. use lpPlvData->codePage to convert
  1021. //----------------------------------------------------------------
  1022. ::MultiByteToWideChar(lpPlvData->codePage,
  1023. MB_PRECOMPOSED,
  1024. lpPlvCol->pszText, -1,
  1025. (WCHAR*)wchBuf, sizeof(wchBuf)/sizeof(WCHAR) );
  1026. hdi.pszText = wchBuf; //lpPlvCol->pszText;
  1027. #else // UNDER_CE
  1028. hdi.pszText = lpPlvCol->pszText;
  1029. #endif // UNDER_CE
  1030. hdi.cxy = lpPlvCol->cx;
  1031. hdi.cchTextMax = lpPlvCol->cchTextMax;
  1032. hdi.fmt |= HDF_OWNERDRAW; //989727: always set ownerdraw
  1033. SendMessageW(lpPlvData->hwndHeader, HDM_INSERTITEMW, (WPARAM)index, (LPARAM)&hdi);
  1034. #ifndef UNDER_CE // always Unicode
  1035. }
  1036. else {
  1037. static HD_ITEMA hdi;
  1038. ZeroMemory(&hdi, sizeof(hdi));
  1039. if(lpPlvCol->mask & LVCF_FMT) { hdi.mask |= HDI_FORMAT; }
  1040. if(lpPlvCol->mask & LVCF_WIDTH) { hdi.mask |= HDI_WIDTH; }
  1041. if(lpPlvCol->mask & LVCF_TEXT) { hdi.mask |= HDI_TEXT; }
  1042. if(lpPlvCol->fmt & LVCFMT_LEFT) { hdi.fmt |= HDF_LEFT; }
  1043. if(lpPlvCol->fmt & LVCFMT_RIGHT) { hdi.fmt |= HDF_RIGHT; }
  1044. if(lpPlvCol->fmt & LVCFMT_CENTER) { hdi.fmt |= HDF_CENTER;}
  1045. if(lpPlvCol->fmt & LVCFMT_JUSTIFYMASK) { hdi.fmt |= HDF_JUSTIFYMASK;}
  1046. hdi.pszText = lpPlvCol->pszText;
  1047. hdi.cxy = lpPlvCol->cx;
  1048. hdi.cchTextMax = lpPlvCol->cchTextMax;
  1049. hdi.fmt |= HDF_OWNERDRAW; //989727: always set ownerdraw
  1050. Header_InsertItem(lpPlvData->hwndHeader, index, &hdi);
  1051. }
  1052. #endif // UNDER_CE
  1053. return 0;
  1054. }
  1055. //----------------------------------------------------------------
  1056. // Private API Declaration
  1057. //----------------------------------------------------------------
  1058. LPPLVDATA PLV_Initialize(VOID)
  1059. {
  1060. LPPLVDATA lpPlvData = (LPPLVDATA)MemAlloc(sizeof(PLVDATA));
  1061. if(!lpPlvData) {
  1062. Dbg(("Memory ERROR\n"));
  1063. return (LPPLVDATA)NULL;
  1064. }
  1065. ZeroMemory((LPVOID)lpPlvData, sizeof(PLVDATA));
  1066. //----------------------------------------------------------------
  1067. //IconView, Report view Common data.
  1068. //----------------------------------------------------------------
  1069. lpPlvData->dwSize = sizeof(PLVDATA); //this data size;
  1070. lpPlvData->dwStyle = PLVSTYLE_ICON; //Pad listview window style (PLVIF_XXXX)
  1071. lpPlvData->hwndSelf = NULL; //Pad listview window handle.
  1072. lpPlvData->iItemCount = 0; //Virtual total item Count. it effects scroll bar.
  1073. lpPlvData->iCurTopIndex = 0; //In report view top line..
  1074. lpPlvData->nCurScrollPos = 0; //In report view Current Scroll posision.
  1075. lpPlvData->iCurIconTopIndex = 0; //In icon view top line..
  1076. lpPlvData->nCurIconScrollPos= 0; //In icon view Scroll posision.
  1077. lpPlvData->uMsg = 0; // user notify message.
  1078. lpPlvData->iCapture = CAPTURE_NONE; //is mouse captured or not.
  1079. lpPlvData->ptCapture.x = 0; //LButton Down mouse point.
  1080. lpPlvData->ptCapture.y = 0; //LButton Down mouse point.
  1081. //----------------------------------------------------------------
  1082. //for Icon view
  1083. //----------------------------------------------------------------
  1084. lpPlvData->nItemWidth = PLVICON_DEFAULT_WIDTH; // List(Icon like )view's whole width.
  1085. lpPlvData->nItemHeight = PLVICON_DEFAULT_HEIGHT; // List(Icon like )view's whole height.
  1086. lpPlvData->iFontPointIcon = PLVICON_DEFAULT_FONTPOINT; // Icon View's font point.
  1087. lpPlvData->hFontIcon = NULL; // Icon View's font
  1088. lpPlvData->iconItemCallbacklParam = (LPARAM)0; // Callback data for LPFNPLVITEMCALLBACK
  1089. lpPlvData->lpfnPlvIconItemCallback = NULL; //Callback function for getting item by index.
  1090. //----------------------------------------------------------------
  1091. //for report view
  1092. //----------------------------------------------------------------
  1093. lpPlvData->hwndHeader = NULL; //Header control's window handle.
  1094. lpPlvData->nRepItemWidth = PLVREP_DEFAULT_WIDTH; //Report view's width
  1095. lpPlvData->nRepItemHeight = PLVREP_DEFAULT_HEIGHT; //Report view's height
  1096. lpPlvData->iFontPointRep = PLVREP_DEFAULT_FONTPOINT; // Report View's font point.
  1097. lpPlvData->hFontRep = NULL; // Report View's font
  1098. lpPlvData->repItemCallbacklParam = (LPARAM)0;
  1099. lpPlvData->lpfnPlvRepItemCallback = NULL; //Callback function for getting colitem by index.
  1100. lpPlvData->lpText = NULL;
  1101. lpPlvData->codePage = CP_ACP; //980727
  1102. #ifdef MSAA
  1103. PLV_InitMSAA(lpPlvData);
  1104. #endif
  1105. return lpPlvData;
  1106. }
  1107. VOID PLV_Destroy(LPPLVDATA lpPlv)
  1108. {
  1109. if(lpPlv) {
  1110. #ifdef MSAA
  1111. PLV_UninitMSAA(lpPlv);
  1112. #endif
  1113. MemFree(lpPlv);
  1114. }
  1115. return;
  1116. }
  1117. INT PLV_SetScrollInfo(HWND hwnd, INT nMin, INT nMax, INT nPage, INT nPos)
  1118. {
  1119. static SCROLLINFO scrInfo;
  1120. scrInfo.cbSize = sizeof(scrInfo);
  1121. scrInfo.fMask = SIF_PAGE | SIF_POS | SIF_RANGE;
  1122. scrInfo.nMin = nMin;
  1123. scrInfo.nMax = nMax-1;
  1124. scrInfo.nPage = nPage;
  1125. scrInfo.nPos = nPos;
  1126. scrInfo.nTrackPos = 0;
  1127. if((scrInfo.nMax - scrInfo.nMin +1) <= (INT)scrInfo.nPage) {
  1128. scrInfo.nMin = 0;
  1129. scrInfo.nMax = 1;
  1130. scrInfo.nPage = 1;
  1131. #ifndef UNDER_CE // Windows CE does not support EnableScrollBar
  1132. SetScrollInfo(hwnd, SB_VERT, &scrInfo, TRUE);
  1133. EnableScrollBar(hwnd, SB_VERT, ESB_DISABLE_BOTH);
  1134. #else // UNDER_CE
  1135. scrInfo.fMask |= SIF_DISABLENOSCROLL;
  1136. SetScrollInfo(hwnd, SB_VERT, &scrInfo, TRUE);
  1137. #endif // UNDER_CE
  1138. }
  1139. else {
  1140. #ifndef UNDER_CE // Windows CE does not support EnableScrollBar
  1141. EnableScrollBar(hwnd, SB_VERT, ESB_ENABLE_BOTH);
  1142. #endif // UNDER_CE
  1143. SetScrollInfo(hwnd, SB_VERT, &scrInfo, TRUE);
  1144. }
  1145. return 0;
  1146. }
  1147. INT PLV_GetScrollTrackPos(HWND hwnd)
  1148. {
  1149. static SCROLLINFO scrInfo;
  1150. scrInfo.cbSize = sizeof(scrInfo);
  1151. scrInfo.fMask = SIF_ALL;
  1152. GetScrollInfo(hwnd, SB_VERT, &scrInfo);
  1153. return scrInfo.nTrackPos;
  1154. }
  1155. INT WINAPI PadListView_SetExtendStyle(HWND hwnd, INT style)
  1156. {
  1157. LPPLVDATA lpPlvData = GetPlvDataFromHWND(hwnd);
  1158. if(!lpPlvData) {
  1159. Dbg(("Internal ERROR\n"));
  1160. return 0;
  1161. }
  1162. if(lpPlvData->hwndHeader) {
  1163. INT s = (INT)GetWindowLong(lpPlvData->hwndHeader, GWL_STYLE);
  1164. SetWindowLong(lpPlvData->hwndHeader, GWL_STYLE, (LONG)(s & ~HDS_BUTTONS));
  1165. }
  1166. return 0;
  1167. Unref(style);
  1168. }
  1169. //////////////////////////////////////////////////////////////////
  1170. // Function : PadListView_GetWidthByColumn
  1171. // Type : INT WINAPI
  1172. // Purpose : Calc PLV's window width by specified Column count
  1173. // : This is PLVS_ICONVIEW style only.
  1174. // Args :
  1175. // : HWND hwnd PadListView window handle
  1176. // : INT col column count
  1177. // Return : width by pixel.
  1178. // DATE : 971120
  1179. //////////////////////////////////////////////////////////////////
  1180. INT WINAPI PadListView_GetWidthByColumn(HWND hwnd, INT col)
  1181. {
  1182. LPPLVDATA lpPlv = GetPlvDataFromHWND(hwnd);
  1183. return IconView_GetWidthByColumn(lpPlv, col);
  1184. }
  1185. //////////////////////////////////////////////////////////////////
  1186. // Function : PadListView_GetHeightByRow
  1187. // Type : INT WINAPI
  1188. // Purpose : Calc PLV's window height
  1189. // by specified Row count.
  1190. // This is PLVS_ICONVIEW style only.
  1191. // Args :
  1192. // : HWND hwnd PLV's window handle
  1193. // : INT row row count
  1194. // Return : height in pixel
  1195. // DATE : 971120
  1196. //////////////////////////////////////////////////////////////////
  1197. INT WINAPI PadListView_GetHeightByRow(HWND hwnd, INT row)
  1198. {
  1199. LPPLVDATA lpPlv = GetPlvDataFromHWND(hwnd);
  1200. return IconView_GetHeightByRow(lpPlv, row);
  1201. }
  1202. //////////////////////////////////////////////////////////////////
  1203. // Function : PadListView_SetHeaderFont
  1204. // Type : INT WINAPI
  1205. // Purpose :
  1206. // Args :
  1207. // : HWND hwnd
  1208. // : LPSTR lpstrFontName
  1209. // Return :
  1210. // DATE : Tue Jul 28 08:58:06 1998
  1211. // Histroy :
  1212. //////////////////////////////////////////////////////////////////
  1213. INT WINAPI PadListView_SetHeaderFont(HWND hwnd, LPTSTR lpstrFontName)
  1214. {
  1215. Dbg(("PadListView_SetHeaderFont START\n"));
  1216. LPPLVDATA lpPlvData = GetPlvDataFromHWND(hwnd);
  1217. INT point = 9;
  1218. if(!lpPlvData) {
  1219. Dbg(("PadListView_SetHeaderFont ERROR\n"));
  1220. return 0;
  1221. }
  1222. HFONT hFont;
  1223. ::ZeroMemory(&g_logFont, sizeof(g_logFont));
  1224. HDC hDC = ::GetDC(hwnd);
  1225. INT dpi = ::GetDeviceCaps(hDC, LOGPIXELSY);
  1226. if(-1 == GetLogFont(hDC, lpstrFontName, &g_logFont)) {
  1227. ::ReleaseDC(hwnd, hDC);
  1228. return -1;
  1229. }
  1230. ::ReleaseDC(hwnd, hDC);
  1231. g_logFont.lfHeight = - (point * dpi)/72;
  1232. g_logFont.lfWidth = 0;
  1233. hFont = CreateFontIndirect(&g_logFont);
  1234. if(!hFont) {
  1235. Dbg(("CreatFontIndirect Error\n"));
  1236. return -1;
  1237. }
  1238. if(lpPlvData->hFontHeader) {
  1239. ::DeleteObject(lpPlvData->hFontHeader);
  1240. }
  1241. lpPlvData->hFontHeader = hFont;
  1242. return 0;
  1243. }
  1244. //////////////////////////////////////////////////////////////////
  1245. // Function : PadListView_SetCodePage
  1246. // Type : INT WINAPI
  1247. // Purpose :
  1248. // Args :
  1249. // : HWND hwnd
  1250. // : INT codePage
  1251. // Return :
  1252. // DATE : Tue Jul 28 08:59:35 1998
  1253. // Histroy :
  1254. //////////////////////////////////////////////////////////////////
  1255. INT WINAPI PadListView_SetCodePage(HWND hwnd, INT codePage)
  1256. {
  1257. Dbg(("PadListView_SetCodePage START\n"));
  1258. LPPLVDATA lpPlvData = GetPlvDataFromHWND(hwnd);
  1259. if(lpPlvData) {
  1260. lpPlvData->codePage = codePage;
  1261. }
  1262. return 0;
  1263. }
  1264. #ifdef MSAA
  1265. //////////////////////////////////////////////////////////////////
  1266. // Functions : MSAA Support Functions
  1267. // DATE : 980724
  1268. //////////////////////////////////////////////////////////////////
  1269. BOOL PLV_InitMSAA(LPPLVDATA lpPlv)
  1270. {
  1271. if(!lpPlv)
  1272. return FALSE;
  1273. lpPlv->bMSAAAvailable = FALSE;
  1274. lpPlv->bCoInitialized = FALSE;
  1275. lpPlv->hOleAcc = NULL;
  1276. lpPlv->pfnLresultFromObject = NULL;
  1277. #ifdef NOTUSED
  1278. lpPlv->pfnObjectFromLresult = NULL;
  1279. lpPlv->pfnAccessibleObjectFromWindow = NULL;
  1280. lpPlv->pfnAccessibleObjectFromPoint = NULL;
  1281. #endif
  1282. lpPlv->pfnCreateStdAccessibleObject = NULL;
  1283. #ifdef NOTUSED
  1284. lpPlv->pfnAccessibleChildren = NULL;
  1285. #endif
  1286. lpPlv->hUser32 = NULL;
  1287. lpPlv->pfnNotifyWinEvent=NULL;
  1288. lpPlv->bReadyForWMGetObject=FALSE;
  1289. lpPlv->pAccPLV = NULL;
  1290. if(!PLV_LoadOleAccForMSAA(lpPlv))
  1291. return FALSE;
  1292. if(!PLV_LoadUser32ForMSAA(lpPlv)){
  1293. PLV_UnloadOleAccForMSAA(lpPlv);
  1294. return FALSE;
  1295. }
  1296. if(!PLV_CoInitialize(lpPlv)){
  1297. PLV_UnloadUser32ForMSAA(lpPlv);
  1298. PLV_UnloadOleAccForMSAA(lpPlv);
  1299. return FALSE;
  1300. }
  1301. lpPlv->bMSAAAvailable = TRUE;
  1302. return TRUE;
  1303. }
  1304. void PLV_UninitMSAA(LPPLVDATA lpPlv)
  1305. {
  1306. if(!lpPlv)
  1307. return;
  1308. if(lpPlv->bMSAAAvailable){
  1309. PLV_CoUninitialize(lpPlv);
  1310. PLV_UnloadUser32ForMSAA(lpPlv);
  1311. PLV_UnloadOleAccForMSAA(lpPlv);
  1312. lpPlv->bMSAAAvailable = FALSE;
  1313. }
  1314. }
  1315. BOOL PLV_CoInitialize(LPPLVDATA lpPlv)
  1316. {
  1317. if(lpPlv && !lpPlv->bCoInitialized &&
  1318. SUCCEEDED(CoInitialize(NULL)))
  1319. lpPlv->bCoInitialized = TRUE;
  1320. return lpPlv->bCoInitialized;
  1321. }
  1322. void PLV_CoUninitialize(LPPLVDATA lpPlv)
  1323. {
  1324. if(lpPlv && lpPlv->bCoInitialized){
  1325. CoUninitialize();
  1326. lpPlv->bCoInitialized = FALSE;
  1327. }
  1328. }
  1329. BOOL PLV_LoadOleAccForMSAA(LPPLVDATA lpPlv)
  1330. {
  1331. if(!lpPlv)
  1332. return FALSE;
  1333. lpPlv->hOleAcc=::LoadLibrary("oleacc.dll");
  1334. if(!lpPlv->hOleAcc)
  1335. return FALSE;
  1336. if((lpPlv->pfnLresultFromObject
  1337. =(LPFNLRESULTFROMOBJECT)::GetProcAddress(lpPlv->hOleAcc,"LresultFromObject"))
  1338. #ifdef NOTUSED
  1339. && (lpPlv->pfnObjectFromLresult
  1340. =(LPFNOBJECTFROMLRESULT)::GetProcAddress(lpPlv->hOleAcc,"ObjectFromLresult"))
  1341. && (lpPlv->pfnAccessibleObjectFromWindow
  1342. =(LPFNACCESSIBLEOBJECTFROMWINDOW)::GetProcAddress(lpPlv->hOleAcc,"AccessibleObjectFromWindow"))
  1343. && (lpPlv->pfnAccessibleObjectFromPoint
  1344. =(LPFNACCESSIBLEOBJECTFROMPOINT)::GetProcAddress(lpPlv->hOleAcc,"AccessibleObjectFromPoint"))
  1345. #endif
  1346. && (lpPlv->pfnCreateStdAccessibleObject
  1347. =(LPFNCREATESTDACCESSIBLEOBJECT)::GetProcAddress(lpPlv->hOleAcc,"CreateStdAccessibleObject"))
  1348. #ifdef NOTUSED
  1349. && (lpPlv->pfnAccessibleChildren
  1350. =(LPFNACCESSIBLECHILDREN)::GetProcAddress(lpPlv->hOleAcc,"CreateAccessibleChildren"))
  1351. #endif
  1352. )
  1353. return TRUE;
  1354. PLV_UnloadOleAccForMSAA(lpPlv);
  1355. return FALSE;
  1356. }
  1357. void PLV_UnloadOleAccForMSAA(LPPLVDATA lpPlv)
  1358. {
  1359. if(!lpPlv)
  1360. return;
  1361. if(lpPlv->hOleAcc){
  1362. ::FreeLibrary(lpPlv->hOleAcc);
  1363. lpPlv->hOleAcc = NULL;
  1364. }
  1365. lpPlv->pfnLresultFromObject=NULL;
  1366. #ifdef NOTUSED
  1367. lpPlv->pfnObjectFromLresult=NULL;
  1368. lpPlv->pfnAccessibleObjectFromWindow=NULL;
  1369. lpPlv->pfnAccessibleObjectFromPoint=NULL;
  1370. #endif
  1371. lpPlv->pfnCreateStdAccessibleObject=NULL;
  1372. #ifdef NOTUSED
  1373. lpPlv->pfnAccessibleChildren=NULL;
  1374. #endif
  1375. }
  1376. BOOL PLV_LoadUser32ForMSAA(LPPLVDATA lpPlv)
  1377. {
  1378. if(!lpPlv)
  1379. return FALSE;
  1380. lpPlv->hUser32=::LoadLibrary("user32.dll");
  1381. if(!lpPlv->hUser32)
  1382. return FALSE;
  1383. if((lpPlv->pfnNotifyWinEvent
  1384. =(LPFNNOTIFYWINEVENT)::GetProcAddress(lpPlv->hUser32,"NotifyWinEvent")))
  1385. return TRUE;
  1386. PLV_UnloadUser32ForMSAA(lpPlv);
  1387. return FALSE;
  1388. }
  1389. void PLV_UnloadUser32ForMSAA(LPPLVDATA lpPlv)
  1390. {
  1391. if(!lpPlv)
  1392. return;
  1393. if(lpPlv->hUser32){
  1394. ::FreeLibrary(lpPlv->hUser32);
  1395. lpPlv->hUser32 = NULL;
  1396. }
  1397. lpPlv->pfnNotifyWinEvent = NULL;
  1398. }
  1399. BOOL PLV_IsMSAAAvailable(LPPLVDATA lpPlv)
  1400. {
  1401. return (lpPlv && lpPlv->bMSAAAvailable);
  1402. }
  1403. LRESULT PLV_LresultFromObject(LPPLVDATA lpPlv,REFIID riid, WPARAM wParam, LPUNKNOWN punk)
  1404. {
  1405. if(lpPlv && lpPlv->pfnLresultFromObject)
  1406. return lpPlv->pfnLresultFromObject(riid, wParam, punk);
  1407. return (LRESULT)E_FAIL;
  1408. }
  1409. #ifdef NOTUSED
  1410. HRESULT PLV_ObjectFromLresult(LPPLVDATA lpPlv,LRESULT lResult, REFIID riid, WPARAM wParam, void** ppvObject)
  1411. {
  1412. if(lpPlv && lpPlv->pfnObjectFromLresult)
  1413. return lpPlv->pfnObjectFromLresult(lResult, riid, wParam, ppvObject);
  1414. return E_FAIL;
  1415. }
  1416. HRESULT PLV_AccessibleObjectFromWindow(LPPLVDATA lpPlv,HWND hwnd, DWORD dwId, REFIID riid, void **ppvObject)
  1417. {
  1418. if(lpPlv && lpPlv->pfnAccessibleObjectFromWindow)
  1419. return lpPlv->pfnAccessibleObjectFromWindow(hwnd, dwId, riid, ppvObject);
  1420. return E_FAIL;
  1421. }
  1422. HRESULT PLV_AccessibleObjectFromPoint(LPPLVDATA lpPlv,POINT ptScreen, IAccessible ** ppacc, VARIANT* pvarChild)
  1423. {
  1424. if(lpPlv && lpPlv->pfnAccessibleObjectFromPoint)
  1425. return lpPlv->pfnAccessibleObjectFromPoint(ptScreen, ppacc, pvarChild);
  1426. return E_FAIL;
  1427. }
  1428. #endif // NOTUSED
  1429. HRESULT PLV_CreateStdAccessibleObject(LPPLVDATA lpPlv,HWND hwnd, LONG idObject, REFIID riid, void** ppvObject)
  1430. {
  1431. if(lpPlv && lpPlv->pfnCreateStdAccessibleObject)
  1432. return lpPlv->pfnCreateStdAccessibleObject(hwnd, idObject, riid, ppvObject);
  1433. return E_FAIL;
  1434. }
  1435. #ifdef NOTUSED
  1436. HRESULT PLV_AccessibleChildren (LPPLVDATA lpPlv,IAccessible* paccContainer, LONG iChildStart,
  1437. LONG cChildren, VARIANT* rgvarChildren,LONG* pcObtained)
  1438. {
  1439. if(lpPlv && lpPlv->pfnAccessibleChildren)
  1440. return lpPlv->pfnAccessibleChildren (paccContainer, iChildStart,cChildren,
  1441. rgvarChildren, pcObtained);
  1442. return E_FAIL;
  1443. }
  1444. #endif
  1445. void PLV_NotifyWinEvent(LPPLVDATA lpPlv,DWORD event,HWND hwnd ,LONG idObject,LONG idChild)
  1446. {
  1447. if(lpPlv && lpPlv->pfnNotifyWinEvent)
  1448. lpPlv->pfnNotifyWinEvent(event,hwnd,idObject,idChild);
  1449. }
  1450. INT PLV_ChildIDFromPoint(LPPLVDATA lpPlv,POINT pt)
  1451. {
  1452. if(!lpPlv)
  1453. return -1;
  1454. static INT index,nCol,nWid;
  1455. static PLVINFO plvInfo;
  1456. static HD_ITEM hdItem;
  1457. if(lpPlv->dwStyle == PLVSTYLE_ICON) // iconview
  1458. index = IV_GetInfoFromPoint(lpPlv, pt, &plvInfo);
  1459. else { // report view
  1460. nCol = RV_GetColumn(lpPlv);
  1461. index = RV_GetInfoFromPoint(lpPlv, pt, &plvInfo);
  1462. if(index < 0) {
  1463. if(pt.y > RV_GetHeaderHeight(lpPlv)) // out of header
  1464. return -1;
  1465. // header
  1466. nWid = 0;
  1467. hdItem.mask = HDI_WIDTH;
  1468. hdItem.fmt = 0;
  1469. for(index = 0;index<nCol;index++){
  1470. Header_GetItem(lpPlv->hwndHeader,index,&hdItem);
  1471. nWid += hdItem.cxy;
  1472. if(pt.x <= nWid)
  1473. break;
  1474. }
  1475. }
  1476. else
  1477. index = (index + 1) * nCol + plvInfo.colIndex;
  1478. }
  1479. return index + 1; // 1 origin
  1480. }
  1481. #endif // MSAA