Re: XForms: Printing and SCrollable Canvas

Steve Lamont (spl@szechuan.ucsd.edu)
Mon, 2 Mar 98 09:47:04 PST

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

> 1. I need a Scrollable Canvas in which I can draw diagrams.

It isn't implemented in XForms yet.

I've done my own sort of hackish Scrolled Canvas by creating a Canvas
bordered by a couple of Scroll Bar objects and then when the Canvas is
created, create a child window to the Canvas:

[... create_form_whatever() before here ...]

fl_modify_canvas_prop( fd_whatever->canvas,
NULL,
activate_canvas,
NULL );

[... fl_show_form() somewhere after here ...]

int activate_canvas( FL_OBJECT *canvas )

{

Window window;
XVisualInfo *xvinfo = fl_state[fl_get_vclass()].xvinfo;
Colormap colormap = DefaultColormap( fl_get_display(),
DefaultScreen( fl_get_display() ) );

window = XCreateSimpleWindow( fl_get_display(),
FL_ObjWin( canvas ),
0, 0,
SCROLL_CANVAS_WIDTH, SCROLL_CANVAS_HEIGHT, 0,
fl_get_pixel( FL_BLACK ),
fl_get_pixel( FL_BLUE ) );
XMapWindow( fl_get_display(), window );

canvas->u_ldata = ( long ) window;

return 0;

}

/*
* This guy handles scrolling the window -- it's the callback for the
* two scrollbars
*/

void scrollbar_cb(FL_OBJECT *ob, long data)

{

FD_whatever *fd_whatever = ( FD_whatever *) ob->form->fdui;
FL_OBJECT *canvas = fd_whatever->display_canvas;
int xpos = -( SCROLL_CANVAS_WIDTH - canvas->w ) *
fl_get_scrollbar_value( fd_whatever->horizontal_scrollbar );
int ypos = -( SCROLL_CANVAS_HEIGHT - canvas->h ) *
fl_get_scrollbar_value( fd_whatever->vertical_scrollbar );

XMoveWindow( fl_get_display(), ( Window ) canvas->u_ldata, xpos, ypos );

}

This provides you with a Window into which you can draw.

This is a *very* incomplete implementation but it should get you
started.

There really should also be another routine to clean up when the
canvas is deactivated but I've never needed one so I've never written
one.

Note that I've also taken the lazy/sleazy route on many of the Window
properties and made assumptions about the default Visual that I would
not make in the general case. I'm also assuming that the scrolled
canvas does not change size -- a bad assumption in general.

> 2. I need to print the diagrams drawn in the Canvas.

Print them how? Postscript dump? How are you drawing them? If
you're processing a set of drawing instructions of some sort, you
should probably just reprocess them into Postscript commands rather
than try to read out from the image. If you're doing some sort of
image processing, you should probably use the backing image directly.

spl
_________________________________________________
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://bloch.phys.uwm.edu/xforms
List Archive: http://bob.usuf2.usuhs.mil/mailserv/list-archives/