tags 429351 + patch
thanks
Attached is a patch to newt to allow users of checkboxes to specify the
width of the checkbox so that several vertical checkboxes will be
appropriately aligned on the right for rtl text. The patch adds an api
function to newt.
This patch is intended to come after the 020 bidi patch.
Baruch
Index: newt-0.52.2/checkbox.c
===================================================================
--- newt-0.52.2.orig/checkbox.c 2007-06-22 18:01:41.000000000 +0100
+++ newt-0.52.2/checkbox.c 2007-06-22 20:07:37.000000000 +0100
@@ -18,6 +18,7 @@
const void * data;
int flags;
int hasFocus;
+ int width;
};
static void makeActive(newtComponent co);
@@ -127,7 +128,7 @@
co->callback = NULL;
co->height = 1;
- co->width = wstrlen(text, -1) + 4;
+ co->width = cb->width = wstrlen(text, -1) + 4;
co->top = top;
co->left = left;
co->takesFocus = 1;
@@ -135,6 +136,13 @@
return co;
}
+void newtCheckboxSetWidth(newtComponent co, int width)
+{
+ width += 4;
+ if (width >= ((struct checkbox *)co->data)->width)
+ ((struct checkbox *)co->data)->width = width;
+}
+
void newtCheckboxSetFlags(newtComponent co, int flags, enum newtFlagsSense sense) {
struct checkbox * cb = co->data;
int row, col;
@@ -159,6 +167,8 @@
static void cbDraw(newtComponent c) {
struct checkbox * cb = c->data;
+ char *tmp;
+ char chOpen, chClose;
if (c->top == -1 || !c->isMapped) return;
@@ -175,25 +185,30 @@
newtGotorc(c->top, c->left);
switch (cb->type) {
- case RADIO:
- SLsmg_write_string("( ) ");
- break;
-
- case CHECK:
- SLsmg_write_string("[ ] ");
- break;
+ case RADIO:
+ chOpen = '(';
+ chClose = ')';
+ break;
- default:
- break;
- }
+ case CHECK:
+ chOpen = '[';
+ chClose = ']';
+ break;
- write_string_int(cb->text, NULL);
+ default:
+ chOpen = chClose = ' ';
+ break;
+ }
+ tmp = malloc(4 + strlen(cb->text) + 1);
+ if (!tmp)
+ return;
+ *tmp = 0;
+ sprintf(tmp, "%c%c%c %s", chOpen, *cb->result, chClose, cb->text);
if (cb->hasFocus)
SLsmg_set_color(cb->active);
-
- newtGotorc(c->top, c->left + 1);
- SLsmg_write_char(*cb->result);
+ write_nstring_int(tmp, cb->width, NULL);
+ free(tmp);
}
static void cbDestroy(newtComponent co) {