From 7420a8bd6b7020b682849be533626179bd87d13d Mon Sep 17 00:00:00 2001 From: Linas Vepstas Date: Sun, 26 Jul 1998 06:47:37 +0000 Subject: [PATCH] start adding actual color handl;ing code git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@918 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/register/table-motif.c | 94 ++++++++++++++++++++++++++++++++++++++ src/register/table-motif.h | 6 ++- 2 files changed, 99 insertions(+), 1 deletion(-) diff --git a/src/register/table-motif.c b/src/register/table-motif.c index 200cc5fc91..14d8f0c001 100644 --- a/src/register/table-motif.c +++ b/src/register/table-motif.c @@ -469,6 +469,46 @@ traverseCB (Widget mw, XtPointer cd, XtPointer cb) /* ==================================================== */ +static void +SetupColorTable (Table *table) +{ + + Display * dpy; + Window win; + XWindowAttributes wattr; + Colormap cmap; + XColor * colors; + int i, ncolors; + + /* get the number of colors in our colormap */ + dpy = XtDisplay (table->table_widget); + win = XtWindow (table->table_widget); + XGetWindowAttributes (dpy, win, &wattr); + ncolors = wattr.visual->map_entries; + cmap = wattr.colormap; + table->ncolors = ncolors; + + /* If the class is TrueColor, then there is no colormap. + * Punt for now. + */ + if (TrueColor == wattr.visual->class) return; + + /* if ncolors is greater than 16K, then we probably + * have a true-color display, and don't have a colormap. + * Punt. Hack Alert + */ + if (16384 < ncolors) return; + + /* get the color values */ + /* hack alert -- remember to free this memory somewhere. */ + colors = (XColor *) malloc ( ncolors * sizeof (XColor)); + table->colors = colors; + for (i=0; icolors; + int ncolors = table->ncolors; + unsigned short r,g,b; + int i; + unsigned int metric; + Pixel idx = 0; + + /* if there's no colormap, then assume True or Direct Color */ + /* hack alert -- will the pixel format be simple argb ??? */ + if (0x0 == colors) return argb; + + r = (argb & 0xff0000) >> 8; + g = argb & 0xff00; + b = (argb & 0xff) << 8; + + /* use a manhatten metric to find the closest color */ + metric = 0xffffffff; + for (i=0; i pr) pr = -pr; + if (0 > pg) pg = -pg; + if (0 > pb) pb = -pb; + m = pr + pg + pb; + if (m < metric) { + metric = m; + idx = colors[i].pixel; + } + } + + /* + * printf ("Info: GetColormapIndex(): \n" + * "\tRequested rgb=0x%x r=0x%x g=0x%x b=0x%x \n" + * "\tfound idx=%d 0x%x 0x%x 0x%x\n", argb, r, g, b, idx, + * colors[idx].red, colors[idx].green, colors[idx].blue); + */ + + return idx; +} + +/* ==================================================== */ + void xaccRefreshTableGUI (Table * table) { @@ -580,6 +669,11 @@ table->entries[i][3]); XmNcells, table->entries, /* XmNcellBackgrounds, table->?? */ 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 9aec28bd1e..45b70abcae 100644 --- a/src/register/table-motif.h +++ b/src/register/table-motif.h @@ -52,12 +52,16 @@ #define TABLE_PRIVATE_DATA \ /* Motif specific private data */ \ Widget table_widget; /* the XbaeMatrix */ \ - Widget next_tab_group; /* where to traverse in the end */ + Widget next_tab_group; /* where to traverse in the end */ \ + unsigned int ncolors; /* number of colors in colormap */ \ + XColor *colors; /* colormap entries */ #define TABLE_PRIVATE_DATA_INIT(table) { \ table->table_widget = 0; \ table->next_tab_group = 0; \ + table->ncolors = 0; \ + table->colors = 0x0; \ } /* hack alert -- shouldn't destroy get rid of the widget? */