toggle.c revision efbcb2bf
1efbcb2bfSmrg#include <stdio.h> 2efbcb2bfSmrg#include <stdlib.h> 3efbcb2bfSmrg#include <X11/StringDefs.h> 4efbcb2bfSmrg#include <Xaw/Box.h> 5efbcb2bfSmrg#include <Xaw/Command.h> 6efbcb2bfSmrg#include <Xaw/Toggle.h> 7efbcb2bfSmrg 8efbcb2bfSmrgstatic Widget toggle[3]; 9efbcb2bfSmrgstatic Widget radio_group; 10efbcb2bfSmrg 11efbcb2bfSmrgstatic void 12efbcb2bfSmrgquit_cb(Widget w, XtPointer client_data, XtPointer call_data) 13efbcb2bfSmrg{ 14efbcb2bfSmrg XtAppSetExitFlag(XtWidgetToApplicationContext(w)); 15efbcb2bfSmrg} 16efbcb2bfSmrg 17efbcb2bfSmrgstatic void 18efbcb2bfSmrggetdata_cb(Widget w, XtPointer client_data, XtPointer call_data) 19efbcb2bfSmrg{ 20efbcb2bfSmrg char *radio_data=XawToggleGetCurrent(radio_group); 21efbcb2bfSmrg if (radio_data) 22efbcb2bfSmrg printf("radio_data=%s\n",radio_data); 23efbcb2bfSmrg else 24efbcb2bfSmrg printf("radio_data=%s\n","nodata"); 25efbcb2bfSmrg} 26efbcb2bfSmrg 27efbcb2bfSmrgstatic void 28efbcb2bfSmrgunset_cb(Widget w, XtPointer client_data, XtPointer call_data) 29efbcb2bfSmrg{ 30efbcb2bfSmrg XawToggleUnsetCurrent(radio_group); 31efbcb2bfSmrg} 32efbcb2bfSmrg 33efbcb2bfSmrg 34efbcb2bfSmrgstatic void 35efbcb2bfSmrgreset_cb(Widget w, XtPointer client_data, XtPointer call_data) 36efbcb2bfSmrg{ 37efbcb2bfSmrg XawToggleSetCurrent(radio_group,"3397"); 38efbcb2bfSmrg} 39efbcb2bfSmrg 40efbcb2bfSmrg 41efbcb2bfSmrgint main(int argc, char **argv) 42efbcb2bfSmrg{ 43efbcb2bfSmrg Widget toplevel,box,command; 44efbcb2bfSmrg XtAppContext app_con; 45efbcb2bfSmrg 46efbcb2bfSmrg toplevel = XtAppInitialize(&app_con, "demo", NULL, 0, 47efbcb2bfSmrg &argc, argv, NULL, 48efbcb2bfSmrg NULL, 0); 49efbcb2bfSmrg 50efbcb2bfSmrg box = XtCreateManagedWidget("box", boxWidgetClass, toplevel, NULL, 0); 51efbcb2bfSmrg 52efbcb2bfSmrg command = XtVaCreateManagedWidget("cmd", 53efbcb2bfSmrg commandWidgetClass, box, 54efbcb2bfSmrg XtNlabel, "EXIT", 55efbcb2bfSmrg NULL); 56efbcb2bfSmrg 57efbcb2bfSmrg toggle[0]=XtVaCreateManagedWidget("toggle", 58efbcb2bfSmrg toggleWidgetClass, box, 59efbcb2bfSmrg// XtNradioData,radioname, 60efbcb2bfSmrg XtNradioGroup,radio_group, 61efbcb2bfSmrg XtNlabel, "track", 62efbcb2bfSmrg NULL); 63efbcb2bfSmrg radio_group=toggle[0]; 64efbcb2bfSmrg toggle[1]=XtVaCreateManagedWidget("toggle", 65efbcb2bfSmrg toggleWidgetClass, box, 66efbcb2bfSmrg// XtNradioData,radioname, 67efbcb2bfSmrg XtNradioGroup,radio_group, 68efbcb2bfSmrg XtNlabel, "trick", 69efbcb2bfSmrg NULL); 70efbcb2bfSmrg 71efbcb2bfSmrg toggle[2]=XtVaCreateManagedWidget("toggle", 72efbcb2bfSmrg toggleWidgetClass, box, 73efbcb2bfSmrg XtNradioData,"3397", 74efbcb2bfSmrg XtNradioGroup,radio_group, 75efbcb2bfSmrg XtNlabel, "tick", 76efbcb2bfSmrg NULL); 77efbcb2bfSmrg 78efbcb2bfSmrg XtAddCallback(command, XtNcallback, quit_cb, NULL); 79efbcb2bfSmrg 80efbcb2bfSmrg command = XtVaCreateManagedWidget("getcurrent", 81efbcb2bfSmrg commandWidgetClass, box, 82efbcb2bfSmrg XtNlabel, "say ", 83efbcb2bfSmrg NULL); 84efbcb2bfSmrg XtAddCallback(command, XtNcallback, getdata_cb, NULL); 85efbcb2bfSmrg 86efbcb2bfSmrg command = XtVaCreateManagedWidget("unsetcurrent", 87efbcb2bfSmrg commandWidgetClass, box, 88efbcb2bfSmrg XtNlabel, "unset ", 89efbcb2bfSmrg NULL); 90efbcb2bfSmrg XtAddCallback(command, XtNcallback, unset_cb, NULL); 91efbcb2bfSmrg 92efbcb2bfSmrg 93efbcb2bfSmrg command = XtVaCreateManagedWidget("setnew", 94efbcb2bfSmrg commandWidgetClass, box, 95efbcb2bfSmrg XtNlabel, "setnew", 96efbcb2bfSmrg NULL); 97efbcb2bfSmrg 98efbcb2bfSmrg XtAddCallback(command, XtNcallback, reset_cb, NULL); 99efbcb2bfSmrg 100efbcb2bfSmrg XtRealizeWidget(toplevel); 101efbcb2bfSmrg XtAppMainLoop(app_con); 102efbcb2bfSmrg exit(0); 103efbcb2bfSmrg} 104