| 1 |
#include <stdlib.h> |
| 2 |
#include <stdio.h> |
| 3 |
#include <X11/StringDefs.h> |
| 4 |
#include <Xaw/Box.h> |
| 5 |
#include <Xaw/Command.h> |
| 6 |
#include <Xaw/Repeater.h> |
| 7 |
|
| 8 |
static int counter; |
| 9 |
|
| 10 |
static void |
| 11 |
quit_cb(Widget w, XtPointer client_data, XtPointer call_data) |
| 12 |
{ |
| 13 |
XtAppSetExitFlag(XtWidgetToApplicationContext(w)); |
| 14 |
} |
| 15 |
|
| 16 |
static void |
| 17 |
start_cb(Widget w, XtPointer ptr, XtPointer arg) |
| 18 |
{ |
| 19 |
#ifdef DEBUG |
| 20 |
puts("Start"); |
| 21 |
#endif |
| 22 |
} |
| 23 |
|
| 24 |
static void |
| 25 |
do_cb(Widget w, XtPointer ptr, XtPointer arg) |
| 26 |
{ |
| 27 |
char buf[10]; |
| 28 |
Widget show= (Widget)ptr; |
| 29 |
counter++; |
| 30 |
snprintf(buf,10,"%d",counter); |
| 31 |
XtVaSetValues(show,XtNlabel,buf,NULL); |
| 32 |
#ifdef DEBUG |
| 33 |
puts("counter"); |
| 34 |
#endif |
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
static void |
| 39 |
stop_cb(Widget w, XtPointer ptr, XtPointer arg) |
| 40 |
{ |
| 41 |
counter=0; |
| 42 |
#ifdef DEBUG |
| 43 |
puts("reset counter"); |
| 44 |
#endif |
| 45 |
} |
| 46 |
|
| 47 |
int main(int argc, char **argv) |
| 48 |
{ |
| 49 |
Widget toplevel,box,command,rep; |
| 50 |
XtAppContext app_con; |
| 51 |
toplevel = XtAppInitialize(&app_con, "demo", NULL, 0, |
| 52 |
&argc, argv, NULL, |
| 53 |
NULL, 0); |
| 54 |
|
| 55 |
box = XtCreateManagedWidget("box", boxWidgetClass, toplevel, NULL, 0); |
| 56 |
|
| 57 |
command = XtVaCreateManagedWidget("cmd", |
| 58 |
commandWidgetClass, box, |
| 59 |
XtNlabel, "EXIT", |
| 60 |
NULL); |
| 61 |
XtAddCallback(command, XtNcallback, quit_cb, NULL); |
| 62 |
|
| 63 |
rep=XtVaCreateManagedWidget("Repeater", |
| 64 |
repeaterWidgetClass, |
| 65 |
box, XtNlabel,"hitme",NULL); |
| 66 |
|
| 67 |
XtAddCallback(rep,XtNstartCallback,start_cb,command); |
| 68 |
|
| 69 |
XtAddCallback(rep,XtNcallback,do_cb,command); |
| 70 |
|
| 71 |
XtAddCallback(rep,XtNstopCallback,stop_cb,command); |
| 72 |
|
| 73 |
XtRealizeWidget(toplevel); |
| 74 |
|
| 75 |
XtAppMainLoop(app_con); |
| 76 |
exit(0); |
| 77 |
} |