1#define _GNU_SOURCE
2#include <stdlib.h>
3#include <stdio.h>
4#include <X11/StringDefs.h>
5#include <Xaw/Box.h>
6#include <Xaw/Label.h>
7#include <Xaw/Scrollbar.h>
8#include <Xaw/Command.h>
9
10static void
11quit_cb(Widget w, XtPointer client_data, XtPointer call_data)
12{
13        XtAppSetExitFlag(XtWidgetToApplicationContext(w));
14}
15
16static void
17scroll_cb(Widget widget,XtPointer label_ptr, XtPointer value_ptr)
18{
19	long value =  (long)value_ptr;
20    Widget label = (Widget) label_ptr;
21    char *msg=NULL;
22    asprintf(&msg, "%ld", value);
23    XtVaSetValues( label, XtNlabel, msg,     NULL);
24    free(msg);
25}
26static void
27jump_cb(Widget widget,XtPointer label_ptr, XtPointer value_ptr)
28{
29	float value =  *(float *)value_ptr;
30        Widget label = (Widget) label_ptr;
31	char *msg=NULL;
32	asprintf(&msg, "%lf", value);
33	XtVaSetValues( label, XtNlabel, msg,     NULL);
34	free(msg);
35}
36
37int main(int argc, char **argv)
38{
39  Widget toplevel,box,label,scroll,command;
40    XtAppContext app_con;
41    toplevel = XtAppInitialize(&app_con, "demo", NULL, 0,
42                               &argc, argv, NULL,
43                               NULL, 0);
44
45    box = XtCreateManagedWidget("box", boxWidgetClass, toplevel, NULL, 0);
46
47    label = XtVaCreateManagedWidget("Label",
48                                   labelWidgetClass,
49				    box, XtNlabel, "hello", NULL);
50
51    command = XtVaCreateManagedWidget("cmd",
52				    commandWidgetClass,  box,
53				    XtNlabel, "EXIT",
54				    NULL);
55
56    XtAddCallback(command, XtNcallback, quit_cb, NULL);
57
58    scroll = XtVaCreateManagedWidget("scroller",
59				     scrollbarWidgetClass, box,
60				     XtNorientation,XtorientHorizontal,
61				     XtNlength,500,
62				     XtNwidth,100,
63				     NULL);
64
65   XtAddCallback(scroll, XtNscrollProc, scroll_cb, label);
66   XtAddCallback(scroll,XtNjumpProc,jump_cb,label);
67
68    XtRealizeWidget(toplevel);
69
70    XtAppMainLoop(app_con);
71    exit(0);
72}
73