[comp.windows.x] background pixmap in a widget

davy@RIACS.EDU (12/10/88)

Okay, I made my own widget using the Template widget supplied with R3.
The X folks are to be congratulated on this, by the way -- it's well
documented, and I had my widget up and running in about 10 minutes.

Anyway, I'd like to have my widget come up with a custom background
pixmap made from some bitmap data I have.  So, I need someplace inside
the widget to put the line:

	pixmap = XCreateBitmapFromData(widget_display, widget_window,
			bitmap_bits, bitmap_width, bitmap_height);

and to set the background pixmap to this.

Right now, I have the "expose" part of the ClassRec structure set to
my own routine which creates the pixmap from the bitmap and retiles
the window the first time it is called.  The problem is, this produces
a sort of "flash" in the window since it gets mapped with the normal
background before I change it to the custom pixmap.

So, the question is, where *should* I put this code?  I want the widget
to create the pixmap, not the application.  As near as I can tell, I
also need to have this code somewhere where I can use the display and
window arguments for the widget.  Should I make my own RealizeProc?
Is there any documentation on what goes in a RealizeProc?

Any ideas?  Am I making sense?

--Dave Curry

swick@ATHENA.MIT.EDU (Ralph R. Swick) (12/10/88)

> Okay, I made my own widget using the Template widget supplied with R3.
> The X folks are to be congratulated on this, by the way -- it's well
> documented, and I had my widget up and running in about 10 minutes.

Thanks.  Glad to hear it was useful.

> Anyway, I'd like to have my widget come up with a custom background
> pixmap made from some bitmap data I have. 
...
> Should I make my own RealizeProc?

Yes, the realize procedure is the appropriate place to put one-time
resource creation of this type.  The initialize procedure could be
used as well and it's almost a toss-up, but delaying until realize
allows for the possibility that a client may change some resource
data (via XtSetValues, for example) upon which your created resources
depend.   Section 2.5 of 'X Toolkit Intrinsics - C Language Interface'
is the place to read about realize procedures.

davy@RIACS.EDU (12/13/88)

     From:  Ralph R. Swick <swick@ATHENA.MIT.EDU>
     Date:  Fri, 09 Dec 88 16:54:48 EST
     Subject:  Re: background pixmap in a widget 

     > Anyway, I'd like to have my widget come up with a custom background
     > pixmap made from some bitmap data I have. 
     ...
     > Should I make my own RealizeProc?

     Yes, the realize procedure is the appropriate place to put one-time
     resource creation of this type.  The initialize procedure could be
     used as well and it's almost a toss-up, but delaying until realize
     allows for the possibility that a client may change some resource
     data (via XtSetValues, for example) upon which your created resources
     depend.   Section 2.5 of 'X Toolkit Intrinsics - C Language Interface'
     is the place to read about realize procedures.

Thanks -- works like a charm.  I made the mistake of looking at
XtRealizeWidget instead of WindowObjRealize the first time, and was a
little daunted by how complex I thought the realize proc was, hence
using the exposure proc.  But now that I looked in the right place,
it's amazing how simple this all is.

I do have a suggestion for the next rev of the Xt docs... in the
sections which talk about all the different procs (realize, expose,
initialize, etc.) it might be useful to include what the defaults do
with some explan- atory notes.  That way someone who needs to write
their own would have something to go by other than digging through the
code.

Overall though, I like the widgets... especially since R3 came with a
menu (List) widget - I wasn't looking forward to doing that on my own.

--Dave

swick@ATHENA.MIT.EDU (Ralph R. Swick) (12/13/88)

> Thanks -- works like a charm.  I made the mistake of looking at ...

awk!  don't look at the implementation, look at the specification.
(I know this is difficult for died-in-the-wool Unix folks, but the X
religion is supposed to be good for others, too :-).

> I do have a suggestion for the next rev of the Xt docs...

point taken.  In most cases, the absense of a method means 'do nothing'.

BTW, don't forget to free your generated resources in a destroy procedure.
Although server resources will usually be freed when a client closes the
connection, it's reasonable for a widget client to create and destroy
a widget multiple times on a single connection.

davy@RIACS.EDU (12/13/88)

     From:  Ralph R. Swick <swick@ATHENA.MIT.EDU>
     Date:  Mon, 12 Dec 88 12:06:59 EST
     Subject:  Re: background pixmap in a widget 

     > Thanks -- works like a charm.  I made the mistake of looking at ...

     awk!  don't look at the implementation, look at the specification.
     (I know this is difficult for died-in-the-wool Unix folks, but the X
     religion is supposed to be good for others, too :-).

Yeah, but...

I didn't really see anything in the manual that said "the default
realize proc just calls XtCreateWindow" or whatever.  It says that a
realize proc should call this, but it doesn't say that's *all* it
needs to do.  Of course, part of the problem might be that I'm just
new to all this widget stuff.

The R3 docs are *much* better than the R2 docs in this respect, but
there could still be a little more.  Maybe O'Reilly or someone will
come out with a "Programing the X Toolkit" and this will all be
resolved anyway...

     BTW, don't forget to free your generated resources in a destroy procedure.
     Although server resources will usually be freed when a client closes the
     connection, it's reasonable for a widget client to create and destroy
     a widget multiple times on a single connection.

Thanks for the tip.

--Dave