newtDefaultMappedHandler,
} ;
+/*
+ * return NULL on malloc error.
+ * FIXME: all createButton calls should check for error
+ */
static newtComponent createButton(int left, int row, const char * text, int compact) {
newtComponent co;
struct button * bu;
+ int width = wstrlen(text,-1);
co = malloc(sizeof(*co));
+ if (co == NULL)
+ return NULL;
bu = malloc(sizeof(struct button));
+ if (bu == NULL) {
+ free (co);
+ return NULL;
+ }
co->data = bu;
+ co->destroyCallback = NULL;
bu->text = strdup(text);
bu->compact = compact;
if (bu->compact) {
co->height = 1;
- co->width = strlen(text) + 3;
+ co->width = width + 3;
} else {
co->height = 4;
- co->width = strlen(text) + 5;
+ co->width = width + 5;
}
co->top = row;
newtGotorc(co->top, co->left);
return co;
+
}
newtComponent newtCompactButton(int left, int row, const char * text) {
SLsmg_set_color(NEWT_COLORSET_BUTTON);
if (bu->compact) {
- if (active)
+ if (!active)
SLsmg_set_color(NEWT_COLORSET_COMPACTBUTTON);
- else
+ else if (SLtt_Use_Ansi_Colors)
SLsmg_set_color(NEWT_COLORSET_BUTTON);
+ else
+ SLsmg_set_color(NEWT_COLORSET_ACTBUTTON);
newtGotorc(co->top+ pushed, co->left + 1 + pushed);
SLsmg_write_char('<');
SLsmg_write_string(bu->text);
buttonDrawText(co, active, pushed);
}
+ /* put cursor at beginning of text for better accessibility */
+ newtGotorc(co->top + (bu->compact ? 0 : 1) + pushed, co->left + 1 + pushed + 1);
}
static void buttonDrawText(newtComponent co, int active, int pushed) {
struct eventResult er;
struct button * bu = co->data;
+ er.result = ER_IGNORED;
+
if (ev.when == EV_NORMAL) {
switch (ev.event) {
case EV_FOCUS:
}
er.result = ER_EXITFORM;
- } else
+ } else
er.result = ER_IGNORED;
break;
+ case EV_MOUSE:
+ if (ev.u.mouse.type == MOUSE_BUTTON_DOWN &&
+ co->top <= ev.u.mouse.y &&
+ co->top + co->height - !bu->compact > ev.u.mouse.y &&
+ co->left <= ev.u.mouse.x &&
+ co->left + co->width - !bu->compact > ev.u.mouse.x) {
+ if (!bu->compact) {
+ buttonDrawIt(co, 1, 1);
+ newtRefresh();
+ newtDelay(150000);
+ buttonDrawIt(co, 1, 0);
+ newtRefresh();
+ newtDelay(150000);
+ }
+ er.result = ER_EXITFORM;
+ }
+ break;
}
- } else
- er.result = ER_IGNORED;
+ }
return er;
}