Newsgroups: comp.sys.hp

In comp.sys.hp, tghe337@cdc835.cdc.polimi.it () writes:

> I need help about interfacing a CRX-24 graphics adapter with Motif 1.1.
> In particular I need info on using 24 bits color depth with motif widgets
> 
> Any help ???
> Thanks a lot in advance...

If your interest is in doing some 24 bit graphics in a Motif application,
take a look at the following example which shows how you can create a
"deep" (24 bit) drawing area in a motif program.  As it turns out, Motif
1.1 has a flaw which prevents the visual selection from working as 
expected.  This program works around that flaw by using its own realize
function.  While this technique will work, it is not generally recommended
and should probably not be used once Motif 1.2 becomes available.

If you are hoping to force the entire widget heirarchy (including the
toplevel) to use the 24 bit visual, then this example will not help you.
Again, the Motif 1.1 flaw causes trouble for this.  Perhaps someone else
will offer an answer for that one.

John Brown
Hewlett-Packard
User Interface Technology Division
Fort Collins, CO
---------------------------------------------------------------------------
This response does not represent the official position of, or statement by,
the Hewlett-Packard Company.  The above data is provided for informational
purposes only.  It is supplied without warranty of any kind.
---------------------------------------------------------------------------

/*

  This example program shows how to create a 24-bit drawing area widget in
  a Motif 1.1 application.  The technique used here should not be necessary
  with future revisions of Motif, and in general is not recommended.  

  This example does not represent the official position of, or statement by,
  the Hewlett-Packard Company.  This example is for informational purposes 
  only.  It is supplied without warranty of any kind.

*/

#include <stdio.h>
#include <Xm/Xm.h>
#include <Xm/Form.h>
#include <Xm/PushB.h>
#include <Xm/DrawingA.h>
#include <X11/IntrinsicP.h>

main( argc, argv )
    int argc;
    char **argv;
{
    void deep_realize(), quit_callback();
    Widget toplevel, form, quit_button, drawing_area;
    XtAppContext app_context;
    XmString quit_text;
    Arg arg[15];
    int n;

    /* Initialize the toolkit and create the toplevel shell widget */

    toplevel = XtAppInitialize( &app_context, "DeepVisual", NULL, 0,
			       &argc, argv, NULL, NULL, 0);

    /* Create a form widget to hold the rest of the children */

    n = 0;
    form = XtCreateManagedWidget( NULL, xmFormWidgetClass, toplevel, arg, n );

    /* Create a quit button and add a callback so that our "callback" 
       function will be invoked when the user clicks on the button. */

    n = 0;
    XtSetArg( arg[n], XmNleftAttachment, XmATTACH_FORM ); n++;
    XtSetArg( arg[n], XmNrightAttachment, XmATTACH_FORM ); n++;
    XtSetArg( arg[n], XmNtopAttachment, XmATTACH_FORM ); n++;
    quit_text = XmStringCreate( "Quit", XmSTRING_DEFAULT_CHARSET );
    XtSetArg( arg[n], XmNlabelString, quit_text ); n++;
    quit_button = XtCreateManagedWidget( "quit", xmPushButtonWidgetClass,
					form, arg, n );
    XtAddCallback( quit_button, XmNactivateCallback, quit_callback, NULL );
    XmStringFree( quit_text );

    /* Create the DrawingArea widget. */

    n = 0;
    XtSetArg( arg[n], XmNtopWidget, quit_button ); n++;
    XtSetArg( arg[n], XmNtopAttachment, XmATTACH_WIDGET ); n++;
    XtSetArg( arg[n], XmNleftAttachment, XmATTACH_FORM ); n++;
    XtSetArg( arg[n], XmNrightAttachment, XmATTACH_FORM ); n++;
    XtSetArg( arg[n], XmNbottomAttachment, XmATTACH_FORM ); n++;
    XtSetArg( arg[n], XmNwidth, 500 ); n++;
    XtSetArg( arg[n], XmNheight, 400 ); n++;
    drawing_area = XtCreateManagedWidget( "DrawingArea", 
					 xmDrawingAreaWidgetClass,
					 form, arg, n );

    /* This trick is needed to work around a problem with Motif 1.1 */
    (XtClass(drawing_area))->core_class.realize = deep_realize;

    XtRealizeWidget( toplevel );

    /* Start the event handling loop */

    XtAppMainLoop( app_context );

} /* end of main() */

/*

  deep_realize - used to realize a "deep" window for graphics

*/
void deep_realize(wdg, mask, winattr)
    Widget wdg;
    Mask *mask;
    XSetWindowAttributes *winattr;
{
    Display *display;
    int i, screen, depth, desired_depth, num_avail_vis;
    Colormap colormap;
    XVisualInfo *avail_vis;
    Visual *visual = NULL;

    display = XtDisplay( wdg );
    screen = DefaultScreen( display );
    desired_depth = 24;

    depth = 0;
    avail_vis = XGetVisualInfo( display, NULL, NULL, &num_avail_vis );

    /* Did we get any visuals ? */
    if ( avail_vis == 0 )
    {
	fprintf(stderr,"No visuals.  Cannot create graphics area.\n");
	return;
    }

    /* Find the deepest visual on this screen */
    
    for ( i = 0; i < num_avail_vis; i++ )
    {
	/* Is this visual on our screen and is it an acceptable class ? */

	if ( avail_vis[i].screen == screen && 
	    ( avail_vis[i].class == PseudoColor ||
	      avail_vis[i].class == DirectColor ||
	      avail_vis[i].class == TrueColor ) )
	{
	    /* Yes, it is!  Is it deeper than what we've already found? */
	    if ( visual == NULL ||
	       ( visual == DefaultVisual( display, screen )) ||
	       ( avail_vis[i].depth > depth && depth != desired_depth ) )
	    {
		/* Yes, so remember it for later */
		depth = avail_vis[i].depth;
		visual = avail_vis[i].visual;
	    }
	}
    }
    
    /* Verify that we did find a "best" visual.  This is mainly to 
       exit gracefully if the user attempts to run this on a grayscale
       or non-color device */

    if ( visual == NULL )
    {
	fprintf(stderr,"No color visual.  Cannot create graphics area.\n");
	return;
    }

    /* Create colormap */

    colormap = XCreateColormap( display, RootWindow(display,screen),
			       visual, AllocNone );

    /* Establish basic attributes needed to successfully create window */

    winattr->border_pixel = 0;
    winattr->background_pixel = 0;
    winattr->colormap = colormap;

    wdg->core.depth = depth;

    XtCreateWindow(wdg, InputOutput, visual, (*mask | CWBackPixel |
		   CWColormap | CWBorderPixel), winattr);

} /* end of deep_realize */

void quit_callback()
{

    exit(0);

}
From: jrm@hpuerca.atl.hp.com (John Morris)
Date: Mon, 31 Aug 1992 22:27:01 GMT
Subject: Needed - xmon for 800 series
Organization: the HP Response Center, Atlanta