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.

ListViewControl.cxx 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. // ListViewControl.cxx: implementation of the ListViewControl class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #ifdef HAVE_CONFIG_H
  5. #include <config.h>
  6. #endif
  7. #include <tchar.h>
  8. #include "ListViewControl.h"
  9. #include "commctrl.h"
  10. //////////////////////////////////////////////////////////////////////
  11. // Construction/Destruction
  12. //////////////////////////////////////////////////////////////////////
  13. using namespace rfb;
  14. using namespace rfb::win32;
  15. ListViewControl::ListViewControl()
  16. {
  17. }
  18. bool ListViewControl::IsSelectedLVItem(DWORD idListView,
  19. HWND hDlg, int numberItem)
  20. {
  21. return (ListView_GetItemState(GetDlgItem(hDlg, idListView),
  22. numberItem, LVIS_SELECTED) == LVIS_SELECTED);
  23. }
  24. void ListViewControl::SelectLVItem(DWORD idListView, HWND hDlg, int numberItem)
  25. {
  26. ListView_SetItemState(GetDlgItem(hDlg, idListView),
  27. numberItem, LVIS_SELECTED, LVIS_SELECTED);
  28. }
  29. BOOL ListViewControl::InitLVColumns(DWORD idListView, HWND hDlg, int width, int columns,
  30. TCHAR *title[], DWORD mask, DWORD LVStyle, DWORD format)
  31. {
  32. (void)ListView_SetExtendedListViewStyle(GetDlgItem(hDlg, idListView), LVStyle);
  33. TCHAR szText[256];
  34. LVCOLUMN lvc;
  35. int iCol;
  36. lvc.mask = mask;
  37. for (iCol = 0; iCol < columns; iCol++) {
  38. lvc.iSubItem = iCol;
  39. lvc.pszText = szText;
  40. lvc.cx = width;
  41. lvc.fmt = format;
  42. _tcscpy(szText, title[iCol]);
  43. if (ListView_InsertColumn(GetDlgItem(hDlg, idListView), iCol, &lvc) == -1)
  44. return FALSE;
  45. }
  46. return TRUE;
  47. }
  48. BOOL ListViewControl::InsertLVItem(DWORD idListView, HWND hDlg, int number, TCHAR * texts[],
  49. int columns)
  50. {
  51. int i;
  52. LVITEM lvI;
  53. lvI.mask = LVIF_TEXT| LVIF_STATE;
  54. lvI.state = 0;
  55. lvI.stateMask = 0;
  56. lvI.iItem = number;
  57. lvI.iSubItem = 0;
  58. lvI.pszText = texts[0];
  59. if(ListView_InsertItem(GetDlgItem(hDlg, idListView), &lvI) == -1)
  60. return FALSE;
  61. for (i =1; i < columns; i++) {
  62. SetLVItemText(
  63. idListView, hDlg,
  64. number, i, texts[i]);
  65. }
  66. return TRUE;
  67. }
  68. void ListViewControl::SetLVItemText(DWORD idListView, HWND hDlg, int numberItem,
  69. int namberColumn, TCHAR * text)
  70. {
  71. ListView_SetItemText(
  72. GetDlgItem(hDlg, idListView),
  73. numberItem, namberColumn, text);
  74. }
  75. void ListViewControl::GetLVItemText(DWORD idListView, HWND hDlg, int numberItem,
  76. int namberColumn, TCHAR * text)
  77. {
  78. ListView_GetItemText(GetDlgItem(hDlg, idListView), numberItem,
  79. namberColumn, text, 256);
  80. }
  81. void ListViewControl::DeleteLVItem(DWORD idListView, HWND hDlg, int number)
  82. {
  83. (void)ListView_DeleteItem(GetDlgItem(hDlg, idListView), number);
  84. }
  85. void ListViewControl::DeleteAllLVItem(DWORD idListView, HWND hDlg)
  86. {
  87. (void)ListView_DeleteAllItems(GetDlgItem(hDlg, idListView));
  88. }
  89. ListViewControl::~ListViewControl()
  90. {
  91. }