1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
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);
}
|