From: chris@ods.com (Chris Atkins)
Subject: Re: Text manipulation in a Drawing Area
Organization: Optical Data Systems, Inc.
X-Newsreader: Tin 1.1 PL5
Distribution: inet
Date: Wed, 26 Aug 1992 22:30:10 GMT

lr@laurie.smec.Sony.COM wrote:
: I am new to Motif programming, and am trying to test different
: possible applications.  One application is annotation of images.
: I would like to be able to place a line of text on an image.  I
: would then like to be able to select that text and move it to a 
: different location.  I would be satisfied in keeping the line(s)
: together and not allowing the separation of text.  I'll save that
: for another day.
: 
:  - I thought of creating a widget for the text and placing that over
: the image, but I do not know how to make the background of the widget
: transparent so that only the text shows.  Is this possible?
: 
:  - Could just the text be an overlay? 
: 
:  - I know that I could go through the process of saving areas of the image
: 	for replacing when the text is moved, but that seems book-keeping
: 	intensive.
: 
You might try creating a window with background_pixmap=None and 
background_pixe=None.  This will essentially create a transparent window.  
The windows background will be a copy of what is under it at the time.  
If the contents of the window it is over changes, or the window is moved with 
respect to it's parent, the background does not update.  The background is also
not redrawn due to expose events!  This requires that you to issue an 
XClearWindow command whenever an expose event is received.  The background will 
be redrawn in response to the XClearWindow based on the contents of the parent 
window.  You can use XDrawString to place the string into the window.

The above could be done in a drawing area widget.  You would determine the size
of the drawing area widget based on the size of the text strings.  You would 
then create the widget.  After the widget is created and the first expose event is received for the drawing area, you would use XtWindow to get the window id 
for your x commands.  You would then use XSetWindowBackground and 
XSetWindowBackgroundPixmap to set the background pixel and pixmap to None.   You
would then need to perform an XClearWindow and XFlush to cause the background to
be updated.  You would also be able to draw your text at this time.

I have done some work with "transparent" drawing areas and always have to 
relearn all the gotchas.  Spend a lot of time reading about background_pixel and
background_pixmap.  You might setting the widgets background and 
backgroundPixmap resources to None.  I have not tried this because I doubt that
they handle it correctly.  

I don't believe that you can do what you want with a lable widget without 
extracting a pixmap from the image and using that as the backgroundPixmap for 
the label.  The problem is in that if you are using a "transparent" window, 
the server does not redraw the background on expose events.  I would bet that 
the label widget is not smart enough to realize it is "transparent" and issue 
the XClearWindow and XFlush calls to have the background redrawn.  You would 
have a hard time doing this from an expose event handler because the label
widget also redraws the string.  Depending on whether your event handler got
called before or after the widgets expose method, you would wipe out the string.

If someone from Motif is reading this, would you consider exposure handling for transparent widgets to be a bug?????

Chris Atkins
Chris@ods.com