1#include <stdio.h>
2#include <stdlib.h>
3
4#include <X11/Intrinsic.h>
5#include <X11/StringDefs.h>
6#include <X11/Xaw/Form.h>
7#include <X11/Xaw/Command.h>
8#include <X11/Xaw/Scrollbar.h>
9
10
11static XtAppContext app_context;
12static Widget scrollbar;
13static Widget command;
14static XtIntervalId timerId;
15
16static void update(XtPointer client_data, XtIntervalId * id)
17{
18    char buf[28];
19    static int i = 1;
20
21    sprintf(buf, "% 2d%%", i);
22    XtVaSetValues(command, XtNlabel, buf, NULL);
23    XawScrollbarSetThumb(scrollbar, 0.0, (i / 100.0));
24    i ++;
25    i %= 100;
26    timerId = XtAppAddTimeOut(app_context, 500 , update, app_context);
27}
28
29static void cmd_cb(Widget w, XtPointer client_data, XtPointer call_data)
30{
31	XtAppSetExitFlag(XtWidgetToApplicationContext(w));
32}
33
34int main(int argc, char **argv)
35{
36
37    Widget form;
38    Widget topLevel;
39
40    topLevel = XtVaAppInitialize(&app_context, "demo",
41				 NULL, 0,
42				 &argc, argv, NULL, NULL);
43
44    form = XtVaCreateManagedWidget("form",
45				   formWidgetClass, topLevel,
46				   XtNorientation, XtorientHorizontal,
47				   XtNborderWidth, 0,
48				   XtNdefaultDistance, 2,
49				   NULL);
50
51    command = XtVaCreateManagedWidget("command",
52				      commandWidgetClass, form,
53				      XtNleft, XtChainLeft,
54				      XtNhighlightThickness, 0,
55				      XtNborderWidth, 2,
56				      XtNlabel, "start",
57				      XtNresize, FALSE,
58				      NULL);
59
60    scrollbar = XtVaCreateManagedWidget("scrollbar",
61					scrollbarWidgetClass, form,
62					XtNhorizDistance, 3,
63					XtNfromHoriz, command,
64 				        XtNorientation, XtorientHorizontal,
65					NULL);
66
67    XawScrollbarSetThumb(scrollbar, 0.0, 0.0);
68
69    /*
70     * disable interaction from scrollbar
71     */
72    XtVaSetValues(scrollbar,
73		  XtNtranslations, XtParseTranslationTable(""), NULL);
74
75    XtAddCallback(command, XtNcallback, cmd_cb, NULL);
76
77    XtRealizeWidget(topLevel);
78    timerId = XtAppAddTimeOut(app_context, 0, update, app_context);
79    XtAppMainLoop(app_context);
80    return 0;
81}
82