home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / sys / hp / 9950 < prev    next >
Encoding:
Internet Message Format  |  1992-09-01  |  6.5 KB

  1. From: brown@hpfcso.FC.HP.COM (John Brown)
  2. Date: Tue, 1 Sep 1992 21:06:21 GMT
  3. Subject: Re: Help on CRX-24 /Motif
  4. Message-ID: <7371282@hpfcso.FC.HP.COM>
  5. Organization: Hewlett-Packard, Fort Collins, CO, USA
  6. Path: sparky!uunet!cs.utexas.edu!sdd.hp.com!hpscdc!cupnews0.cup.hp.com!hppad.waterloo.hp.com!hppad!hpfcso!brown
  7. Newsgroups: comp.sys.hp
  8. References: <tghe337.714822215@cdc835>
  9. Lines: 197
  10.  
  11. In comp.sys.hp, tghe337@cdc835.cdc.polimi.it () writes:
  12.  
  13. > I need help about interfacing a CRX-24 graphics adapter with Motif 1.1.
  14. > In particular I need info on using 24 bits color depth with motif widgets
  15. > Any help ???
  16. > Thanks a lot in advance...
  17.  
  18. If your interest is in doing some 24 bit graphics in a Motif application,
  19. take a look at the following example which shows how you can create a
  20. "deep" (24 bit) drawing area in a motif program.  As it turns out, Motif
  21. 1.1 has a flaw which prevents the visual selection from working as 
  22. expected.  This program works around that flaw by using its own realize
  23. function.  While this technique will work, it is not generally recommended
  24. and should probably not be used once Motif 1.2 becomes available.
  25.  
  26. If you are hoping to force the entire widget heirarchy (including the
  27. toplevel) to use the 24 bit visual, then this example will not help you.
  28. Again, the Motif 1.1 flaw causes trouble for this.  Perhaps someone else
  29. will offer an answer for that one.
  30.  
  31. John Brown
  32. Hewlett-Packard
  33. User Interface Technology Division
  34. Fort Collins, CO
  35. ---------------------------------------------------------------------------
  36. This response does not represent the official position of, or statement by,
  37. the Hewlett-Packard Company.  The above data is provided for informational
  38. purposes only.  It is supplied without warranty of any kind.
  39. ---------------------------------------------------------------------------
  40.  
  41. /*
  42.  
  43.   This example program shows how to create a 24-bit drawing area widget in
  44.   a Motif 1.1 application.  The technique used here should not be necessary
  45.   with future revisions of Motif, and in general is not recommended.  
  46.  
  47.   This example does not represent the official position of, or statement by,
  48.   the Hewlett-Packard Company.  This example is for informational purposes 
  49.   only.  It is supplied without warranty of any kind.
  50.  
  51. */
  52.  
  53. #include <stdio.h>
  54. #include <Xm/Xm.h>
  55. #include <Xm/Form.h>
  56. #include <Xm/PushB.h>
  57. #include <Xm/DrawingA.h>
  58. #include <X11/IntrinsicP.h>
  59.  
  60. main( argc, argv )
  61.     int argc;
  62.     char **argv;
  63. {
  64.     void deep_realize(), quit_callback();
  65.     Widget toplevel, form, quit_button, drawing_area;
  66.     XtAppContext app_context;
  67.     XmString quit_text;
  68.     Arg arg[15];
  69.     int n;
  70.  
  71.     /* Initialize the toolkit and create the toplevel shell widget */
  72.  
  73.     toplevel = XtAppInitialize( &app_context, "DeepVisual", NULL, 0,
  74.                    &argc, argv, NULL, NULL, 0);
  75.  
  76.     /* Create a form widget to hold the rest of the children */
  77.  
  78.     n = 0;
  79.     form = XtCreateManagedWidget( NULL, xmFormWidgetClass, toplevel, arg, n );
  80.  
  81.     /* Create a quit button and add a callback so that our "callback" 
  82.        function will be invoked when the user clicks on the button. */
  83.  
  84.     n = 0;
  85.     XtSetArg( arg[n], XmNleftAttachment, XmATTACH_FORM ); n++;
  86.     XtSetArg( arg[n], XmNrightAttachment, XmATTACH_FORM ); n++;
  87.     XtSetArg( arg[n], XmNtopAttachment, XmATTACH_FORM ); n++;
  88.     quit_text = XmStringCreate( "Quit", XmSTRING_DEFAULT_CHARSET );
  89.     XtSetArg( arg[n], XmNlabelString, quit_text ); n++;
  90.     quit_button = XtCreateManagedWidget( "quit", xmPushButtonWidgetClass,
  91.                     form, arg, n );
  92.     XtAddCallback( quit_button, XmNactivateCallback, quit_callback, NULL );
  93.     XmStringFree( quit_text );
  94.  
  95.     /* Create the DrawingArea widget. */
  96.  
  97.     n = 0;
  98.     XtSetArg( arg[n], XmNtopWidget, quit_button ); n++;
  99.     XtSetArg( arg[n], XmNtopAttachment, XmATTACH_WIDGET ); n++;
  100.     XtSetArg( arg[n], XmNleftAttachment, XmATTACH_FORM ); n++;
  101.     XtSetArg( arg[n], XmNrightAttachment, XmATTACH_FORM ); n++;
  102.     XtSetArg( arg[n], XmNbottomAttachment, XmATTACH_FORM ); n++;
  103.     XtSetArg( arg[n], XmNwidth, 500 ); n++;
  104.     XtSetArg( arg[n], XmNheight, 400 ); n++;
  105.     drawing_area = XtCreateManagedWidget( "DrawingArea", 
  106.                      xmDrawingAreaWidgetClass,
  107.                      form, arg, n );
  108.  
  109.     /* This trick is needed to work around a problem with Motif 1.1 */
  110.     (XtClass(drawing_area))->core_class.realize = deep_realize;
  111.  
  112.     XtRealizeWidget( toplevel );
  113.  
  114.     /* Start the event handling loop */
  115.  
  116.     XtAppMainLoop( app_context );
  117.  
  118. } /* end of main() */
  119.  
  120. /*
  121.  
  122.   deep_realize - used to realize a "deep" window for graphics
  123.  
  124. */
  125. void deep_realize(wdg, mask, winattr)
  126.     Widget wdg;
  127.     Mask *mask;
  128.     XSetWindowAttributes *winattr;
  129. {
  130.     Display *display;
  131.     int i, screen, depth, desired_depth, num_avail_vis;
  132.     Colormap colormap;
  133.     XVisualInfo *avail_vis;
  134.     Visual *visual = NULL;
  135.  
  136.     display = XtDisplay( wdg );
  137.     screen = DefaultScreen( display );
  138.     desired_depth = 24;
  139.  
  140.     depth = 0;
  141.     avail_vis = XGetVisualInfo( display, NULL, NULL, &num_avail_vis );
  142.  
  143.     /* Did we get any visuals ? */
  144.     if ( avail_vis == 0 )
  145.     {
  146.     fprintf(stderr,"No visuals.  Cannot create graphics area.\n");
  147.     return;
  148.     }
  149.  
  150.     /* Find the deepest visual on this screen */
  151.     
  152.     for ( i = 0; i < num_avail_vis; i++ )
  153.     {
  154.     /* Is this visual on our screen and is it an acceptable class ? */
  155.  
  156.     if ( avail_vis[i].screen == screen && 
  157.         ( avail_vis[i].class == PseudoColor ||
  158.           avail_vis[i].class == DirectColor ||
  159.           avail_vis[i].class == TrueColor ) )
  160.     {
  161.         /* Yes, it is!  Is it deeper than what we've already found? */
  162.         if ( visual == NULL ||
  163.            ( visual == DefaultVisual( display, screen )) ||
  164.            ( avail_vis[i].depth > depth && depth != desired_depth ) )
  165.         {
  166.         /* Yes, so remember it for later */
  167.         depth = avail_vis[i].depth;
  168.         visual = avail_vis[i].visual;
  169.         }
  170.     }
  171.     }
  172.     
  173.     /* Verify that we did find a "best" visual.  This is mainly to 
  174.        exit gracefully if the user attempts to run this on a grayscale
  175.        or non-color device */
  176.  
  177.     if ( visual == NULL )
  178.     {
  179.     fprintf(stderr,"No color visual.  Cannot create graphics area.\n");
  180.     return;
  181.     }
  182.  
  183.     /* Create colormap */
  184.  
  185.     colormap = XCreateColormap( display, RootWindow(display,screen),
  186.                    visual, AllocNone );
  187.  
  188.     /* Establish basic attributes needed to successfully create window */
  189.  
  190.     winattr->border_pixel = 0;
  191.     winattr->background_pixel = 0;
  192.     winattr->colormap = colormap;
  193.  
  194.     wdg->core.depth = depth;
  195.  
  196.     XtCreateWindow(wdg, InputOutput, visual, (*mask | CWBackPixel |
  197.            CWColormap | CWBorderPixel), winattr);
  198.  
  199. } /* end of deep_realize */
  200.  
  201. void quit_callback()
  202. {
  203.  
  204.     exit(0);
  205.  
  206. }
  207.