diff --git a/src/common/main.c b/src/common/main.c index fd8da52..abeb242 100644 --- a/src/common/main.c +++ b/src/common/main.c @@ -341,6 +341,7 @@ static void do_attribute(Sheet *cursheet, Key action) line_msg(_("Cell attribute:"),_("Cell is locked")); return; } + ColorAspect ca = FOREGROUND; switch ((int)action) { case ADJUST_CENTER: ++adj; /* drop through */ @@ -373,12 +374,7 @@ static void do_attribute(Sheet *cursheet, Key action) /* 5 -- set precision */ /*{{{*/ case ADJUST_PRECISION: { - size_t ex,offx; - int n; - - offx=0; - ex=0; - n = getprecision(fcell); + int n = getprecision(fcell); const char* prompt = _("Precision for block:"); if (onecell) prompt = _("Precision for cell:"); int c = line_numedit(&n, prompt); @@ -388,6 +384,22 @@ static void do_attribute(Sheet *cursheet, Key action) break; } /*}}}*/ + /* Set a color */ /*{{{*/ + case ADJUST_BACKGROUND: + ca = BACKGROUND; + /* FALL THROUGH */ + case ADJUST_FOREGROUND: { + int n = getcolor(fcell, ca); + const char* prompt = _("%s for block:"); + if (onecell) prompt = _("%s for cell:"); + char pbuf[256]; + sprintf(pbuf, prompt, ColorAspect_Name[ca]); + int c = line_numedit(&n, pbuf); + if (c < 0) return; + for (ALL_LOCS_IN_REGION(cursheet,w)) + changed = setcolor(cursheet, w, ca, (ColorNum)n) || changed; + break; + } /* 6 -- shadow */ /*{{{*/ case ADJUST_SHADOW: { @@ -1443,6 +1455,8 @@ int do_sheetcmd(Sheet *cursheet, Key c, int moveonly) case ADJUST_SHADOW: case ADJUST_BOLD: case ADJUST_UNDERLINE: + case ADJUST_FOREGROUND: + case ADJUST_BACKGROUND: case ADJUST_TRANSPARENT: case ADJUST_LABEL: case ADJUST_LOCK: diff --git a/src/common/main.h b/src/common/main.h index 7915cd3..84d9cb5 100644 --- a/src/common/main.h +++ b/src/common/main.h @@ -85,7 +85,9 @@ typedef enum { FILL_BLOCK = -58, ADJUST_DECIMAL = -59, ADJUST_COMPACT = -60, - ADJUST_HEXACT = -61 + ADJUST_HEXACT = -61, + ADJUST_FOREGROUND = -62, + ADJUST_BACKGROUND = -63 } Key; extern int do_sheetcmd(Sheet *cursheet, Key c, int moveonly); diff --git a/src/common/sheet.c b/src/common/sheet.c index 84ac653..bc8520d 100644 --- a/src/common/sheet.c +++ b/src/common/sheet.c @@ -731,6 +731,21 @@ DEFSETTER(igncell, bool, ignored); DEFSETTER(setfltformat, FloatFormat, fform); DEFSETTER(setprecision, int, precision); +/* sadly color has an extra argument */ +bool setcolor(Sheet *sheet, const Location at, ColorAspect asp, ColorNum col) +{ + assert(sheet != (Sheet*)0); + bool isnew = false; + Cell* thecell = initcellofsheet(sheet, at, &isnew); + if (isnew) sheet->changed = true; + if (thecell->aspect[asp] != col) { + thecell->aspect[asp] = col; + sheet->changed = true; + return true; + } + return isnew; +} + /* clk -- clock cell */ /*{{{*/ void clk(Sheet *sheet, const Location at) { diff --git a/src/common/sheet.h b/src/common/sheet.h index 3c622a4..6c63018 100644 --- a/src/common/sheet.h +++ b/src/common/sheet.h @@ -100,6 +100,7 @@ bool setadjust(Sheet *sheet, const Location at, Adjust adjust); bool shadow(Sheet *sheet, const Location at, bool yep); bool bold(Sheet *sheet, const Location at, bool yep); bool underline(Sheet *sheet, const Location at, bool yep); +bool setcolor(Sheet *sheet, const Location at, ColorAspect asp, ColorNum col); bool lockcell(Sheet *sheet, const Location at, bool yep); bool maketrans(Sheet *sheet, const Location at, bool yep); bool igncell(Sheet *sheet, const Location at, bool yep); diff --git a/src/display.c b/src/display.c index aa701e3..deb28ec 100644 --- a/src/display.c +++ b/src/display.c @@ -117,12 +117,15 @@ static int do_attribute(Sheet *cursheet) case 2: { const char *typemenu[] = - { _("bB)old"), _("uU)nderline"), NULL }; + { _("bB)old"), _("uU)nderline"), + _("fF)oreground"), _("kBack)ground"), NULL }; switch (c = line_menu(prompt, typemenu, 0)) { case -2: case -1: c = K_INVALID; break; case 0: c = ADJUST_BOLD; break; case 1: c = ADJUST_UNDERLINE; break; + case 2: c = ADJUST_FOREGROUND; break; + case 3: c = ADJUST_BACKGROUND; break; default: assert(0); } break; @@ -530,6 +533,17 @@ void redraw_sheet(Sheet *sheet) } else realsize=size; ms = getmarkstate(sheet); + int usecp = 0; + ColorNum fg = getcolor(cell, FOREGROUND); + ColorNum bg = getcolor(cell, BACKGROUND); + while (usecp < curcp) { + unsigned short pfg, pbg; + pair_content(usecp, &pfg, &pbg); + if (fg == pfg && bg == pbg) break; + ++usecp; + } + if (usecp == curcp) init_pair(curcp++, fg, bg); + wcolor_set(stdscr, usecp, NULL); invert = (ms != UNMARKED) && loc_in_box(tmp, sheet->mark1, sheet->mark2); if (x == sheet->cur[X] && (y-header+sheet->offy) == sheet->cur[Y]) @@ -540,6 +554,7 @@ void redraw_sheet(Sheet *sheet) (void)mvwaddstr(stdscr,sheet->oriy+y,sheet->orix+width,buf+cutoff); for (fill=mbslen(buf+cutoff); fill