Re: XForms: colormaps and canvases

Stephen Langer (langer@cam.nist.gov)
Fri, 31 Oct 1997 10:37:56 -0500

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

Hi --

Last week I posted a question about whether it's possible to have
two canvases share the same colormap, when that colormap is different
from the one used by the rest of the forms. I got a few helpful suggestions
about workarounds, but no real answer to the question.

Since I really need to know if this is a bug that could be fixed or
if it's just something that I'll have to live with, I'm going to ask
again: Is it legal to use fl_set_canvas_colormap() to install the same
colormap in two different canvases?

Here's an example code (somewhat simplified from the one I posted
earlier). Running on an SGI, but displaying on either an 8-bit Sun
or a 24-bit SGI, I get the error
X Error of failed request: BadColor (invalid Colormap parameter)
Major opcode of failed request: 79 (X_FreeColormap)
when the "Quit" button is pressed and the form is freed.

I've tried this with XForms versions 0.81 (IRIX 5.3) and 0.86 (IRIX 6.2,
n32).

Thanks,
Steve

-- 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 --

----------- cut here -------------------

/* Test program that creates a form with two canvases and a Quit
* button. The canvases share a colormap. When the Quit button is
* pressed, the form is hidden and freed, generating an X error. If
* the colormap is installed in only one of the canvases, no error is
* generated.
*/

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

typedef struct {
FL_FORM *testform;
void *vdata;
long ldata;
FL_OBJECT *quitbutton;
FL_OBJECT *canvas1;
FL_OBJECT *canvas2;
} 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->canvas1 = obj = fl_add_canvas(FL_NORMAL_CANVAS,30,50,110,110,"");
fdui->canvas2 = obj = fl_add_canvas(FL_NORMAL_CANVAS,170,50,110,110,"");
fl_end_form();

fdui->testform->fdui = fdui;

return fdui;
}

/*---------------------------------------*/

FD_testform *testform;

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 a colormap and tell the canvases to use it. */
colormap = fl_create_colormap(fl_state[fl_get_vclass()].xvinfo, 16);
fl_set_canvas_colormap(testform->canvas1, colormap);
/*****************************************************
* If the next line is deleted no error is generated!
****************************************************/
fl_set_canvas_colormap(testform->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);
}
_________________________________________________
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/