From 76d34a47f00c24ff9debb0fa11a341ab8d595d90 Mon Sep 17 00:00:00 2001 From: Linas Vepstas Date: Sun, 26 Jul 1998 22:47:17 +0000 Subject: [PATCH] more step towards implementing cell colors git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@919 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/register/splitreg.c | 6 ++ src/register/table-allgui.c | 183 ++++++++---------------------------- src/register/table-allgui.h | 115 +++++++++++++++++++++- src/register/table-gtk.h | 3 + src/register/table-motif.c | 94 ++++++++++++++++-- src/register/table-motif.h | 15 ++- 6 files changed, 265 insertions(+), 151 deletions(-) diff --git a/src/register/splitreg.c b/src/register/splitreg.c index 53b37a752a..770adead72 100644 --- a/src/register/splitreg.c +++ b/src/register/splitreg.c @@ -362,6 +362,12 @@ void xaccInitSplitRegister (SplitRegister *reg, int type) FANCY (desc, QuickFill, DESC); FANCY (balance, Price, BALN); + /* set the color of the cells in the transaction cursor */ + reg->descCell->cell.bg_color = 0xccccff; + reg->balanceCell->cell.bg_color = 0xccccff; + reg->dateCell->cell.bg_color = 0xccccff; + reg->numCell->bg_color = 0xccccff; + /* --------------------------- */ /* define the ledger cursor that handles splits */ /* the cursor is 1 row tall */ diff --git a/src/register/table-allgui.c b/src/register/table-allgui.c index 7a4867f9d4..def98696e8 100644 --- a/src/register/table-allgui.c +++ b/src/register/table-allgui.c @@ -122,113 +122,30 @@ xaccSetTableSize (Table * table, int phys_rows, int phys_cols, } /* ==================================================== */ -/* in C, we don't have templates. So cook up a $define that acts like a - * template. This one will resize a 2D array. - */ -#define RESIZE_ARR(table_rows,table_cols,new_rows,new_cols,arr,type,null_val,free_cell_op) \ +#define NOOP(x) /* a big old no-op */ +#define FREEUP(x) { if(x) free(x); } + +#define FREE_ARR(arrname,freeup,killval) \ { \ - int old_rows, old_cols; \ int i,j; \ - \ - /* save old table size */ \ - old_rows = table_rows; \ - old_cols = table_cols; \ - if (0 > old_rows) old_rows = 0; \ - if (0 > old_cols) old_cols = 0; \ - \ - /* realloc to get the new table size. Note that the */ \ - /* new table may be wider or slimmer, taller or shorter. */ \ - if (old_rows >= new_rows) { \ - if (old_cols >= new_cols) { \ - \ - /* if we are here, new table has fewer cols */ \ - /* simply truncate columns */ \ - for (i=0; iarrname) { \ + for (i=0; inum_phys_rows; i++) { \ + if (table->arrname[i]) { \ + for (j=0; jnum_phys_cols; j++) { \ + freeup (table->arrname[i][j]); \ + table->arrname[i][j] = killval; \ } \ + free (table->arrname[i]); \ } \ - } else { \ - \ - /* if we are here, the new table has more */ \ - /* columns. Realloc the columns. */ \ - for (i=0; i= new_cols) { \ - \ - /* new table has fewer columns. */ \ - /* Simply truncate the columns */ \ - for (i=0; iarrname[i] = NULL; \ } \ + free (table->arrname); \ } \ + table->arrname = NULL; \ } -/* ==================================================== */ static void xaccFreeTableEntries (Table * table) @@ -236,38 +153,15 @@ xaccFreeTableEntries (Table * table) int i,j; /* free the entries */ - if (table->entries) { - for (i=0; inum_phys_rows; i++) { - if (table->entries[i]) { - for (j=0; jnum_phys_cols; j++) { - if (table->entries[i][j]) free (table->entries[i][j]); - table->entries[i][j] = NULL; - } - free (table->entries[i]); - } - table->entries[i] = NULL; - } - free (table->entries); - } - table->entries = NULL; + FREE_ARR (entries, FREEUP, NULL); /* free the locators */ - if (table->locators) { - for (i=0; inum_phys_rows; i++) { - if (table->locators[i]) { - for (j=0; jnum_phys_cols; j++) { - if (table->locators[i][j]) free (table->locators[i][j]); - table->locators[i][j] = NULL; - } - free (table->locators[i]); - } - table->locators[i] = NULL; - } - free (table->locators); - } - table->locators = NULL; + FREE_ARR (locators, FREEUP, NULL); + + /* free the foreground and background color arrays */ + FREE_ARR (bg_colors, NOOP, 0xffffff); + FREE_ARR (bg_colors, NOOP, 0x0); - /* hack alert -- incomplete -- also do colors */ /* null out user data and handlers */ for (i=0; inum_virt_rows; i++) { for (j=0; jnum_virt_cols; j++) { @@ -308,7 +202,7 @@ xaccTableResize (Table * table, } /* resize the string data array */ - RESIZE_ARR ((table->num_phys_rows), + XACC_RESIZE_ARRAY ((table->num_phys_rows), (table->num_phys_cols), new_phys_rows, new_phys_cols, @@ -318,7 +212,7 @@ xaccTableResize (Table * table, free); /* resize the locator array */ - RESIZE_ARR ((table->num_phys_rows), + XACC_RESIZE_ARRAY ((table->num_phys_rows), (table->num_phys_cols), new_phys_rows, new_phys_cols, @@ -328,50 +222,55 @@ xaccTableResize (Table * table, free); /* resize the bg color array (white background) */ - RESIZE_ARR ((table->num_phys_rows), + XACC_RESIZE_ARRAY ((table->num_phys_rows), (table->num_phys_cols), new_phys_rows, new_phys_cols, (table->bg_colors), int, (0xffffff), /* white */ - (int)); /* no-op */ + NOOP); /* no-op */ /* resize the foreground color array (black text) */ - RESIZE_ARR ((table->num_phys_rows), + XACC_RESIZE_ARRAY ((table->num_phys_rows), (table->num_phys_cols), new_phys_rows, new_phys_cols, (table->fg_colors), int, (0x0), /* black */ - (int)); /* no-op */ - - /* we are done with the physical dimensions. - * record them for posterity. */ - table->num_phys_rows = new_phys_rows; - table->num_phys_cols = new_phys_cols; + NOOP); /* no-op */ /* resize the user-data hooks */ - RESIZE_ARR ((table->num_virt_rows), + XACC_RESIZE_ARRAY ((table->num_virt_rows), (table->num_virt_cols), new_virt_rows, new_virt_cols, (table->user_data), void *, (NULL), - (void *)); /* no-op */ + NOOP); /* no-op */ /* resize the handler array */ - RESIZE_ARR ((table->num_virt_rows), + XACC_RESIZE_ARRAY ((table->num_virt_rows), (table->num_virt_cols), new_virt_rows, new_virt_cols, (table->handlers), CellBlock *, (NULL), - (CellBlock *)); /* no-op */ + NOOP); /* no-op */ + + /* call the "derived" class resize method */ + TABLE_PRIVATE_DATA_RESIZE (table, + new_phys_rows, new_phys_cols, + new_virt_rows, new_virt_cols); + + /* we are done with the physical dimensions. + * record them for posterity. */ + table->num_phys_rows = new_phys_rows; + table->num_phys_cols = new_phys_cols; /* we are done with the virtual dimensions. * record them for posterity. */ diff --git a/src/register/table-allgui.h b/src/register/table-allgui.h index 7f1ff73c63..ebc1486d5f 100644 --- a/src/register/table-allgui.h +++ b/src/register/table-allgui.h @@ -192,7 +192,7 @@ void xaccCommitCursor (Table *); /* hack alert -- * for all practical purposes, RefreshHeader is identical - * tp CommitCursor(), except that it acts on cellblock 0,0. + * to CommitCursor(), except that it acts on cellblock 0,0. * it should probably be made obsolete. */ void xaccRefreshHeader (Table *); @@ -208,6 +208,119 @@ void xaccRefreshHeader (Table *); void xaccVerifyCursorPosition (Table *table, int phys_row, int phys_col); +/* ==================================================== */ +/* + * In C, we don't have things like C++ templates. + * So cook up a #define that acts like a template. + * This one will resize a 2D array in a reasonably + * efficient manner. + */ + + +#define XACC_RESIZE_ARRAY(table_rows,table_cols,new_rows,new_cols,arr,type,null_val,free_cell_op) \ +{ \ + int old_rows, old_cols; \ + int i,j; \ + \ + /* save old table size */ \ + old_rows = table_rows; \ + old_cols = table_cols; \ + if (0 > old_rows) old_rows = 0; \ + if (0 > old_cols) old_cols = 0; \ + \ + /* realloc to get the new table size. Note that the */ \ + /* new table may be wider or slimmer, taller or shorter. */ \ + if (old_rows >= new_rows) { \ + if (old_cols >= new_cols) { \ + \ + /* if we are here, new table has fewer cols */ \ + /* simply truncate columns */ \ + for (i=0; i= new_cols) { \ + \ + /* new table has fewer columns. */ \ + /* Simply truncate the columns */ \ + for (i=0; iprev_entry_text); table->prev_entry_text = NULL; \ } +/* nothing to resize */ +#define TABLE_PRIVATE_DATA_RESIZE(table) + typedef struct _Table Table; /* create the GtkWidget */ diff --git a/src/register/table-motif.c b/src/register/table-motif.c index 14d8f0c001..6949fdc41f 100644 --- a/src/register/table-motif.c +++ b/src/register/table-motif.c @@ -480,6 +480,9 @@ SetupColorTable (Table *table) XColor * colors; int i, ncolors; + /* if already initialized, do nothing */ + if (0 != table->ncolors) return; + /* get the number of colors in our colormap */ dpy = XtDisplay (table->table_widget); win = XtWindow (table->table_widget); @@ -655,25 +658,104 @@ GetColormapIndex (Table *table, int argb) /* ==================================================== */ +#define NOOP(x) /* do nothing */ + +void +xaccMotifResizeTable (Table * table, + int new_phys_rows, int new_phys_cols, + int new_virt_rows, int new_virt_cols) + +{ + XACC_RESIZE_ARRAY ((table->num_phys_rows), + (table->num_phys_cols), + new_phys_rows, + new_phys_cols, + (table->bg_hues), + Pixel, + 1, + NOOP); + + XACC_RESIZE_ARRAY ((table->num_phys_rows), + (table->num_phys_cols), + new_phys_rows, + new_phys_cols, + (table->fg_hues), + Pixel, + 0, + NOOP); +} + +/* ==================================================== */ + void xaccRefreshTableGUI (Table * table) { + int iphys, jphys; + int bg_cache, fg_cache; + Pixel bg_cache_val, fg_cache_val; + Pixel white, black; + {int i; printf (" refresh numphysrows=%d numphyscols=%d \n", table->num_phys_rows,table->num_phys_cols); for (i=0; inum_phys_rows; i++) { -printf ("cell %d act:%s descr: %s \n", i, table->entries[i][2], +printf ("cell %d color: 0x%x act:%s descr: %s \n", i, table->bg_colors[i][3], table->entries[i][2], table->entries[i][3]); }} + + /* make sure that the color table is initialized. + * it would be slightly more efficient if we called + * this from a realize method, but we don't have one + * of these handy. + */ + SetupColorTable (table); + + black = GetColormapIndex (table, 0x0); + fg_cache = 0x0; + fg_cache_val = black; + + white = GetColormapIndex (table, 0xffffff); + bg_cache = 0xffffff; + bg_cache_val = white; + + for (iphys=0; iphysnum_phys_rows; iphys++) + { + for (jphys = 0; jphys < table->num_phys_cols; jphys++) + { + /* fill in the colormap entry that is the equivalent + * of th requested background color */ + if (0xffffff == table->bg_colors[iphys][jphys]) { + table->bg_hues[iphys][jphys] = white; + } else + if (bg_cache == table->bg_colors[iphys][jphys]) { + table->bg_hues[iphys][jphys] = bg_cache_val; + } else { + bg_cache = table->bg_colors[iphys][jphys]; + bg_cache_val = GetColormapIndex (table, bg_cache); + table->bg_hues[iphys][jphys] = bg_cache_val; + } + + /* fill in the colormap entry that is the equivalent + * of th requested foreground color */ + if (0xffffff == table->fg_colors[iphys][jphys]) { + table->fg_hues[iphys][jphys] = white; + } else + if (fg_cache == table->fg_colors[iphys][jphys]) { + table->fg_hues[iphys][jphys] = fg_cache_val; + } else { + fg_cache = table->fg_colors[iphys][jphys]; + fg_cache_val = GetColormapIndex (table, fg_cache); + table->fg_hues[iphys][jphys] = fg_cache_val; + } + } + } + XtVaSetValues (table->table_widget, XmNrows, table->num_phys_rows, XmNcolumns, table->num_phys_cols, XmNcells, table->entries, - /* XmNcellBackgrounds, table->?? */ + XmNcellBackgrounds, table->bg_hues, + XmNcolors, table->fg_hues, NULL); - - SetupColorTable (table); -{Pixel p=GetColormapIndex (table,0x99ee33); -printf ("its %d\n", p); } } /* ================== end of file ======================= */ diff --git a/src/register/table-motif.h b/src/register/table-motif.h index 45b70abcae..9be20d5590 100644 --- a/src/register/table-motif.h +++ b/src/register/table-motif.h @@ -53,8 +53,10 @@ /* Motif specific private data */ \ Widget table_widget; /* the XbaeMatrix */ \ Widget next_tab_group; /* where to traverse in the end */ \ - unsigned int ncolors; /* number of colors in colormap */ \ - XColor *colors; /* colormap entries */ + unsigned int ncolors; /* number of colors in colormap */ \ + XColor *colors; /* colormap entries */ \ + Pixel **bg_hues; /* background cell colors */ \ + Pixel **fg_hues; /* foreground (text) cell colors */ #define TABLE_PRIVATE_DATA_INIT(table) { \ @@ -62,17 +64,26 @@ table->next_tab_group = 0; \ table->ncolors = 0; \ table->colors = 0x0; \ + table->bg_hues = 0x0; \ + table->fg_hues = 0x0; \ } /* hack alert -- shouldn't destroy get rid of the widget? */ +/* hack alert -- I think destroy should unmalloc colors ?? */ #define TABLE_PRIVATE_DATA_DESTROY(table) +#define TABLE_PRIVATE_DATA_RESIZE xaccMotifResizeTable + typedef struct _Table Table; /* create the widget */ Widget xaccCreateTable (Table *, Widget parent, char * name); void xaccNextTabGroup (Table *, Widget); +void xaccMotifResizeTable (Table * table, + int new_phys_rows, int new_phys_cols, + int new_virt_rows, int new_virt_cols); + /* redraw the table GUI */ void xaccRefreshTableGUI (Table *);