From: ewt Date: Wed, 4 Dec 1996 19:16:43 +0000 (+0000) Subject: added newtEntrySetFlags(), NEWT_ENTRY_DISABLED X-Git-Tag: v0-9~35 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=38f35ccded8ccabfa744e83774ab57cd6b1703ec;p=thirdparty%2Fnewt.git added newtEntrySetFlags(), NEWT_ENTRY_DISABLED --- diff --git a/entry.c b/entry.c index 5e9e54b..7aa76d3 100644 --- a/entry.c +++ b/entry.c @@ -63,7 +63,6 @@ newtComponent newtEntry(int left, int top, char * initialValue, int width, co->left = left; co->height = 1; co->width = width; - co->takesFocus = 1; co->callback = NULL; co->ops = &entryOps; @@ -74,6 +73,11 @@ newtComponent newtEntry(int left, int top, char * initialValue, int width, en->bufUsed = 0; en->bufAlloced = width + 1; + if (!(en->flags & NEWT_ENTRY_DISABLED)) + co->takesFocus = 1; + else + co->takesFocus = 0; + if (initialValue && strlen(initialValue) > width) { en->bufAlloced = strlen(initialValue) + 1; } @@ -98,10 +102,14 @@ static void entryDraw(newtComponent co) { int len; if (co->top == -1) return; + + if (en->flags & NEWT_ENTRY_DISABLED) + SLsmg_set_color(NEWT_COLORSET_DISENTRY); + else + SLsmg_set_color(NEWT_COLORSET_ENTRY); if (en->flags & NEWT_ENTRY_HIDDEN) { newtGotorc(co->top, co->left); - SLsmg_set_color(COLORSET_ENTRY); for (i = 0; i < co->width; i++) SLsmg_write_char('_'); newtGotorc(co->top, co->left); @@ -110,7 +118,6 @@ static void entryDraw(newtComponent co) { } newtGotorc(co->top, co->left); - SLsmg_set_color(COLORSET_ENTRY); if (en->cursorPosition < en->firstChar) { /* scroll to the left */ @@ -140,6 +147,22 @@ static void entryDraw(newtComponent co) { newtGotorc(co->top, co->left + (en->cursorPosition - en->firstChar)); } +void newtEntrySetFlags(newtComponent co, int flags, enum newtFlagsSense sense) { + struct entry * en = co->data; + int row, col; + + en->flags = newtSetFlags(en->flags, flags, sense); + + if (!(en->flags & NEWT_ENTRY_DISABLED)) + co->takesFocus = 1; + else + co->takesFocus = 0; + + newtGetrc(&row, &col); + entryDraw(co); + newtGotorc(row, col); +} + static void entryDestroy(newtComponent co) { struct entry * en = co->data; diff --git a/newt.h b/newt.h index ca78846..2f16c38 100644 --- a/newt.h +++ b/newt.h @@ -20,6 +20,9 @@ #define NEWT_COLORSET_ROOTTEXT 18 #define NEWT_COLORSET_EMPTYSCALE 19 #define NEWT_COLORSET_FULLSCALE 20 +#define NEWT_COLORSET_DISENTRY 21 + +enum newtFlagsSense { NEWT_FLAGS_SET, NEWT_FLAGS_RESET }; struct newtColors { char * rootFg, * rootBg; @@ -40,6 +43,7 @@ struct newtColors { char * helpLineFg, * helpLineBg; char * rootTextFg, * rootTextBg; char * emptyScale, * fullScale; + char * disabledEntryFg, * disabledEntryBg; }; typedef struct newtComponent * newtComponent; @@ -127,10 +131,12 @@ void newtFormAddHotKey(newtComponent co, int key); #define NEWT_ENTRY_SCROLL (1 << 0) #define NEWT_ENTRY_HIDDEN (1 << 1) #define NEWT_ENTRY_RETURNEXIT (1 << 2) +#define NEWT_ENTRY_DISABLED (1 << 3) newtComponent newtEntry(int left, int top, char * initialValue, int width, char ** resultPtr, int flags); void newtEntrySet(newtComponent co, char * value, int cursorAtEnd); +void newtEntrySetFlags(newtComponent co, int flags, enum newtFlagsSense sense); newtComponent newtScale(int left, int top, int width, long long fullValue); void newtScaleSet(newtComponent co, long long amount);