home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / windows / x / 19221 < prev    next >
Encoding:
Text File  |  1992-11-17  |  3.8 KB  |  137 lines

  1. Newsgroups: comp.windows.x
  2. Path: sparky!uunet!usc!rpi!uwm.edu!spool.mu.edu!yale.edu!jvnc.net!darwin.sura.net!udel!intercon!psinntp!sunic!dkuug!daimi!datpete
  3. From: datpete@daimi.aau.dk (Peter Andersen)
  4. Subject: RadioGroups in Aw ??
  5. Message-ID: <1992Nov17.095011.29951@daimi.aau.dk>
  6. Sender: datpete@daimi.aau.dk (Peter Andersen)
  7. Reply-To: datpete@mjolner.dk (Peter Andersen)
  8. Organization: DAIMI: Computer Science Department, Aarhus University, Denmark
  9. Date: Tue, 17 Nov 92 09:50:11 GMT
  10. Lines: 125
  11.  
  12. I have tried using the Toggles of the Athena widgets (X11R4).
  13. I want to use them for a radio panel.
  14. I have created 5 Toggles t1, t2, t3, t4, and t5, that I connect
  15. in the following way:
  16.  
  17.     XtSetArg(arg, XtNradioGroup, t1);
  18.     XtSetValues(t2, arg, 1);
  19.     XtSetArg(arg, XtNradioGroup, t2);
  20.     XtSetValues(t1, arg, 1);
  21.     XtSetArg(arg, XtNradioGroup, t2);
  22.     XtSetValues(t3, arg, 1);
  23.     XtSetArg(arg, XtNradioGroup, t3);
  24.     XtSetValues(t4, arg, 1);
  25.     XtSetArg(arg, XtNradioGroup, t4);
  26.     XtSetValues(t5, arg, 1);
  27.  
  28. (The complete program in this version is added at the end).
  29.  
  30. This works fine, the previously selected toggle deselects
  31. when another is clicked.
  32.  
  33. My problem is that, if I change it to the somewhat more natural
  34.  
  35.     XtSetArg(arg, XtNradioGroup, t2);
  36.     XtSetValues(t1, arg, 1);
  37.     XtSetArg(arg, XtNradioGroup, t3);
  38.     XtSetValues(t2, arg, 1);
  39.     XtSetArg(arg, XtNradioGroup, t4);
  40.     XtSetValues(t3, arg, 1);
  41.     XtSetArg(arg, XtNradioGroup, t5);
  42.     XtSetValues(t4, arg, 1);
  43.     XtSetArg(arg, XtNradioGroup, t1);
  44.     XtSetValues(t5, arg, 1);
  45.  
  46. it does not work!
  47.  
  48. I have various other combinations that work, and some that
  49. does not. I have tried to read the manual very carefully, but
  50. so far I have not figured out the pattern!
  51.  
  52. Can anyone explain this to me in detail?
  53.  
  54. The first (working) version:
  55.  
  56.  
  57. #include <stdio.h>
  58. #include <X11/Intrinsic.h>
  59. #include <X11/StringDefs.h>    /* Get standard string definations. */
  60.  
  61. #include <X11/Xaw/Toggle.h>    
  62. #include <X11/Xaw/Box.h>    
  63. #include <X11/Xaw/Cardinals.h>    
  64.  
  65. extern void exit();
  66.  
  67. main(argc, argv)
  68. int argc;
  69. char **argv;
  70. {
  71.     static XtCallbackProc Print();
  72.     int i;
  73.     Arg arg;
  74.     XtAppContext app_con;
  75.     Widget toplevel, box, t1, t2, t3, t4, t5;
  76.  
  77.     toplevel = XtAppInitialize(&app_con, "Xradiobutton",
  78.                    0, 0, &argc, argv, 0, NULL, ZERO);
  79.  
  80.     box = XtCreateManagedWidget("box", boxWidgetClass, toplevel,
  81.                 NULL, ZERO);
  82.     
  83.     /*
  84.      * Put a command widget in the box.
  85.      */
  86.  
  87.     t1 = XtCreateManagedWidget("toggle1", toggleWidgetClass, box,
  88.                    NULL, ZERO);
  89.     XtAddCallback(t1, XtNcallback, Print, NULL);
  90.  
  91.     t2 = XtCreateManagedWidget("toggle2", toggleWidgetClass, box,
  92.                    NULL, ZERO);
  93.     XtAddCallback(t2, XtNcallback, Print, NULL);
  94.  
  95.     t3 = XtCreateManagedWidget("toggle3", toggleWidgetClass, box,
  96.                    NULL, ZERO);
  97.     XtAddCallback(t3, XtNcallback, Print, NULL);
  98.  
  99.     t4 = XtCreateManagedWidget("toggle4", toggleWidgetClass, box,
  100.                    NULL, ZERO);
  101.     XtAddCallback(t4, XtNcallback, Print, NULL);
  102.  
  103.     t5 = XtCreateManagedWidget("toggle5", toggleWidgetClass, box,
  104.                    NULL, ZERO);
  105.     XtAddCallback(t5, XtNcallback, Print, NULL);
  106.  
  107.     /* specify radiogroup connection */
  108.     
  109.     XtSetArg(arg, XtNradioGroup, t1);
  110.     XtSetValues(t2, arg, 1);
  111.     XtSetArg(arg, XtNradioGroup, t2);
  112.     XtSetValues(t1, arg, 1);
  113.     XtSetArg(arg, XtNradioGroup, t2);
  114.     XtSetValues(t3, arg, 1);
  115.     XtSetArg(arg, XtNradioGroup, t3);
  116.     XtSetValues(t4, arg, 1);
  117.     XtSetArg(arg, XtNradioGroup, t4);
  118.     XtSetValues(t5, arg, 1);
  119.     
  120.     XtRealizeWidget(toplevel);
  121.     XtAppMainLoop(app_con);
  122. }
  123.  
  124. static XtCallbackProc
  125. Print(w, call_data, client_data)
  126. Widget w;
  127. XtPointer call_data, client_data;
  128. {
  129.   Boolean state;
  130.   Arg arg;
  131.   XtSetArg(arg, XtNstate, &state);
  132.   XtGetValues(w, &arg, 1);
  133.   fprintf(stdout, "%s %s\n", XtName(w), (state)? "on" : "off" );
  134. }
  135.  
  136. Peter Andersen
  137.