From: chris@ods.com (Chris Atkins)
Subject: Re: DrawingArea and Colormaps Problem
Organization: Optical Data Systems, Inc.
X-Newsreader: Tin 1.1 PL5
Date: Mon, 17 Aug 1992 15:01:10 GMT

Michael P. Mack (6500mack@ucsbuxa.ucsb.edu) wrote:
: I am writing an application that draws images in a DrawingArea
: Widget with the option of changing the colormap.  I want the
: new colormap to be active only when the pointer is in the
: DrawingArea.  However I can't seem to get it to work right.
: 
: I set the window colormap for the DrawingArea using this callback
: routine (there are buttons to select a colormap):
: 
:   void changeColormap(w,client_data,call_data)
:     Widget w;
:     caddr_t client_data;
:     XmAnyCallbackStruct *call_data;
:     {
:     Window win;
: 
:     win = XtWindow(Draw);
:     switch ((int)client_data)  {
:       case BW  : XSetWindowColormap(disp,win,BWcmap); break;
:       case RGB : XSetWindowColormap(disp,win,RGBcmap); break;
:       default  : XSetWindowColormap(disp,win,cmap); break;
:       }
:     }
: 
: As it is written, absolutely no change occurs when the pointer is
: in the DrawingArea.  If I change to 'win = XtWindow(topwidget);'
: then the colormap is installed whenever the pointer is in the main
: window, but when this happens I can't see any of the buttons.
: 

You need to make sure the colormap you are trying to use is installed.  You can
use XInstallColormap to install the colormap after the call to 
XSetWindowColormap.  Chances are that you can only have one installed colormap
at a time.  You can check this out by running xdpyinfo and looking at the values
of number of colormaps for each screen of the display.  

If you begin installing the colormap when the user moves into the window, you
will also need to reinstall the old one when the user leaves the window.

One thing you might consider is to have the complete hierarchy from the top 
level shell on down use the same colormap.  Before the shell is created, you 
would create a colormap and fill in the colors needed by your interface.  You
might want to keep the number of colors needed in the interface small so that
you have several available for the image rendering. 

I assume that you mean grey scale instead of black and white.  If this is the 
case, your color rgb values will be weighted to come up with grey scale values
for the interface.

One benefit of setting the shell colormap and notifying the window manager when
the colormap changes is that the window manager will take of the colormap 
swapping for you and the user will be able to see the controls ( buttons, etc.)
at the same time focus is in the drawing area.

Chris Atkins
chris@ods.com

: I even set up the WM_COLORMAP_WINDOWS property using the code
: shown here (this is the first time I've used this function so
: please tell me if it is incorrect):
: 
:   Window win=XtWindow(Draw);
:   XSetWMColormapWindows(disp,win,&win,1);
:                              ^^^
:                              I even tried XtWindow(topwidget)
: 
: I am going crazy trying to figure out how to do this since I
: know it is possible!
: 
: Any help will be GREATLY appreciated.
: 
: 
: Mike Mack
: 6500mack@ucsbuxa.ucsb.edu
: