]> git.ipfire.org Git - thirdparty/newt.git/commitdiff
allowing changing colors in individual labels, scrollbars, entries, scales
authorMiroslav Lichvar <mlichvar@redhat.com>
Wed, 18 May 2011 17:23:39 +0000 (19:23 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Wed, 18 May 2011 17:23:39 +0000 (19:23 +0200)
entry.c
label.c
newt.0.52.ver
newt.h
scale.c
scrollbar.c
textbox.c

diff --git a/entry.c b/entry.c
index 5585ce5d1a0bb1b92065ec125c9228ee390fdccc..a5ae6889f16c42f5d0961edb448fdfa23a4b8d44 100644 (file)
--- a/entry.c
+++ b/entry.c
@@ -23,6 +23,8 @@ struct entry {
     int firstChar;             /* first character position being shown */
     newtEntryFilter filter;
     void * filterData;
+    int cs;
+    int csDisabled;
 };
 
 static int previous_char(const char *buf, int pos);
@@ -117,6 +119,9 @@ newtComponent newtEntry(int left, int top, const char * initialValue, int width,
        en->cursorPosition = 0;
     }
 
+    en->cs = NEWT_COLORSET_ENTRY;
+    en->csDisabled = NEWT_COLORSET_DISENTRY;
+
     return co;
 }
 
