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.

130 lines
2.9 KiB

  1. //
  2. // mxToolKit (c) 1999 by Mete Ciragan
  3. //
  4. // file: mxTab.cpp
  5. // implementation: Win32 API
  6. // last modified: Apr 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/mxTab.h"
  15. #include <windows.h>
  16. #include <commctrl.h>
  17. #include <stdio.h>
  18. class mxTab_i
  19. {
  20. public:
  21. int dummy;
  22. };
  23. void mxTab_resizeChild (HWND hwnd)
  24. {
  25. TC_ITEM ti;
  26. int index = TabCtrl_GetCurSel (hwnd);
  27. if (index >= 0)
  28. {
  29. ti.mask = TCIF_PARAM;
  30. TabCtrl_GetItem (hwnd, index, &ti);
  31. mxWidget *widget = (mxWidget *) ti.lParam;
  32. if (widget)
  33. {
  34. RECT rc, rc2;
  35. GetWindowRect (hwnd, &rc);
  36. ScreenToClient (GetParent (hwnd), (LPPOINT) &rc.left);
  37. ScreenToClient (GetParent (hwnd), (LPPOINT) &rc.right);
  38. TabCtrl_GetItemRect (hwnd, index, &rc2);
  39. int ex = GetSystemMetrics (SM_CXEDGE);
  40. int ey = GetSystemMetrics (SM_CYEDGE);
  41. rc.top += (rc2.bottom - rc2.top) + 3 * ey;
  42. rc.left += 2 * ex;
  43. rc.right -= 2 * ex;
  44. rc.bottom -= 2 * ey;
  45. HDWP hdwp = BeginDeferWindowPos (2);
  46. DeferWindowPos (hdwp, hwnd, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER);
  47. DeferWindowPos (hdwp, (HWND) widget->getHandle (), HWND_TOP, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, SWP_SHOWWINDOW);
  48. EndDeferWindowPos (hdwp);
  49. }
  50. }
  51. }
  52. mxTab::mxTab (mxWindow *parent, int x, int y, int w, int h, int id)
  53. : mxWidget (parent, x, y, w, h)
  54. {
  55. if (!parent)
  56. return;
  57. DWORD dwStyle = WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS;
  58. HWND hwndParent = (HWND) ((mxWidget *) parent)->getHandle ();
  59. void *handle = (void *) CreateWindowEx (0, WC_TABCONTROL, "", dwStyle,
  60. x, y, w, h, hwndParent,
  61. (HMENU) id, (HINSTANCE) GetModuleHandle (NULL), NULL);
  62. SendMessage ((HWND) handle, WM_SETFONT, (WPARAM) (HFONT) GetStockObject (ANSI_VAR_FONT), MAKELPARAM (TRUE, 0));
  63. SetWindowLong ((HWND) handle, GWL_USERDATA, (LONG) this);
  64. setHandle (handle);
  65. setType (MX_TAB);
  66. setParent (parent);
  67. setId (id);
  68. }
  69. mxTab::~mxTab ()
  70. {
  71. //TabCtrl_DeleteAllItems ((HWND) getHandle ());
  72. }
  73. void
  74. mxTab::add (mxWidget *widget, const char *text)
  75. {
  76. TC_ITEM ti;
  77. ti.mask = TCIF_TEXT | TCIF_PARAM;
  78. ti.pszText = (LPSTR) text;
  79. ti.lParam = (LPARAM) widget;
  80. TabCtrl_InsertItem ((HWND) getHandle (), TabCtrl_GetItemCount ((HWND) getHandle ()), &ti);
  81. mxTab_resizeChild ((HWND) getHandle ());
  82. }
  83. void
  84. mxTab::remove (int index)
  85. {
  86. TabCtrl_DeleteItem ((HWND) getHandle (), index);
  87. }
  88. void
  89. mxTab::select (int index)
  90. {
  91. TabCtrl_SetCurSel ((HWND) getHandle (), index);
  92. }
  93. int
  94. mxTab::getSelectedIndex () const
  95. {
  96. return (int) TabCtrl_GetCurSel ((HWND) getHandle ());
  97. }