Re: Do we have scrolled canvases yet?

Steve Lamont (spl@szechuan.ucsd.edu)
Tue, 14 Jan 97 07:40:05 PST

To subscribers of the xforms list from spl@szechuan.ucsd.edu (Steve Lamont) :

> I was wondering, if isn't too much trouble, if you could post a
> small example of XLib coding which:
>
> 1) Opens a window.
> 2) Draws a rectangle in it.

#include <stdio.h>
#include <X11/Xlib.h>

int main( int argc, char **argv )

{

Display *display = XOpenDisplay( NULL );
int screen_num = DefaultScreen( display );
XSetWindowAttributes attrs;
Window window;
GC gc;
XGCValues values;

attrs.background_pixel = BlackPixel( display, screen_num );

window =
XCreateWindow( display,
RootWindow( display, screen_num ),
100, 100, 500, 500, 0,
DefaultDepth( display, screen_num ),
InputOutput, CopyFromParent,
CWBackPixel, &attrs );

XMapWindow( display, window );
XFlush( display );

sleep( 1 ); /* Necessary -- otherwise the Expose event clobbers drawing */

XClearWindow( display, window );
values.function = GXcopy;
values.foreground = WhitePixel( display, screen_num );
values.background = BlackPixel( display, screen_num );
values.line_width = 1;
gc = XCreateGC( display, window,
GCFunction |
GCForeground |
GCBackground |
GCLineWidth, &values );

XDrawRectangle( display, window, gc, 100, 100, 300, 300 );

XFlush( display );

sleep( 5 );

exit( 0 );

}

> That's what I did. In my Expose handler, I had it just write to
> stdout "Exposed!". When I XMapWindow()'d my childCanvas, "Exposed!"
> wasn't getting written to stdout anymore, which means my Expose handler
> wasn't getting called anymore. Which,I hypothesize, must be because
> childCanvas covers the entire XForms canvas, the XForms canvas is not ever
> "exposed" anymore and thus my Expose handler no longer gets called.

More or less. You can ignore the Expose event on your child window by
turning it off in the event mask.

> Sure would be cool if you could make an XForms canvas a child of
> another XForms canvas. That way I can stay out of XLib all together and
> stick to good 'ol, easy-to-use, XForms :-).

You can use an XForms Free Object to do a lot of what you want to do.
I suspect that if you're clever, you could even do scrolling by
playing with origins and clip masks.

spl