@@ -184,9 +189,9 @@ static void entryDraw(newtComponent co) {
     if (!co->isMapped) return;
 
     if (en->flags & NEWT_FLAG_DISABLED)
-       SLsmg_set_color(NEWT_COLORSET_DISENTRY);
+       SLsmg_set_color(en->csDisabled);
     else
-       SLsmg_set_color(NEWT_COLORSET_ENTRY);
+       SLsmg_set_color(en->cs);
 
     if (en->flags & NEWT_FLAG_HIDDEN) {
        newtGotorc(co->top, co->left);
@@ -255,6 +260,14 @@ void newtEntrySetFlags(newtComponent co, int flags, enum newtFlagsSense sense) {
     newtGotorc(row, col);
 }
 
+void newtEntrySetColors(newtComponent co, int normal, int disabled) {
+    struct entry * en = co->data;
+
+    en->cs = normal;
+    en->csDisabled = disabled;
+    entryDraw(co);
+}
+
 static void entryDestroy(newtComponent co) {
     struct entry * en = co->data;
 
diff --git a/label.c b/label.c
index bc9e510f09748e205e4ba31334bc3ea5a350894c..85fa518a99f157dda0e820ee01356bd332b7d7f8 100644 (file)
--- a/label.c
+++ b/label.c
@@ -8,6 +8,7 @@
 struct label {
     char * text;
     int length;
+    int cs;
 };
 
 static void labelDraw(newtComponent co);
@@ -41,6 +42,7 @@ newtComponent newtLabel(int left, int top, const char * text) {
 
     la->length = strlen(text);
     la->text = strdup(text);
+    la->cs = COLORSET_LABEL;
 
     return co;
 }
@@ -63,12 +65,19 @@ void newtLabelSetText(newtComponent co, const char * text) {
     labelDraw(co);
 }
 
+void newtLabelSetColors(newtComponent co, int colorset) {
+    struct label * la = co->data;
+
+    la->cs = colorset;
+    labelDraw(co);
+}
+
 static void labelDraw(newtComponent co) {
     struct label * la = co->data;
 
     if (!co->isMapped) return;
 
-    SLsmg_set_color(COLORSET_LABEL);
+    SLsmg_set_color(la->cs);
 
     newtGotorc(co->top, co->left);
     SLsmg_write_string(la->text);
index bad81e87aa5cb336e09841e19dd02daaf36b164a..10ea1b190f1b65bbc4b8a5a158a7c75bc39acdf0 100644 (file)
@@ -152,3 +152,12 @@ NEWT_0.52.11 {
        global:
                newtRadioSetCurrent;
 } NEWT_0.52.9;
+
+NEWT_0.52.13 {
+       global:
+               newtEntrySetColors;
+               newtLabelSetColors;
+               newtScaleSetColors;
+               newtScrollbarSetColors;
+               newtTextboxSetColors;
+} NEWT_0.52.11;
diff --git a/newt.h b/newt.h
index 81a57ca251c2f574254ca3097af7508ca450114a..103b1390db73be1a5a028156bafa30e95d413bdc 100644 (file)
--- a/newt.h
+++ b/newt.h
@@ -161,9 +161,11 @@ void newtGetScreenSize(int * cols, int * rows);
 
 newtComponent newtLabel(int left, int top, const char * text);
 void newtLabelSetText(newtComponent co, const char * text);
+void newtLabelSetColors(newtComponent co, int colorset);
 newtComponent newtVerticalScrollbar(int left, int top, int height,
                                    int normalColorset, int thumbColorset);
 void newtScrollbarSet(newtComponent co, int where, int total);
+void newtScrollbarSetColors(newtComponent co, int normal, int thumb);
 
 newtComponent newtListbox(int left, int top, int height, int flags);
 void * newtListboxGetCurrent(newtComponent co);
@@ -214,6 +216,7 @@ newtComponent newtTextbox(int left, int top, int width, int height, int flags);
 void newtTextboxSetText(newtComponent co, const char * text);
 void newtTextboxSetHeight(newtComponent co, int height);
 int newtTextboxGetNumLines(newtComponent co);
+void newtTextboxSetColors(newtComponent co, int normal, int active);
 char * newtReflowText(char * text, int width, int flexDown, int flexUp,
                      int * actualWidth, int * actualHeight);
 
@@ -251,9 +254,11 @@ void newtEntrySet(newtComponent co, const char * value, int cursorAtEnd);
 void newtEntrySetFilter(newtComponent co, newtEntryFilter filter, void * data);
 char * newtEntryGetValue(newtComponent co);
 void newtEntrySetFlags(newtComponent co, int flags, enum newtFlagsSense sense);
+void newtEntrySetColors(newtComponent co, int normal, int disabled);
 
 newtComponent newtScale(int left, int top, int width, long long fullValue);
 void newtScaleSet(newtComponent co, unsigned long long amount);
+void newtScaleSetColors(newtComponent co, int empty, int full);
 
 void newtComponentAddCallback(newtComponent co, newtCallback f, void * data);
 void newtComponentTakesFocus(newtComponent co, int val);
diff --git a/scale.c b/scale.c
index f9a1f40cd9771c87d137d6f1a4502525536f7615..3dbfca96e20e46f774b4723e38d444e0350ae4b8 100644 (file)
--- a/scale.c
+++ b/scale.c
@@ -9,6 +9,8 @@ struct scale {
     long long fullValue;
     int charsSet;
     unsigned int percentage;
+    int csEmpty;
+    int csFull;
 };
 
 static void scaleDraw(newtComponent co);
@@ -41,6 +43,8 @@ newtComponent newtScale(int left, int top, int width, long long fullValue) {
     sc->fullValue = fullValue;
     sc->charsSet = 0;
     sc->percentage = 0;
+    sc->csEmpty = NEWT_COLORSET_EMPTYSCALE;
+    sc->csFull = NEWT_COLORSET_FULLSCALE;
 
     return co;
 }
@@ -67,6 +71,14 @@ void newtScaleSet(newtComponent co, unsigned long long amount) {
     }
 }
 
+void newtScaleSetColors(newtComponent co, int empty, int full) {
+    struct scale * sc = co->data;
+
+    sc->csEmpty = empty;
+    sc->csFull = full;
+    scaleDraw(co);
+}
+
 static void scaleDraw(newtComponent co) {
     struct scale * sc = co->data;
     int i;
@@ -79,11 +91,11 @@ static void scaleDraw(newtComponent co) {
 
     sprintf(percent, "%3d%%", sc->percentage);
 
-    SLsmg_set_color(NEWT_COLORSET_FULLSCALE);
+    SLsmg_set_color(sc->csFull);
     
     for (i = 0; i < co->width; i++) {
         if (i == sc->charsSet)
-            SLsmg_set_color(NEWT_COLORSET_EMPTYSCALE);
+            SLsmg_set_color(sc->csEmpty);
         if (i >= xlabel && i < xlabel+4)
             SLsmg_write_char(percent[i-xlabel]);
         else
index b89ede2beb32dac93e57b1dc4a37e647f6194848..0c706b37274e3f4c670b94102eff0d5119647d46 100644 (file)
@@ -69,6 +69,14 @@ newtComponent newtVerticalScrollbar(int left, int top, int height,
     return co;
 }
 
+void newtScrollbarSetColors(newtComponent co, int normal, int thumb) {
+    struct scrollbar * sb = co->data;
+
+    sb->cs = normal;
+    sb->csThumb = thumb;
+    sbDraw(co);
+}
+
 static void sbDraw(newtComponent co) {
     struct scrollbar * sb = co->data;
     int i;
index 6429062f1fa39c5a7c75a3ab1ac7dc43b3657396..8bbd409d76bf0ec1919ebc40f6b9c49c613f0f5a 100644 (file)
--- a/textbox.c
+++ b/textbox.c
@@ -14,10 +14,12 @@ struct textbox {
     int numLines;
     int linesAlloced;
     int doWrap;
-    newtComponent sb_act, sb;
+    newtComponent sb;
     int topLine;
     int textWidth;
     int isActive;
+    int cs;
+    int csActive;
 };
 
 static char * expandTabs(const char * text);
@@ -45,7 +47,6 @@ static void textboxMapped(newtComponent co, int isMapped) {
     co->isMapped = isMapped;
     if (tb->sb) {
        tb->sb->ops->mapped(tb->sb, isMapped);
-       tb->sb_act->ops->mapped(tb->sb_act, isMapped);
     }
 }
 
@@ -57,7 +58,6 @@ static void textboxPlace(newtComponent co, int newLeft, int newTop) {
 
     if (tb->sb) {
        tb->sb->ops->place(tb->sb, co->left + co->width - 1, co->top);
-       tb->sb_act->ops->place(tb->sb_act, co->left + co->width - 1, co->top);
     }
 }
 
@@ -115,21 +115,29 @@ newtComponent newtTextbox(int left, int top, int width, int height, int flags) {
     tb->topLine = 0;
     tb->textWidth = width;
     tb->isActive = 0;
+    tb->cs = COLORSET_TEXTBOX;
+    tb->csActive = COLORSET_ACTTEXTBOX;
 
     if (flags & NEWT_FLAG_SCROLL) {
        co->width += 2;
-       tb->sb_act = newtVerticalScrollbar(co->left + co->width - 1, co->top, 
-                          co->height, COLORSET_ACTTEXTBOX, COLORSET_TEXTBOX);
        tb->sb = newtVerticalScrollbar(co->left + co->width - 1, co->top, 
-                          co->height, COLORSET_TEXTBOX, COLORSET_TEXTBOX);
+                          co->height, tb->cs, tb->cs);
        co->takesFocus = 1;
     } else {
-       tb->sb_act = tb->sb = NULL;
+       tb->sb = NULL;
     }
 
     return co;
 }
 
+void newtTextboxSetColors(newtComponent co, int normal, int active) {
+    struct textbox * tb = co->data;
+
+    tb->cs = normal;
+    tb->csActive = active;
+    textboxDraw(co);
+}
+
 static char * expandTabs(const char * text) {
     int bufAlloced = strlen(text) + 40;
     char * buf, * dest;
@@ -369,16 +377,12 @@ static void textboxDraw(newtComponent c) {
 
     if (tb->sb) {
        size = tb->numLines - c->height;
-       if (tb->isActive) {
-               newtScrollbarSet(tb->sb_act, tb->topLine, size ? size : 0);
-               tb->sb_act->ops->draw(tb->sb_act);
-       } else {
-               newtScrollbarSet(tb->sb, tb->topLine, size ? size : 0);
-               tb->sb->ops->draw(tb->sb);
-       }
+       newtScrollbarSet(tb->sb, tb->topLine, size ? size : 0);
+       newtScrollbarSetColors(tb->sb, tb->isActive ? tb->csActive :
+                       tb->cs, tb->cs);
     }
 
-    SLsmg_set_color(NEWT_COLORSET_TEXTBOX);
+    SLsmg_set_color(tb->cs);
 
     for (i = 0; (i + tb->topLine) < tb->numLines && i < c->height; i++) {
        newtGotorc(c->top + i, c->left);
@@ -469,8 +473,6 @@ static void textboxDestroy(newtComponent co) {
 
     if (tb->sb)
        tb->sb->ops->destroy(tb->sb);
-    if (tb->sb_act)
-       tb->sb_act->ops->destroy(tb->sb_act);
     for (i = 0; i < tb->numLines; i++) 
        free(tb->lines[i]);
     free(tb->lines);