2025-10-10 06:08:19 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
#include <Mw/Milsko.h>
|
|
|
|
|
|
|
|
|
|
static int create(MwWidget handle) {
|
2025-10-10 11:45:27 +00:00
|
|
|
int st;
|
|
|
|
|
MwEntry e;
|
2025-10-10 06:08:19 +00:00
|
|
|
|
|
|
|
|
if((st = MwEntryClass->create(handle)) != 0) return st;
|
|
|
|
|
|
2025-10-10 11:45:27 +00:00
|
|
|
e = handle->internal;
|
2025-10-10 09:17:16 +00:00
|
|
|
e->right = 32;
|
|
|
|
|
|
2025-10-10 06:08:19 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void destroy(MwWidget handle) {
|
|
|
|
|
MwEntryClass->destroy(handle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void draw(MwWidget handle) {
|
|
|
|
|
MwEntryClass->draw(handle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void key(MwWidget handle, int code) {
|
2025-10-10 06:22:14 +00:00
|
|
|
MwEntry e = handle->internal;
|
|
|
|
|
const char* str = MwGetText(handle, MwNtext);
|
|
|
|
|
int ok = 0;
|
|
|
|
|
if(str == NULL) str = "";
|
|
|
|
|
|
|
|
|
|
if(code == '-' && e->cursor == 0 && strchr(str, (int)'-') == NULL) {
|
|
|
|
|
ok = 1;
|
|
|
|
|
} else if('0' <= code && code <= '9') {
|
|
|
|
|
ok = 1;
|
|
|
|
|
} else if(code == '.' && strchr(str, (int)'.') == NULL) {
|
|
|
|
|
ok = 1;
|
2025-10-10 11:45:27 +00:00
|
|
|
} else if(code == MwLLKeyBackSpace || code == MwLLKeyLeft || code == MwLLKeyRight) {
|
2025-10-10 09:17:16 +00:00
|
|
|
ok = 1;
|
2025-10-10 06:22:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(ok) MwEntryClass->key(handle, code);
|
2025-10-10 06:08:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MwClassRec MwNumberEntryClassRec = {
|
|
|
|
|
create, /* create */
|
|
|
|
|
destroy, /* destroy */
|
|
|
|
|
draw, /* draw */
|
|
|
|
|
NULL, /* click */
|
|
|
|
|
NULL, /* parent_resize */
|
|
|
|
|
NULL, /* prop_change */
|
|
|
|
|
NULL, /* mouse_move */
|
|
|
|
|
MwForceRender, /* mouse_up */
|
|
|
|
|
MwForceRender, /* mouse_down */
|
|
|
|
|
key, /* key */
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL};
|
|
|
|
|
MwClass MwNumberEntryClass = &MwNumberEntryClassRec;
|