1
0

listview.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. ** Copyright (C) 2003 Nullsoft, Inc.
  3. **
  4. ** This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held
  5. ** liable for any damages arising from the use of this software.
  6. **
  7. ** Permission is granted to anyone to use this software for any purpose, including commercial applications, and to
  8. ** alter it and redistribute it freely, subject to the following restrictions:
  9. **
  10. ** 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software.
  11. ** If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
  12. **
  13. ** 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
  14. **
  15. ** 3. This notice may not be removed or altered from any source distribution.
  16. **
  17. */
  18. #include <windows.h>
  19. #include <commctrl.h>
  20. #include "listview.h"
  21. #ifdef GEN_ML_EXPORTS
  22. #include "main.h" // for getting the font
  23. #include "config.h"
  24. #endif
  25. // bp Comment: all the calls beginning "ListView_" are
  26. // MACROs defined in commctrl.h
  27. void W_ListView :: AddCol (char *text, int w)
  28. {
  29. LVCOLUMN lvc={0,};
  30. lvc.mask = LVCF_TEXT|LVCF_WIDTH;
  31. lvc.pszText = text;
  32. if (w) lvc.cx=w;
  33. ListView_InsertColumn (m_hwnd, m_col, &lvc);
  34. m_col++;
  35. }
  36. int W_ListView::GetColumnWidth (int col)
  37. {
  38. if (col < 0 || col >= m_col) return 0;
  39. return ListView_GetColumnWidth (m_hwnd, col);
  40. }
  41. int W_ListView::GetParam (int p)
  42. {
  43. LVITEM lvi={0,};
  44. lvi.mask = LVIF_PARAM;
  45. lvi.iItem = p;
  46. ListView_GetItem (m_hwnd, &lvi);
  47. return lvi.lParam;
  48. }
  49. int W_ListView::InsertItem (int p, char *text, int param)
  50. {
  51. LVITEM lvi={0,};
  52. lvi.mask = LVIF_TEXT | LVIF_PARAM;
  53. lvi.iItem = p;
  54. lvi.pszText = text;
  55. lvi.cchTextMax=strlen (text);
  56. lvi.lParam = param;
  57. return ListView_InsertItem (m_hwnd, &lvi);
  58. }
  59. void W_ListView::SetItemText (int p, int si, char *text)
  60. {
  61. LVITEM lvi={0,};
  62. lvi.iItem = p;
  63. lvi.iSubItem = si;
  64. lvi.mask = LVIF_TEXT;
  65. lvi.pszText = text;
  66. lvi.cchTextMax = strlen (text);
  67. ListView_SetItem (m_hwnd, &lvi);
  68. }
  69. void W_ListView::SetItemParam (int p, int param)
  70. {
  71. LVITEM lvi={0,};
  72. lvi.iItem = p;
  73. lvi.mask=LVIF_PARAM;
  74. lvi.lParam=param;
  75. ListView_SetItem (m_hwnd, &lvi);
  76. }
  77. void W_ListView::refreshFont ()
  78. {
  79. if (m_font)
  80. {
  81. DeleteFont (m_font);
  82. SetWindowFont (m_hwnd, NULL, FALSE);
  83. }
  84. m_font = NULL;
  85. HWND h;
  86. #ifdef GEN_ML_EXPORTS
  87. h=g_hwnd;
  88. #else
  89. h=m_libraryparent;
  90. #endif
  91. if (h && m_allowfonts)
  92. {
  93. int a=SendMessage (h, WM_USER+0x1000 /*WM_ML_IPC*/,66, 0x0600 /*ML_IPC_SKIN_WADLG_GETFUNC*/);
  94. if (a)
  95. {
  96. m_font= (HFONT)a;
  97. SetWindowFont (m_hwnd, m_font, FALSE);
  98. }
  99. }
  100. InvalidateRect (m_hwnd, NULL, TRUE);
  101. }
  102. void W_ListView::setallowfonts (int allow)
  103. {
  104. m_allowfonts=allow;
  105. }
  106. void W_ListView::setwnd (HWND hwnd)
  107. {
  108. m_hwnd = hwnd;
  109. if (hwnd)
  110. {
  111. ListView_SetExtendedListViewStyle (hwnd, LVS_EX_FULLROWSELECT|LVS_EX_UNDERLINEHOT );
  112. refreshFont ();
  113. }
  114. }