home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / fj / maillis / xwindow / 17553 < prev    next >
Encoding:
Text File  |  1992-11-17  |  3.9 KB  |  143 lines

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