home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / gnu / gcc / help / 3037 < prev    next >
Encoding:
Text File  |  1993-01-27  |  6.2 KB  |  234 lines

  1. Xref: sparky gnu.gcc.help:3037 comp.os.vms:22045
  2. Path: sparky!uunet!uunet.ca!canrem!telly!utzoo!torn!spool.mu.edu!sdd.hp.com!swrinde!gatech!concert!ais.com!bruce
  3. From: bruce@ais.com (Bruce C. Wright)
  4. Newsgroups: gnu.gcc.help,comp.os.vms
  5. Subject: Using GCC on VMS DECwindows/Motif
  6. Message-ID: <1993Jan27.132430.5967@ais.com>
  7. Date: 27 Jan 93 13:24:30 GMT
  8. Organization: Applied Information Systems, Chapel Hill, NC
  9. Lines: 223
  10.  
  11. Has anyone successfully used Gnu CC under VMS to link to the DECwindows
  12. Motif libraries?  The version I have (1.40) can't deal with the Motif
  13. header files that DEC ships, because they use things like externalref
  14. that are available in DEC's VAX C compiler but not in gcc.  So far
  15. none of the obvious workarounds have worked (adding a line to the
  16. source file like `#define externalref extern' will compile and build
  17. but when it runs it gets the wrong values for some of the Motif constants
  18. and fails -- apparently gcc's semantics for extern don't match VAX C's
  19. semantics for externalref).  Some X11 .h files don't have the problem --
  20. it's particularly (exclusively?) the Motif *.h files.  I can build
  21. lots of things that don't use Motif but so far have had trouble getting
  22. gcc to deal with the Motif widget class constants and similar things.
  23.  
  24. I'm sure I can solve this by building my own copy of X using gcc,
  25. and possibly by editing _all_ of the X11 .h files to use more standard
  26. C syntax :-(  but I'd rather not if there's a better (easier) way.
  27. Below is a simple program to demonstrate the problem.  It needs to be
  28. compiled and linked with:
  29.  
  30.     $ gcc /nocase test
  31.     $ link test,xwin/opt
  32.  
  33. xwin.opt:
  34.     sys$share:vaxcrtl    /share
  35.     sys$share:decw$xlibshr    /share
  36.     sys$share:decw$xmlibshr    /share
  37.  
  38. The error I get is:
  39.  
  40.     X Toolkit Error: XtCreateWidget requires non-NULL widget class
  41.  
  42. on the call to XtCreateManagedWidget.  I'd like to find a solution that
  43. doesn't require making changes to DECwindows (like recompiling the X
  44. libraries from the MIT distribution), making extensive editing changes
  45. to the source files (I have lots of them, adding a short #ifdef at the
  46. top of each is OK but lots of editing to the bodies of the files will be
  47. a lot of trouble), or use VAX C (the machine this is for doesn't have a
  48. license for it).
  49.  
  50. Thanks,
  51.  
  52. Bruce C. Wright
  53.  
  54. ------------------------- cut here ---------------------------
  55. /*
  56.  * test1.c
  57.  *
  58.  *    A minimalist X program.
  59.  */
  60.  
  61. #ifdef __GNUC__
  62. /* #include <sys/types.h> */
  63. #define externalref extern
  64. #define NO_X_GBLS
  65. #endif
  66.  
  67. #include <X11/StringDefs.h>
  68. #include <X11/Xlib.h>
  69. #include <X11/Intrinsic.h>
  70. #include <X11/Xutil.h>
  71. #include <Xm/Xm.h>
  72. #include <Xm/DrawingA.h>
  73.  
  74. #define    START_CIRCLE    0
  75. #define    FULL_CIRCLE    (64*360)
  76.  
  77. void resize ();
  78. void redisplay ();
  79.  
  80. typedef struct    {
  81.     int        depth, ncolors;
  82.     GC        gc;
  83.     Dimension     width, height;
  84. } image_data, *image_data_ptr;
  85.  
  86. unsigned long    iRedPixel;
  87. unsigned long    iBluePixel;
  88. unsigned long    iGreenPixel;
  89. unsigned long    iYellowPixel;
  90. unsigned long    iWhitePixel;
  91. unsigned long    iBlackPixel;
  92. unsigned long    iCyanPixel;
  93. unsigned long    iMagentaPixel;
  94.  
  95. main (argc, argv)
  96.     int    argc;
  97.     char    *argv [];
  98. {
  99.     Widget        toplevel, canvas;
  100.     image_data    data;
  101.  
  102.     toplevel = XtInitialize (argv [0], "Test", NULL, 0,
  103.                 &argc, argv);
  104.     /*
  105.      */
  106. /*    XtGetApplicationResources (toplevel, &data, resources,
  107.                 XtNumber (resources), NULL, 0);
  108.     /*
  109.      * Create the widget to display.
  110.      */
  111.     canvas = XtCreateManagedWidget ("canvas",
  112.                     xmDrawingAreaWidgetClass,
  113.                     toplevel, NULL, 0);
  114.     printf ("Widget created\n");
  115.     init_data (canvas, &data);
  116.     printf ("Data initialized\n");
  117.      XtAddCallback (canvas, XmNexposeCallback, redisplay, &data);
  118.     XtAddCallback (canvas, XmNresizeCallback, resize, &data);
  119.  
  120.     XtRealizeWidget (toplevel);
  121.     printf ("Widget realized\n");
  122.  
  123.     iRedPixel = get_pixel (canvas, "red");
  124.     iGreenPixel = get_pixel (canvas, "green");
  125.     iBluePixel = get_pixel (canvas, "blue");
  126.     iYellowPixel = get_pixel (canvas, "yellow");
  127.     iWhitePixel = get_pixel (canvas, "white");
  128.     iBlackPixel = get_pixel (canvas, "black");
  129.     iCyanPixel = get_pixel (canvas, "cyan");
  130.     iMagentaPixel = get_pixel (canvas, "magenta");
  131.  
  132.     printf ("get_pixel called\n");
  133.  
  134.     resize (canvas, &data, NULL);
  135.  
  136.     printf ("resize called\n");
  137.  
  138.     XtMainLoop ();
  139.  
  140. }
  141.  
  142. init_data (w, data)
  143.     Widget        w;
  144.     image_data    *data;
  145. {
  146.     Arg    wargs [2];
  147.  
  148.     /*
  149.      * Get the size of the drawing area.
  150.      */
  151.     XtSetArg (wargs [0], XtNwidth,    &data->width);
  152.     XtSetArg (wargs [1], XtNheight, &data->height);
  153.     XtGetValues (w, wargs, 2);
  154.  
  155.     /*
  156.      * Find out how many colors we have to work with, and create
  157.      * a default, writeable, graphics context.
  158.      */
  159.     data->ncolors = XDisplayCells (XtDisplay (w),
  160.                        XDefaultScreen (XtDisplay (w)));
  161.     data->gc = XCreateGC (XtDisplay (w),
  162.                 DefaultRootWindow (XtDisplay (w)),
  163.                 NULL, NULL);
  164. }
  165.  
  166. get_pixel (w, colorname)
  167.     Widget     w;
  168.     char    *colorname;
  169. {
  170.     Display *dpy    = XtDisplay (w);
  171.     int    scr    = DefaultScreen (dpy);
  172.     Colormap cmap    = DefaultColormap (dpy, scr);
  173.     XColor    color, ignore;
  174.  
  175.     if (XAllocNamedColor (dpy, cmap, colorname, &color, &ignore))
  176.         return (color.pixel);
  177.     else
  178.         {
  179.         printf ("Warning: Couldn't allocate color %s\n", colorname);
  180.         return (BlackPixel (dpy, scr));
  181.         }
  182. }    
  183.  
  184. void redisplay (w, data, call_data)
  185.     Widget        w;
  186.     image_data    *data;
  187.     caddr_t        call_data;
  188. {
  189.     Display    *dpy    = XtDisplay (w);
  190.     Window     wnd    = XtWindow (w);
  191.     /*
  192.      * Draw the data on the window.
  193.      */
  194.     XSetForeground (dpy, data->gc, iRedPixel);
  195.     XDrawLine (dpy, wnd, data->gc, 10, 10, 100, 100);
  196.  
  197.     XSetForeground (dpy, data->gc, iYellowPixel);
  198.     XDrawRectangle (dpy, wnd, data->gc, 100, 100, 100, 100);    
  199.  
  200.     XSetForeground (dpy, data->gc, iGreenPixel);
  201.     XDrawArc (dpy, wnd, data->gc, 110, 110, 100, 100,
  202.                 START_CIRCLE, FULL_CIRCLE);
  203.  
  204.     XSetForeground (dpy, data->gc, iCyanPixel);
  205.     XFillRectangle (dpy, wnd, data->gc, 200, 200, 100, 100);
  206.  
  207.     XSetForeground (dpy, data->gc, iBluePixel);
  208.     XFillArc (dpy, wnd, data->gc, 200, 200, 100, 100,
  209.                 START_CIRCLE, FULL_CIRCLE);
  210. }
  211.  
  212. void resize (w, data, call_data)
  213.     Widget        w;
  214.     image_data    *data;
  215.     caddr_t        call_data;
  216. {
  217.     Arg    wargs [10];
  218.     /*
  219.      * Get the new window size
  220.      */
  221.     XtSetArg (wargs [0], XtNwidth,    &data->width);
  222.     XtSetArg (wargs [1], XtNheight, &data->height);
  223.     XtGetValues (w, wargs, 2);
  224.     /*
  225.      * Clear the window and generate an Expose event for
  226.      * the entire window.
  227.      */
  228.     if (XtIsRealized (w))
  229.         XClearArea (XtDisplay (w), XtWindow (w), 0, 0, 0, 0, TRUE);
  230. }
  231. ------------------------- cut here ---------------------------
  232.  
  233.  
  234.