[comp.windows.x.motif] How to set the colormap for a DrawingArea?

pturner@ese.ese.ogi.edu (Paul Turner) (03/20/91)

It's obvious I know nothing about colormaps and X. What I
want to do is install my colormap for a DrawingArea widget
that is different from the default colormap of the screen.
So when the pointer is in the DrawingArea, my colormap
gets installed. So far, nothing happens.

Hardware is RS6000 w AIX+3001, 8 bit color.

Code fragments follow:

canvas is the name of the DrawingArea widget. I create
the DrawingArea and manage it. I then call

    xwin = XtWindow(canvas);
    disp = XtDisplay(canvas);

I then call the following procedure in my driver for X 
graphics, I'm attempting to create a colormap called mycmap:

xlibinitcmap()
{
    int i;
    ncolors = DisplayCells(disp, DefaultScreen(disp));
    if (ncolors > 256) ncolors = 256;
    cmap = DefaultColormap(disp, DefaultScreen(disp));
    for (i = 0; i < ncolors; i++) {
        xc[i].pixel = i;
        xc[i].flags = DoRed | DoGreen | DoBlue;
    }
    XQueryColors(disp, cmap, xc, ncolors);
    mycmap = XCreateColormap(disp, xwin,
                                  DefaultVisual(disp, DefaultScreen(disp)),
                                  AllocAll);
    for (i = 42; i < 100; i++) {
        xc[i].red = red[i - 40] << 8;
        xc[i].green = green[i - 40] << 8;
        xc[i].blue = blue[i - 40] << 8;
        colors[i - 40] = xc[i].pixel;
    }
    /* I want colors 0 and 1 to be black and white */
    colors[0] = WhitePixel(disp, DefaultScreen(disp));
    colors[1] = BlackPixel(disp, DefaultScreen(disp));
    XStoreColors(disp, mycmap, xc, ncolors);
}

after this I call

        XSetWindowColormap(disp, xwin, mycmap);

I feel mwm should install the colormap whenever the pointer
is inside the DrawingArea, but nothing happens.

My colormap IS installed when I use the top level widget (lets call it
app_shell). If in the above I set:

        XSetWindowColormap(disp, XtWindow(app_shell), mycmap);

This causes problems if any of the colors Motif uses happen
to lie in the range 40-99. I just want the colormap set for the
DrawingArea.

What gives?

Thanks,

--Paul
pturner@ese.ogi.edu