summaryrefslogtreecommitdiff
path: root/examples/repeater.c
blob: f6b1f5922f48e9688f82298dc21be4a378543e4e (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
#include <stdlib.h>
#include <stdio.h>
#include <X11/StringDefs.h>
#include <Xaw/Box.h>
#include <Xaw/Command.h>
#include <Xaw/Repeater.h>

static int counter;

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

static void
start_cb(Widget w, XtPointer ptr, XtPointer arg) 
{
#ifdef DEBUG	
	puts("Start");
#endif
}

static void
do_cb(Widget w, XtPointer ptr, XtPointer arg) 
{
	char buf[10];
	Widget show= (Widget)ptr;
	counter++;
	snprintf(buf,10,"%d",counter);
	XtVaSetValues(show,XtNlabel,buf,NULL);
#ifdef DEBUG
	puts("counter");
#endif
}


static void
stop_cb(Widget w, XtPointer ptr, XtPointer arg) 
{
	counter=0;
#ifdef DEBUG
	puts("reset counter");
#endif
}

int main(int argc, char **argv)
{
  Widget toplevel,box,command,rep;
  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);
  XtAddCallback(command, XtNcallback, quit_cb, NULL);

  rep=XtVaCreateManagedWidget("Repeater",
			      repeaterWidgetClass,
			      box,  XtNlabel,"hitme",NULL);

  XtAddCallback(rep,XtNstartCallback,start_cb,command);

  XtAddCallback(rep,XtNcallback,do_cb,command);

  XtAddCallback(rep,XtNstopCallback,stop_cb,command);
    
  XtRealizeWidget(toplevel);

  XtAppMainLoop(app_con);
  exit(0);
}