listview.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. #ifndef _LISTVIEW_H_
  19. #define _LISTVIEW_H_
  20. #include <windows.h>
  21. #include <windowsx.h>
  22. #include <commctrl.h>
  23. class W_ListView
  24. {
  25. public:
  26. W_ListView()
  27. {
  28. m_hwnd=NULL;
  29. m_col=0;
  30. m_allowfonts=1;
  31. m_font=NULL;
  32. #ifndef GEN_ML_EXPORTS
  33. m_libraryparent=NULL;
  34. #endif
  35. }
  36. W_ListView(HWND hwnd)
  37. {
  38. m_hwnd=NULL;
  39. m_col=0;
  40. m_allowfonts=1;
  41. m_font=NULL;
  42. #ifndef GEN_ML_EXPORTS
  43. m_libraryparent=NULL;
  44. #endif
  45. setwnd(hwnd);
  46. }
  47. ~W_ListView()
  48. {
  49. if (m_font) DeleteFont(m_font);
  50. m_font=0;
  51. }
  52. void refreshFont();
  53. #ifndef GEN_ML_EXPORTS
  54. void setLibraryParentWnd(HWND hwndParent)
  55. {
  56. m_libraryparent=hwndParent;
  57. }// for Winamp Font getting stuff
  58. #endif
  59. void setallowfonts(int allow=1);
  60. void setwnd(HWND hwnd);
  61. void AddCol(char *text, int w);
  62. int GetCount(void)
  63. {
  64. return ListView_GetItemCount(m_hwnd);
  65. }
  66. int GetParam(int p);
  67. void DeleteItem(int n)
  68. {
  69. ListView_DeleteItem(m_hwnd,n);
  70. }
  71. void Clear(void)
  72. {
  73. ListView_DeleteAllItems(m_hwnd);
  74. }
  75. int GetSelected(int x)
  76. {
  77. return(ListView_GetItemState(m_hwnd, x, LVIS_SELECTED) & LVIS_SELECTED)?1:0;
  78. }
  79. int GetSelectedCount()
  80. {
  81. return ListView_GetSelectedCount(m_hwnd);
  82. }
  83. int GetSelectionMark()
  84. {
  85. return ListView_GetSelectionMark(m_hwnd);
  86. }
  87. void SetSelected(int x)
  88. {
  89. ListView_SetItemState(m_hwnd,x,LVIS_SELECTED,LVIS_SELECTED);
  90. }
  91. int InsertItem(int p, char *text, int param);
  92. void GetItemRect(int i, RECT *r)
  93. {
  94. ListView_GetItemRect(m_hwnd, i, r, LVIR_BOUNDS);
  95. }
  96. void SetItemText(int p, int si, char *text);
  97. void SetItemParam(int p, int param);
  98. void GetText(int p, int si, char *text, int maxlen)
  99. {
  100. ListView_GetItemText(m_hwnd, p, si, text, maxlen);
  101. }
  102. int FindItemByParam(int param)
  103. {
  104. LVFINDINFO fi={LVFI_PARAM,0,param};
  105. return ListView_FindItem(m_hwnd,-1,&fi);
  106. }
  107. int FindItemByPoint(int x, int y)
  108. {
  109. int l=GetCount();
  110. for (int i=0;i<l;i++)
  111. {
  112. RECT r;
  113. GetItemRect(i, &r);
  114. if (r.left<=x && r.right>=x && r.top<=y && r.bottom>=y) return i;
  115. }
  116. return -1;
  117. }
  118. int GetColumnWidth(int col);
  119. HWND getwnd(void)
  120. {
  121. return m_hwnd;
  122. }
  123. protected:
  124. HWND m_hwnd;
  125. HFONT m_font;
  126. int m_col;
  127. int m_allowfonts;
  128. #ifndef GEN_ML_EXPORTS
  129. HWND m_libraryparent;
  130. #endif
  131. };
  132. #endif//_LISTVIEW_H_