Re: XForms: Pseudo Dialog Boxes and Object Locking...

Steve Lamont (spl@szechuan.ucsd.edu)
Wed, 5 Nov 97 06:07:22 PST

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

> Pseudo Dialog Boxes:
> I would like to display a message in the middle of my application
> window without creating another form. I know I can group all the
> objects and do a show and hide on them, however, I would like to suspend
> all interaction with the rest of my application. Is there an easy way
> to do this? ...

Probably the best way would be to collect all of the objects you wish
to disable into a group and then call fl_deactivate_object() with the
group object as the argument.

> ... Can I make a file selector appear in the application window
> instead of in it's own window? (I just am having some problems with
> fvwm2 autoraise hiding the file selector and other dialogs if you slide
> your mouse out of the dialog window)

No, you can't without writing your own emulation of the file
selector. Autoraise sounds like an especially annoying feature.

> Object Locking:
> I am curious if there is a way to lock an object or group of objects
> like you can a form. I am using pixmap buttons to represent a
> checkerboard on screen. Sometimes drawing into the board takes some
> time and I'd like to be able to give the user feedback. However, in
> order to do a single display of the newly drawn board, I must lock the
> main form. Then I can't display any feedback without creating a dialog
> (or something similar). If I could lock the group of pixmap buttons
> explcitly, then I could give the user feedback in my main form.

I'm not completely sure I understand what mean by "locking" an
object. Why do you wish to do this? Is this because of the slow redraw?

> Also, It seems that pixmaps are really slow to draw. Is this inherent
> in the pixmap format, or is xforms just somewhat inefficient? I am
> including the pixmaps as char ** in the binary of my application and
> using fl_set_pixmapbutton_data(...) to change them.

This is because you're reinterpreting the Pixmap every time you draw
it, which is unnecessary. You can get XForms to hand you the XID of
the Pixmap and then just use the Xlib XCopyArea() function to copy
what is effectively an instance of the Pixmap to where ever you you
wish.

Here's a bit of code I'm using in an application to do somewhat the
same thing:

static void draw_pixmap( FL_OBJECT *ob,
ImageP image_ptr, unsigned long x, unsigned long y )

{

Pixmap pixmap = get_image_pixmap( image_ptr );
Pixmap shape_mask = get_image_shape_mask( image_ptr );
unsigned long width = get_image_width( image_ptr );
unsigned long height = get_image_height( image_ptr );
GC gc = fl_state[fl_get_vclass()].gc[1];
char *text = get_image_title( image_ptr );

XSetClipMask( fl_get_display(), gc, shape_mask );
XSetClipOrigin( fl_get_display(), gc, ob->x + x, ob->y + y );
XSetPlaneMask( fl_get_display(), gc, AllPlanes );

XCopyArea( fl_get_display(),
pixmap,
FL_ObjWin( ob ),
gc,
0, 0,
width, height,
ob->x + x, ob->y + y );

}

The x and y parameters are the location, relative to the origin of
the object, where the Pixmap is to be drawn. Note that I use a shape
mask so that I only draw the "colored" pixels and the background color
appears everywhere else.

The function is called by the FL_DRAW event handler in a Free object.
It could also be called by a similar handler in a custom object.

The Pixmap itself is created with

static ImageP create_pixmap_from_xpm( char **xpm, char *name )

{

XpmAttributes attributes;
ImageP image_ptr = new_image();
Pixmap pixmap;
Pixmap shape_mask;

attributes.valuemask = XpmSize;
XpmCreatePixmapFromData( fl_get_display(),
fl_state[fl_get_vclass()].trailblazer,
xpm,
&pixmap,
&shape_mask,
&attributes );
set_image_pixmap( image_ptr, pixmap );
set_image_shape_mask( image_ptr, shape_mask );
set_image_width( image_ptr, attributes.width );
set_image_height( image_ptr, attributes.height );
set_image_title( image_ptr, strdup( name ) );

return image_ptr;

}

The above function is called only once for each Pixmap.

The set_image*() and get_image*() functions are utility functions for
creating, setting, and extracting members from an opaque data
structure which looks like

struct _Image {
Pixmap pixmap;
Pixmap shape_mask;
long int width;
long int height;

char *title;

ImageP next;
ImageP previous;
};

[...]

typedef struct _Image Image;
typedef Image *ImageP;

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