Counter Strike : Global Offensive Source Code
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.

161 lines
3.2 KiB

  1. //
  2. // mxToolKit (c) 1999 by Mete Ciragan
  3. //
  4. // file: mxListBox.cpp
  5. // implementation: Win32 API
  6. // last modified: Mar 18 1999, Mete Ciragan
  7. // copyright: The programs and associated files contained in this
  8. // distribution were developed by Mete Ciragan. The programs
  9. // are not in the public domain, but they are freely
  10. // distributable without licensing fees. These programs are
  11. // provided without guarantee or warrantee expressed or
  12. // implied.
  13. //
  14. #include "mxtk/mxListBox.h"
  15. #include <windows.h>
  16. class mxListBox_i
  17. {
  18. public:
  19. int dummy;
  20. };
  21. mxListBox::mxListBox (mxWindow *parent, int x, int y, int w, int h, int id, int style)
  22. : mxWidget (parent, x, y, w, h)
  23. {
  24. if (!parent)
  25. return;
  26. DWORD dwStyle = WS_VISIBLE | WS_CHILD | LBS_NOTIFY | WS_VSCROLL | WS_HSCROLL;
  27. HWND hwndParent = (HWND) ((mxWidget *) parent)->getHandle ();
  28. if (style == MultiSelection)
  29. dwStyle |= LBS_MULTIPLESEL | LBS_EXTENDEDSEL;
  30. void *handle = (void *) CreateWindowEx (WS_EX_CLIENTEDGE, "LISTBOX", "", WS_VISIBLE | WS_CHILD | LBS_NOTIFY | WS_VSCROLL,
  31. x, y, w, h, hwndParent,
  32. (HMENU) id, (HINSTANCE) GetModuleHandle (NULL), NULL);
  33. SendMessage ((HWND) handle, WM_SETFONT, (WPARAM) (HFONT) GetStockObject (ANSI_VAR_FONT), MAKELPARAM (TRUE, 0));
  34. SetWindowLong ((HWND) handle, GWL_USERDATA, (LONG) this);
  35. setHandle (handle);
  36. setType (MX_LISTBOX);
  37. setParent (parent);
  38. setId (id);
  39. }
  40. mxListBox::~mxListBox ()
  41. {
  42. removeAll ();
  43. }
  44. void
  45. mxListBox::add (const char *item)
  46. {
  47. SendMessage ((HWND) getHandle (), LB_ADDSTRING, 0, (LPARAM) (LPCTSTR) item);
  48. }
  49. void
  50. mxListBox::select (int index)
  51. {
  52. SendMessage ((HWND) getHandle (), LB_SETCURSEL, (WPARAM) index, 0L);
  53. }
  54. void
  55. mxListBox::deselect (int index)
  56. {
  57. SendMessage ((HWND) getHandle (), LB_SETSEL, (WPARAM) FALSE, (LPARAM) (UINT) index);
  58. }
  59. void
  60. mxListBox::remove (int index)
  61. {
  62. SendMessage ((HWND) getHandle (), LB_DELETESTRING, (WPARAM) index, 0L);
  63. }
  64. void
  65. mxListBox::removeAll ()
  66. {
  67. SendMessage ((HWND) getHandle (), LB_RESETCONTENT, 0, 0L);
  68. }
  69. void
  70. mxListBox::setItemText (int index, const char *item)
  71. {
  72. //SendMessage ((HWND) getHandle (), LB_SETTEXT, (WPARAM) index, (LPARAM) (LPCTSTR) item);
  73. }
  74. void
  75. mxListBox::setItemData (int index, void *data)
  76. {
  77. SendMessage ((HWND) getHandle (), LB_SETITEMDATA, (WPARAM) index, (LPARAM) data);
  78. }
  79. int
  80. mxListBox::getItemCount () const
  81. {
  82. return (int) SendMessage ((HWND) getHandle (), LB_GETCOUNT, 0, 0L);
  83. }
  84. int
  85. mxListBox::getSelectedIndex () const
  86. {
  87. return (int) SendMessage ((HWND) getHandle (), LB_GETCURSEL, 0, 0L);
  88. }
  89. bool
  90. mxListBox::isSelected (int index) const
  91. {
  92. return (bool) (SendMessage ((HWND) getHandle (), LB_GETSEL, (WPARAM) index, 0L) > 0);
  93. }
  94. const char*
  95. mxListBox::getItemText (int index) const
  96. {
  97. static char text[256];
  98. SendMessage ((HWND) getHandle (), LB_GETTEXT, (WPARAM) index, (LPARAM) (LPCTSTR) text);
  99. return text;
  100. }
  101. void*
  102. mxListBox::getItemData (int index) const
  103. {
  104. return (void *) SendMessage ((HWND) getHandle (), LB_GETITEMDATA, (WPARAM) index, 0L);
  105. }
  106. int
  107. mxListBox::getTopIndex () const
  108. {
  109. return (int) SendMessage ((HWND) getHandle (), LB_GETTOPINDEX, 0, 0L);
  110. }