From: chris@ods.com (Chris Atkins)
Subject: Re: Popup dialog and GC problem
Organization: Optical Data Systems, Inc.
X-Newsreader: Tin 1.1 PL5
Date: Mon, 17 Aug 1992 19:02:00 GMT

Lincoln McFarland (mcfar@leadse5.UUCP) wrote:
: 
: 
: I have been creating pop up dialogs along the model suggested by Young p. 114
: and can get things to work reasonably well with a few exceptions.  Basicly
: I code the following:
: 
: main()
: {
:    Widget toplevel;
:    Widget form;
:    Widget button;
:    Widget dialog;
: 
:    toplevel = XtInitialize( argv[0], "fred", NULL, 0, &argc, argv);
: 
:    form =  XtCreateManagedWidget( "form", xmFormWidgetClass, toplevel, al, ac);
: 
:    button = XtCreateManageddWidget( "button", xmPushButtonWidgetClass, 
:                                     form, al, ac);
: 
:    dialog = create_dialog( toplevel );
: 
:    XtAddCallback( button, XmNactivateCallback, show_dialog, dialog);
: 
:    XtRealizeWidget( toplevel );
: 
:    XtMainLoop();
: 
: } /* end main */
: 
: Show dialog is just XtManageChild(dialog) like Young p. 115
: 
: Create dialog is along the lines of:
: 
: Widget create_dialog( parent )
: Widget parent;
: {
:    Widget local_dialog;
: 
:    /* logo resources */
:    XGCValues   arrow_val;
:    pixmap_data arrow_pd;
:    Widget      arrow;
: 
:    local_dialog = XmCreateFormDialog( parent, "dialog", al, ac);
: 
:    /*-- create a arrow image  --*/
:    ac = 0;
:    arrow = XtCreateManagedWidget( "arrow",
:                                xmDrawingAreaWidgetClass, local_dialog, al,ac);
: 
:    /* Use the forground and background colors of the logo to
:       create a graphics context */
:    ac = 0;
:    XtSetArg (al[ac], XtNforeground, &downHead_val.foreground); ac++;
:    XtSetArg (al[ac], XtNbackground, &downHead_val.background); ac++;
:    XtGetValues (downHead, al, ac);
:    arrow_pd.gc = XtGetGC (arrow, GCForeground|GCBackground,
:                             &arrow_val);
: 
:    arrow_pd.width  = arrow_width;
:    arrow_pd.height = arrow_height;
:    arrow_pd.pix = create_pixmap(arrow, arrow_pd.gc, arrow_bits,                          arrow_width, arrow_height);
: 
:   XtAddCallback (arrow, XmNexposeCallback, redisplay, &arrow_pd);
:   XtAddCallback (arrow, XmNresizeCallback, resize, &arrow_pd);
: 
: 
:    /* add buttons and text widgets and stuff as above */
: 
:    return local_dialog;
: 
: } /* end create_dialog() */
: 
: 
: Problem 1)
: 
: I can't seem to get a handle on the graphics contexts of the dialog.
: I want to add a bit map and used Young p. 191 as an example.  create_pixmap()
: and picmap_data are defined as he has it and this works fine at the main
: level.
: 
: Things will compile fine, however when the call back is run I get:
: 
: X Error of failed request:  BadGC (invalid GC parameter)
:   Major opcode of failed request:  56 (X_ChangeGC)
:   Resource id in failed request:  0xf7800128
:   Serial number of failed request:  465
:   Current serial number in output stream:  515
: 
: 
: and the program crashes.
: 
XtGetGC should only be used when you do not wish to change any of the GC values
in the GC.  You specify all the values you care about and it finds or creates a
GC having the specified values.  All other values are set to the default.
Once you have obtained the GC using XtGetGC, you should not try to change any
of it's values as this will potentially foul up other widgets.  

XCreateBitmapFromData and XReadBitmapFile both work with a pixmap of depth 1 andany functions you perform on them should use a GC created with a drawable of 
depth 1.  The functions XCreatePixmapFromBitmapData and XCopyPlane should use a
GC with the desired depth(probably 8).  

One common confussion you seem to have is that you must find THE GC for the 
widget using XtGetGC.  XtGetGC is an XtFunction which allows for the caching of
GC's so that if all widgets in your application have a background of red, and 
a foreground of black, and all are on the same screen of the same display with
the same depth, that only one GC is used by all widgets instead of having each
widget create and use a seperate GC.  You could create a new GC if you wish to
do your graphics processing.

Chris Atkins
chris@ods.com