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.

134 lines
2.8 KiB

  1. //
  2. // mxToolKit (c) 1999 by Mete Ciragan
  3. //
  4. // file: mxScrollbar.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/mxScrollbar.h"
  15. #include <windows.h>
  16. #include <commctrl.h>
  17. class mxScrollbar_i
  18. {
  19. public:
  20. int dummy;
  21. };
  22. mxScrollbar::mxScrollbar (mxWindow *parent, int x, int y, int w, int h, int id, int style)
  23. : mxWidget (parent, x, y, w, h)
  24. {
  25. if (!parent)
  26. return;
  27. DWORD dwStyle = WS_CHILD | WS_VISIBLE;
  28. HWND hwndParent = (HWND) ((mxWidget *) parent)->getHandle ();
  29. if (style == Horizontal)
  30. dwStyle = WS_CHILD | WS_VISIBLE | SBS_HORZ | SBS_RIGHTALIGN;
  31. else if (style == Vertical)
  32. dwStyle = WS_CHILD | WS_VISIBLE | SBS_VERT | SBS_RIGHTALIGN; // WS_VSCROLL;
  33. void *handle = (void *) CreateWindowEx (0, "SCROLLBAR", "", dwStyle,
  34. x, y, w, h, hwndParent,
  35. (HMENU) id, (HINSTANCE) GetModuleHandle (NULL), NULL);
  36. SendMessage ((HWND) handle, WM_SETFONT, (WPARAM) (HFONT) GetStockObject (ANSI_VAR_FONT), MAKELPARAM (TRUE, 0));
  37. SetWindowLong ((HWND) handle, GWL_USERDATA, (LONG) this);
  38. setHandle (handle);
  39. setType (MX_SCROLLBAR);
  40. setParent (parent);
  41. setId (id);
  42. }
  43. mxScrollbar::~mxScrollbar ()
  44. {
  45. }
  46. void
  47. mxScrollbar::setValue (int ivalue)
  48. {
  49. SetScrollPos( (HWND) getHandle (), SB_CTL, ivalue, FALSE );
  50. }
  51. void
  52. mxScrollbar::setRange (int min, int max )
  53. {
  54. SCROLLINFO si = { sizeof( SCROLLINFO ), SIF_RANGE, min, max, 0, 0, 0 };
  55. SetScrollInfo( (HWND) getHandle (), SB_CTL, &si, TRUE );
  56. }
  57. void
  58. mxScrollbar::setPagesize (int size)
  59. {
  60. SCROLLINFO si = { sizeof( SCROLLINFO ), SIF_PAGE, 0, 0, (UINT)size, 0, 0 };
  61. SetScrollInfo( (HWND) getHandle (), SB_CTL, &si, TRUE );
  62. }
  63. int
  64. mxScrollbar::getValue () const
  65. {
  66. // SCROLLINFO si = { sizeof( SCROLLINFO ), SIF_POS | SIF_TRACKPOS, 0, 0, 0, 0, 0 };
  67. // GetScrollInfo( (HWND) getHandle (), SB_CTL, &si );
  68. // return si.nPos;
  69. return GetScrollPos( (HWND) getHandle (), SB_CTL );
  70. }
  71. int
  72. mxScrollbar::getMinValue () const
  73. {
  74. SCROLLINFO si = { sizeof( SCROLLINFO ), SIF_RANGE, 0, 0, 0, 0, 0 };
  75. GetScrollInfo( (HWND) getHandle (), SB_CTL, &si );
  76. return si.nMin;
  77. }
  78. int
  79. mxScrollbar::getMaxValue () const
  80. {
  81. SCROLLINFO si = { sizeof( SCROLLINFO ), SIF_RANGE, 0, 0, 0, 0, 0 };
  82. GetScrollInfo( (HWND) getHandle (), SB_CTL, &si );
  83. return si.nMax;
  84. }
  85. int
  86. mxScrollbar::getPagesize () const
  87. {
  88. SCROLLINFO si = { sizeof( SCROLLINFO ), SIF_PAGE, 0, 0, 0, 0, 0 };
  89. GetScrollInfo( (HWND) getHandle (), SB_CTL, &si );
  90. return si.nPage;
  91. }