XForms: colormaps and canvases

Stephen Langer (langer@cam.nist.gov)
Tue, 21 Oct 1997 16:54:12 -0400

To subscribers of the xforms list from "Stephen Langer" <langer@cam.nist.gov> :

Hello --

Is it possible to install a colormap in more than one canvas?

I have a canvas that uses a lot of colors, so I use my own colormap.
Another canvas is used to display a colorbar showing all the colors
used in the first canvas, so it's natural to use the same colormap
for both canvases. On 8-bit pseudocolor displays I get X errors when
deleting the form containing the canvases. Apparently the colormap
is being freed more than once.

I'm using xforms 0.81 on an SGI (the IRIX 5.3 version). I know 0.81 is
old, but it seemed to be stable, and stability is more important to me
at the moment than being on the cutting edge...

A short example program is appended. Clicking on the "Quit" button
removes the form and generates the error

X Error of failed request: BadColor (invalid Colormap parameter)
Major opcode of failed request: 79 (X_FreeColormap)
Resource id in failed request: 0x700000f
Serial number of failed request: 740
Current serial number in output stream: 741

Thanks for any suggestions!

-- Steve

#include <stdio.h>
#include <stdlib.h>
#include "forms.h"

typedef struct {
FL_FORM *testform;
FL_OBJECT *quitbutton;
FL_OBJECT *box1;
FL_OBJECT *box2;
void *vdata;
long ldata;
} FD_testform;

extern void quit(FL_OBJECT *, long);

FD_testform *create_form_testform(void)
{
FL_OBJECT *obj;
FD_testform *fdui = (FD_testform *) fl_calloc(1, sizeof(*fdui));

fdui->testform = fl_bgn_form(FL_NO_BOX, 320, 250);
obj = fl_add_box(FL_UP_BOX,0,0,320,250,"");
fdui->quitbutton = obj =
fl_add_button(FL_NORMAL_BUTTON,260,210,50,30,"Quit");
fl_set_object_callback(obj,quit,0);
fdui->box1 = obj = fl_add_box(FL_FLAT_BOX,50,50,110,90,"");
fl_set_object_color(obj,FL_DARKVIOLET,FL_COL1);
fdui->box2 = obj = fl_add_box(FL_FLAT_BOX,180,50,120,90,"");
fl_set_object_color(obj,FL_PALEGREEN,FL_COL1);
fl_end_form();

return fdui;
}
/*---------------------------------------*/

FD_testform *testform;
FL_OBJECT *canvas1, *canvas2;

int main(int argc, char *argv[]) {
Colormap colormap;

fl_initialize(&argc, argv, "TestCanvas", 0, 0);

/* make sure errors are reported right away */
XSynchronize(fl_get_display(), True);

testform = create_form_testform();

/* create two canvases */
fl_addto_form(testform->testform);
canvas1 = fl_add_canvas(FL_NORMAL_CANVAS,
testform->box1->x, testform->box1->y,
testform->box1->w, testform->box1->h,
"canvas1");
canvas2 = fl_add_canvas(FL_NORMAL_CANVAS,
testform->box2->x, testform->box2->y,
testform->box2->w, testform->box2->h,
"canvas2");
fl_end_form();

/* create a colormap and tell the canvases to use it. */
colormap = XCreateColormap(fl_get_display(), fl_default_window(),
fl_state[fl_get_vclass()].xvinfo->visual,
AllocAll);
fl_set_canvas_colormap(canvas1, colormap);
/*****************************************************
* If the next line is deleted no error is generated!
****************************************************/
fl_set_canvas_colormap(canvas2, colormap);

fl_show_form(testform->testform, FL_PLACE_MOUSE, FL_FULLBORDER, "test");
fl_do_forms();
return 0;
}

void quit(FL_OBJECT *obj, long arg) {
fl_hide_form(testform->testform);
fl_free_form(testform->testform);
fputs("Success!\n", stderr);
exit(0);
}

-- 
-- EMail: stephen.langer@nist.gov                    Phone: (301) 975-5423 --
-- WWW:  http://math.nist.gov/mcsd/Staff/SLanger/    Fax:   (301) 990-4127 --
-- Mail: Building 820 Room 365; NIST; Gaithersburg, Md          20899-0001 --
_________________________________________________
To unsubscribe, send the message "unsubscribe" to
xforms-request@bob.usuf2.usuhs.mil or see
http://bob.usuf2.usuhs.mil/mailserv/xforms.html
Xforms Home Page: http://bragg.phys.uwm.edu/xforms
List Archive: http://bob.usuf2.usuhs.mil/mailserv/list-archives/