summaryrefslogtreecommitdiff
path: root/lib/libXaw/examples/toggle.c
blob: 2d7e88b8fb019081e663ad0d51a1175e338c03ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include <stdio.h>
#include <stdlib.h>
#include <X11/StringDefs.h>	   
#include <Xaw/Box.h>
#include <Xaw/Command.h>
#include <Xaw/Toggle.h>

static Widget toggle[3];
static Widget    radio_group;

static void
quit_cb(Widget w, XtPointer client_data, XtPointer call_data)
{
        XtAppSetExitFlag(XtWidgetToApplicationContext(w));
}

static void
getdata_cb(Widget w, XtPointer client_data, XtPointer call_data)
{
	char *radio_data=XawToggleGetCurrent(radio_group);
	if (radio_data) 
		printf("radio_data=%s\n",radio_data);
	else
		printf("radio_data=%s\n","nodata");
}

static void
unset_cb(Widget w, XtPointer client_data, XtPointer call_data)
{
	XawToggleUnsetCurrent(radio_group);
}


static void
reset_cb(Widget w, XtPointer client_data, XtPointer call_data)
{
	XawToggleSetCurrent(radio_group,"3397");
}


int main(int argc, char **argv)
{
	Widget toplevel,box,command;
	XtAppContext app_con;

	toplevel = XtAppInitialize(&app_con, "demo", NULL, 0,
                               &argc, argv, NULL,
                               NULL, 0);
	
    box = XtCreateManagedWidget("box", boxWidgetClass, toplevel, NULL, 0);

    command = XtVaCreateManagedWidget("cmd",
                                   commandWidgetClass,  box,
				      XtNlabel, "EXIT",
				      NULL);

    toggle[0]=XtVaCreateManagedWidget("toggle",
				   toggleWidgetClass,  box,
//				   XtNradioData,radioname,
				   XtNradioGroup,radio_group,
   			           XtNlabel, "track",
				   NULL);
    radio_group=toggle[0];
    toggle[1]=XtVaCreateManagedWidget("toggle",
				   toggleWidgetClass,  box,
//				   XtNradioData,radioname,
   				   XtNradioGroup,radio_group,
   			           XtNlabel, "trick",
				    NULL);

    toggle[2]=XtVaCreateManagedWidget("toggle",
				   toggleWidgetClass,  box,
				   XtNradioData,"3397",
				   XtNradioGroup,radio_group,
   			           XtNlabel, "tick",
				    NULL);

    XtAddCallback(command, XtNcallback, quit_cb, NULL);

    command = XtVaCreateManagedWidget("getcurrent",
                                   commandWidgetClass,  box,
				      XtNlabel, "say ",
				      NULL);
      XtAddCallback(command, XtNcallback, getdata_cb, NULL);

      command = XtVaCreateManagedWidget("unsetcurrent",
                                   commandWidgetClass,  box,
				      XtNlabel, "unset ",
				      NULL);
      XtAddCallback(command, XtNcallback, unset_cb, NULL);

      
      command = XtVaCreateManagedWidget("setnew",
                                   commandWidgetClass,  box,
				      XtNlabel, "setnew",
				      NULL);

      XtAddCallback(command, XtNcallback, reset_cb, NULL);
	
    XtRealizeWidget(toplevel);
    XtAppMainLoop(app_con);
    exit(0);
}