summaryrefslogtreecommitdiff
path: root/utils/mxtk/mxlineedit.cpp
diff options
context:
space:
mode:
authorFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
committerFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
commit3bf9df6b2785fa6d951086978a3e66f49427166a (patch)
tree2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /utils/mxtk/mxlineedit.cpp
downloadarchived-source-engine-2018-hl2-src-3bf9df6b2785fa6d951086978a3e66f49427166a.tar.xz
archived-source-engine-2018-hl2-src-3bf9df6b2785fa6d951086978a3e66f49427166a.zip
Diffstat (limited to 'utils/mxtk/mxlineedit.cpp')
-rw-r--r--utils/mxtk/mxlineedit.cpp140
1 files changed, 140 insertions, 0 deletions
diff --git a/utils/mxtk/mxlineedit.cpp b/utils/mxtk/mxlineedit.cpp
new file mode 100644
index 0000000..035852f
--- /dev/null
+++ b/utils/mxtk/mxlineedit.cpp
@@ -0,0 +1,140 @@
+//
+// mxToolKit (c) 1999 by Mete Ciragan
+//
+// file: mxLineEdit.cpp
+// implementation: Win32 API
+// last modified: Mar 18 1999, Mete Ciragan
+// copyright: The programs and associated files contained in this
+// distribution were developed by Mete Ciragan. The programs
+// are not in the public domain, but they are freely
+// distributable without licensing fees. These programs are
+// provided without guarantee or warrantee expressed or
+// implied.
+//
+#include "mxtk/mxLineEdit.h"
+#include <windows.h>
+#include "mxtk/mxEvent.h"
+#include "mxtk/mxWindow.h"
+
+
+class mxLineEdit_i
+{
+public:
+ int dummy;
+};
+
+#include "tier0/dbg.h"
+
+
+typedef LRESULT (CALLBACK * WndProc_t)(HWND hwnd, UINT uMessage, WPARAM wParam, LPARAM lParam);
+
+static WndProc_t s_OldWndProc = 0;
+
+static LRESULT CALLBACK EditWndProc (HWND hwnd, UINT uMessage, WPARAM wParam, LPARAM lParam)
+{
+ int iret = 0;
+
+ // This lovely bit of hackery ensures we get return key events
+ if ( uMessage == WM_CHAR)
+ {
+ iret = s_OldWndProc( hwnd, uMessage, wParam, lParam );
+
+ // Post the message directly to all windows in the hierarchy until
+ // someone responds
+ mxLineEdit *lineEdit = (mxLineEdit *) GetWindowLong (hwnd, GWL_USERDATA);
+ mxEvent event;
+ event.event = mxEvent::KeyDown;
+ event.action = lineEdit->getId();
+ event.key = (int) wParam;
+
+ mxWindow* window = lineEdit->getParent();
+ while (window)
+ {
+ if (window->handleEvent (&event))
+ break;
+
+ window = window->getParent ();
+ }
+ }
+ else
+ {
+ if ( uMessage == WM_LBUTTONDOWN )
+ {
+ SetFocus( hwnd );
+ }
+ iret = s_OldWndProc( hwnd, uMessage, wParam, lParam );
+ }
+ return iret;
+}
+
+mxLineEdit::mxLineEdit (mxWindow *parent, int x, int y, int w, int h, const char *label, int id, int style)
+: mxWidget (parent, x, y, w, h, label)
+{
+ if (!parent)
+ return;
+
+ DWORD dwStyle = WS_VISIBLE | WS_CHILD | ES_AUTOHSCROLL | WS_TABSTOP; // | ES_WANTRETURN | ES_MULTILINE;
+ HWND hwndParent = (HWND) ((mxWidget *) parent)->getHandle ();
+
+ if (style == ReadOnly)
+ dwStyle |= ES_READONLY;
+ else if (style == Password)
+ dwStyle |= ES_PASSWORD;
+
+ if (!s_OldWndProc)
+ {
+ WNDCLASSEX editClass;
+ GetClassInfoEx( (HINSTANCE) GetModuleHandle (NULL), "EDIT", &editClass );
+ s_OldWndProc = editClass.lpfnWndProc;
+
+ editClass.cbSize = sizeof(WNDCLASSEX);
+ editClass.cbClsExtra = 0;
+ editClass.lpfnWndProc = EditWndProc;
+ editClass.lpszClassName = "mx_edit";
+ RegisterClassEx( &editClass );
+ }
+
+ void *handle = (void *) CreateWindowEx (WS_EX_CLIENTEDGE, "mx_edit", label, dwStyle, //WS_VISIBLE | WS_CHILD | ES_AUTOHSCROLL,
+ x, y, w, h, hwndParent,
+ (HMENU) id, (HINSTANCE) GetModuleHandle (NULL), NULL);
+
+ SendMessage ((HWND) handle, WM_SETFONT, (WPARAM) (HFONT) GetStockObject (ANSI_VAR_FONT), MAKELPARAM (TRUE, 0));
+ SendMessage ((HWND) getHandle (), EM_LIMITTEXT, (WPARAM) 256, 0L);
+ SetWindowLong ((HWND) handle, GWL_USERDATA, (LONG) this);
+
+ setHandle (handle);
+ setType (MX_LINEEDIT);
+ setParent (parent);
+ setId (id);
+}
+
+
+
+mxLineEdit::~mxLineEdit ()
+{
+}
+
+void mxLineEdit::clear()
+{
+ SendMessage( (HWND)getHandle(), WM_SETTEXT, (WPARAM)0, (LPARAM)"" );
+}
+
+void mxLineEdit::getText( char *buf, size_t bufsize )
+{
+ buf[ 0 ] = 0;
+ SendMessage( (HWND) getHandle (), WM_GETTEXT, (WPARAM)bufsize, (LPARAM)buf );
+}
+
+void
+mxLineEdit::setMaxLength (int max)
+{
+ SendMessage ((HWND) getHandle (), EM_LIMITTEXT, (WPARAM) max, 0L);
+}
+
+
+
+int
+mxLineEdit::getMaxLength () const
+{
+ return (int) SendMessage ((HWND) getHandle (), EM_GETLIMITTEXT, 0, 0L);
+}