2025-10-08 17:16:03 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
#include <Mw/Milsko.h>
|
|
|
|
|
|
|
|
|
|
static int create(MwWidget handle) {
|
|
|
|
|
MwSetDefault(handle);
|
|
|
|
|
|
2025-10-08 17:34:14 +00:00
|
|
|
MwLLSetCursor(handle->lowlevel, &MwCursorText, &MwCursorTextMask);
|
|
|
|
|
|
2025-10-08 17:16:03 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void draw(MwWidget handle) {
|
2025-10-08 18:42:01 +00:00
|
|
|
MwRect r;
|
|
|
|
|
MwLLColor base = MwParseColor(handle, MwGetText(handle, MwNbackground));
|
|
|
|
|
MwLLColor text = MwParseColor(handle, MwGetText(handle, MwNforeground));
|
|
|
|
|
const char* str = MwGetText(handle, MwNtext);
|
2025-10-08 17:16:03 +00:00
|
|
|
|
|
|
|
|
r.x = 0;
|
|
|
|
|
r.y = 0;
|
|
|
|
|
r.width = MwGetInteger(handle, MwNwidth);
|
|
|
|
|
r.height = MwGetInteger(handle, MwNheight);
|
|
|
|
|
|
|
|
|
|
MwDrawFrame(handle, &r, base, (handle->pressed || MwGetInteger(handle, MwNchecked)) ? 1 : 0);
|
|
|
|
|
MwDrawRect(handle, &r, base);
|
2025-10-08 18:42:01 +00:00
|
|
|
if(str != NULL) {
|
|
|
|
|
int h = MwTextHeight(handle, "M");
|
|
|
|
|
MwPoint p;
|
2025-10-08 17:16:03 +00:00
|
|
|
|
2025-10-08 18:42:01 +00:00
|
|
|
p.x = (r.height - h) / 2;
|
|
|
|
|
p.y = r.height / 2;
|
|
|
|
|
|
|
|
|
|
/* limit so there isn't a crazy padding */
|
|
|
|
|
if(p.x > 4) p.x = 4;
|
|
|
|
|
|
|
|
|
|
MwDrawText(handle, &p, str, 0, MwALIGNMENT_BEGINNING, text);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MwLLFreeColor(text);
|
2025-10-08 17:16:03 +00:00
|
|
|
MwLLFreeColor(base);
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-08 18:13:13 +00:00
|
|
|
static void key(MwWidget handle, int code) {
|
2025-10-08 18:42:01 +00:00
|
|
|
const char* str = MwGetText(handle, MwNtext);
|
|
|
|
|
char* out;
|
|
|
|
|
char buf[2];
|
|
|
|
|
if(str == NULL) str = "";
|
|
|
|
|
|
|
|
|
|
if(code == MwLLKeyBackSpace) {
|
|
|
|
|
if(strlen(str) == 0) return;
|
|
|
|
|
out = malloc(strlen(str) + 1);
|
|
|
|
|
|
|
|
|
|
strcpy(out, str);
|
|
|
|
|
out[strlen(out) - 1] = 0;
|
|
|
|
|
|
|
|
|
|
MwSetText(handle, MwNtext, out);
|
|
|
|
|
|
|
|
|
|
free(out);
|
|
|
|
|
} else {
|
|
|
|
|
buf[0] = code;
|
|
|
|
|
buf[1] = 0;
|
|
|
|
|
|
|
|
|
|
out = malloc(strlen(str) + 1 + 1);
|
|
|
|
|
strcpy(out, str);
|
|
|
|
|
strcat(out, buf);
|
|
|
|
|
|
|
|
|
|
MwSetText(handle, MwNtext, out);
|
|
|
|
|
|
|
|
|
|
free(out);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MwForceRender(handle);
|
2025-10-08 18:13:13 +00:00
|
|
|
}
|
|
|
|
|
|
2025-10-08 17:16:03 +00:00
|
|
|
MwClassRec MwTextClassRec = {
|
2025-10-08 18:03:46 +00:00
|
|
|
create, /* create */
|
|
|
|
|
NULL, /* destroy */
|
|
|
|
|
draw, /* draw */
|
|
|
|
|
NULL, /* click */
|
|
|
|
|
NULL, /* parent_resize */
|
|
|
|
|
NULL, /* prop_change */
|
|
|
|
|
NULL, /* mouse_move */
|
|
|
|
|
MwForceRender, /* mouse_up */
|
|
|
|
|
MwForceRender, /* mouse_down */
|
2025-10-08 18:13:13 +00:00
|
|
|
key, /* key */
|
2025-10-08 18:03:46 +00:00
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL};
|
2025-10-08 17:16:03 +00:00
|
|
|
MwClass MwTextClass = &MwTextClassRec;
|