summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/makefile2
-rw-r--r--examples/readme.md5
-rw-r--r--examples/xawhisto.c81
3 files changed, 86 insertions, 2 deletions
diff --git a/examples/makefile b/examples/makefile
index b65abd1..bb613e5 100644
--- a/examples/makefile
+++ b/examples/makefile
@@ -3,7 +3,7 @@ CC=gcc
CFLAGS=-Wall -g -I/usr/include/X11
LDFLAGS=-L.
LOADLIBES= -lX11 -lXt -lXaw
-FILES=viewport toggle strip scrollbar repeater pane menu list
+FILES=viewport toggle strip scrollbar repeater pane menu list xawhisto
all: $(FILES)
diff --git a/examples/readme.md b/examples/readme.md
index 06ae9ad..5e4a392 100644
--- a/examples/readme.md
+++ b/examples/readme.md
@@ -48,4 +48,7 @@ toggle
select, unselect one of many buttons
viewport
- shrink the window, select any of the buttons
+ shrink the window, select any of the buttons
+
+xawhisto
+ use the scollbar to show a value
diff --git a/examples/xawhisto.c b/examples/xawhisto.c
new file mode 100644
index 0000000..542bbf0
--- /dev/null
+++ b/examples/xawhisto.c
@@ -0,0 +1,81 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <X11/Intrinsic.h>
+#include <X11/StringDefs.h>
+#include <X11/Xaw/Form.h>
+#include <X11/Xaw/Command.h>
+#include <X11/Xaw/Scrollbar.h>
+
+
+static XtAppContext app_context;
+static Widget scrollbar;
+static Widget command;
+static XtIntervalId timerId;
+
+static void update(XtPointer client_data, XtIntervalId * id)
+{
+ char buf[28];
+ static int i = 1;
+
+ sprintf(buf, "% 2d%%", i);
+ XtVaSetValues(command, XtNlabel, buf, NULL);
+ XawScrollbarSetThumb(scrollbar, 0.0, (i / 100.0));
+ i ++;
+ i %= 100;
+ timerId = XtAppAddTimeOut(app_context, 500 , update, app_context);
+}
+
+static void cmd_cb(Widget w, XtPointer client_data, XtPointer call_data)
+{
+ XtAppSetExitFlag(XtWidgetToApplicationContext(w));
+}
+
+int main(int argc, char **argv)
+{
+
+ Widget form;
+ Widget topLevel;
+
+ topLevel = XtVaAppInitialize(&app_context, "demo",
+ NULL, 0,
+ &argc, argv, NULL, NULL);
+
+ form = XtVaCreateManagedWidget("form",
+ formWidgetClass, topLevel,
+ XtNorientation, XtorientHorizontal,
+ XtNborderWidth, 0,
+ XtNdefaultDistance, 2,
+ NULL);
+
+ command = XtVaCreateManagedWidget("command",
+ commandWidgetClass, form,
+ XtNleft, XtChainLeft,
+ XtNhighlightThickness, 0,
+ XtNborderWidth, 2,
+ XtNlabel, "start",
+ XtNresize, FALSE,
+ NULL);
+
+ scrollbar = XtVaCreateManagedWidget("scrollbar",
+ scrollbarWidgetClass, form,
+ XtNhorizDistance, 3,
+ XtNfromHoriz, command,
+ XtNorientation, XtorientHorizontal,
+ NULL);
+
+ XawScrollbarSetThumb(scrollbar, 0.0, 0.0);
+
+ /*
+ * disable interaction from scrollbar
+ */
+ XtVaSetValues(scrollbar,
+ XtNtranslations, XtParseTranslationTable(""), NULL);
+
+ XtAddCallback(command, XtNcallback, cmd_cb, NULL);
+
+ XtRealizeWidget(topLevel);
+ timerId = XtAppAddTimeOut(app_context, 0, update, app_context);
+ XtAppMainLoop(app_context);
+ return 0;
+}