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.

140 lines
3.5 KiB

  1. //
  2. // mxToolKit (c) 1999 by Mete Ciragan
  3. //
  4. // file: mxLineEdit.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/mxLineEdit.h"
  15. #include <windows.h>
  16. #include "mxtk/mxEvent.h"
  17. #include "mxtk/mxWindow.h"
  18. class mxLineEdit_i
  19. {
  20. public:
  21. int dummy;
  22. };
  23. #include "tier0/dbg.h"
  24. typedef LRESULT (CALLBACK * WndProc_t)(HWND hwnd, UINT uMessage, WPARAM wParam, LPARAM lParam);
  25. static WndProc_t s_OldWndProc = 0;
  26. static LRESULT CALLBACK EditWndProc (HWND hwnd, UINT uMessage, WPARAM wParam, LPARAM lParam)
  27. {
  28. int iret = 0;
  29. // This lovely bit of hackery ensures we get return key events
  30. if ( uMessage == WM_CHAR)
  31. {
  32. iret = s_OldWndProc( hwnd, uMessage, wParam, lParam );
  33. // Post the message directly to all windows in the hierarchy until
  34. // someone responds
  35. mxLineEdit *lineEdit = (mxLineEdit *) GetWindowLong (hwnd, GWL_USERDATA);
  36. mxEvent event;
  37. event.event = mxEvent::KeyDown;
  38. event.action = lineEdit->getId();
  39. event.key = (int) wParam;
  40. mxWindow* window = lineEdit->getParent();
  41. while (window)
  42. {
  43. if (window->handleEvent (&event))
  44. break;
  45. window = window->getParent ();
  46. }
  47. }
  48. else
  49. {
  50. if ( uMessage == WM_LBUTTONDOWN )
  51. {
  52. SetFocus( hwnd );
  53. }
  54. iret = s_OldWndProc( hwnd, uMessage, wParam, lParam );
  55. }
  56. return iret;
  57. }
  58. mxLineEdit::mxLineEdit (mxWindow *parent, int x, int y, int w, int h, const char *label, int id, int style)
  59. : mxWidget (parent, x, y, w, h, label)
  60. {
  61. if (!parent)
  62. return;
  63. DWORD dwStyle = WS_VISIBLE | WS_CHILD | ES_AUTOHSCROLL | WS_TABSTOP; // | ES_WANTRETURN | ES_MULTILINE;
  64. HWND hwndParent = (HWND) ((mxWidget *) parent)->getHandle ();
  65. if (style == ReadOnly)
  66. dwStyle |= ES_READONLY;
  67. else if (style == Password)
  68. dwStyle |= ES_PASSWORD;
  69. if (!s_OldWndProc)
  70. {
  71. WNDCLASSEX editClass;
  72. GetClassInfoEx( (HINSTANCE) GetModuleHandle (NULL), "EDIT", &editClass );
  73. s_OldWndProc = editClass.lpfnWndProc;
  74. editClass.cbSize = sizeof(WNDCLASSEX);
  75. editClass.cbClsExtra = 0;
  76. editClass.lpfnWndProc = EditWndProc;
  77. editClass.lpszClassName = "mx_edit";
  78. RegisterClassEx( &editClass );
  79. }
  80. void *handle = (void *) CreateWindowEx (WS_EX_CLIENTEDGE, "mx_edit", label, dwStyle, //WS_VISIBLE | WS_CHILD | ES_AUTOHSCROLL,
  81. x, y, w, h, hwndParent,
  82. (HMENU) id, (HINSTANCE) GetModuleHandle (NULL), NULL);
  83. SendMessage ((HWND) handle, WM_SETFONT, (WPARAM) (HFONT) GetStockObject (ANSI_VAR_FONT), MAKELPARAM (TRUE, 0));
  84. SendMessage ((HWND) getHandle (), EM_LIMITTEXT, (WPARAM) 256, 0L);
  85. SetWindowLong ((HWND) handle, GWL_USERDATA, (LONG) this);
  86. setHandle (handle);
  87. setType (MX_LINEEDIT);
  88. setParent (parent);
  89. setId (id);
  90. }
  91. mxLineEdit::~mxLineEdit ()
  92. {
  93. }
  94. void mxLineEdit::clear()
  95. {
  96. SendMessage( (HWND)getHandle(), WM_SETTEXT, (WPARAM)0, (LPARAM)"" );
  97. }
  98. void mxLineEdit::getText( char *buf, size_t bufsize )
  99. {
  100. buf[ 0 ] = 0;
  101. SendMessage( (HWND) getHandle (), WM_GETTEXT, (WPARAM)bufsize, (LPARAM)buf );
  102. }
  103. void
  104. mxLineEdit::setMaxLength (int max)
  105. {
  106. SendMessage ((HWND) getHandle (), EM_LIMITTEXT, (WPARAM) max, 0L);
  107. }
  108. int
  109. mxLineEdit::getMaxLength () const
  110. {
  111. return (int) SendMessage ((HWND) getHandle (), EM_GETLIMITTEXT, 0, 0L);
  112. }