ui/motif/label.c

Sat, 04 Jan 2025 16:22:14 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sat, 04 Jan 2025 16:22:14 +0100
branch
newapi
changeset 429
0921f8a5d535
parent 428
c7dcd2ab2d3d
child 430
ea949c0109d8
permissions
-rw-r--r--

implement progressbar (Motif)

62
70d2aee84432 added grid container (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
70d2aee84432 added grid container (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
70d2aee84432 added grid container (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
428
c7dcd2ab2d3d implement label (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
4 * Copyright 2024 Olaf Wintermann. All rights reserved.
62
70d2aee84432 added grid container (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
70d2aee84432 added grid container (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
70d2aee84432 added grid container (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
70d2aee84432 added grid container (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
70d2aee84432 added grid container (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
70d2aee84432 added grid container (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
70d2aee84432 added grid container (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
70d2aee84432 added grid container (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
70d2aee84432 added grid container (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
70d2aee84432 added grid container (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
70d2aee84432 added grid container (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
70d2aee84432 added grid container (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
70d2aee84432 added grid container (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
70d2aee84432 added grid container (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
70d2aee84432 added grid container (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
70d2aee84432 added grid container (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
70d2aee84432 added grid container (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
70d2aee84432 added grid container (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
70d2aee84432 added grid container (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
70d2aee84432 added grid container (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
70d2aee84432 added grid container (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
70d2aee84432 added grid container (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
70d2aee84432 added grid container (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
70d2aee84432 added grid container (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
70d2aee84432 added grid container (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #include <stdio.h>
70d2aee84432 added grid container (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30 #include <stdlib.h>
70d2aee84432 added grid container (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31
70d2aee84432 added grid container (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32 #include "label.h"
70d2aee84432 added grid container (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33 #include "container.h"
70d2aee84432 added grid container (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34 #include "../common/context.h"
70d2aee84432 added grid container (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35 #include "../common/object.h"
70d2aee84432 added grid container (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36
429
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
37 #include "Grid.h"
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
38
428
c7dcd2ab2d3d implement label (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
39 static UIWIDGET label_create(UiObject *obj, UiLabelArgs args, int align) {
c7dcd2ab2d3d implement label (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
40 Arg xargs[16];
c7dcd2ab2d3d implement label (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
41 int n = 0;
c7dcd2ab2d3d implement label (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
42
c7dcd2ab2d3d implement label (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
43 UiContainerPrivate *ctn = ui_obj_container(obj);
c7dcd2ab2d3d implement label (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
44 UI_APPLY_LAYOUT(ctn->layout, args);
c7dcd2ab2d3d implement label (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
45
c7dcd2ab2d3d implement label (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
46 Widget parent = ctn->prepare(ctn, xargs, &n);
c7dcd2ab2d3d implement label (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
47
c7dcd2ab2d3d implement label (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
48 XtSetArg(xargs[n], XmNalignment, align); n++;
c7dcd2ab2d3d implement label (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
49 XmString label = NULL;
c7dcd2ab2d3d implement label (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
50 if(args.label) {
c7dcd2ab2d3d implement label (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
51 label = XmStringCreateLocalized((char*)args.label);
c7dcd2ab2d3d implement label (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
52 XtSetArg(xargs[n], XmNlabelString, label); n++;
c7dcd2ab2d3d implement label (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
53 }
c7dcd2ab2d3d implement label (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
54
c7dcd2ab2d3d implement label (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
55 char *name = args.name ? (char*)args.name : "label";
c7dcd2ab2d3d implement label (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
56 Widget w = XmCreateLabel(parent, name, xargs, n);
c7dcd2ab2d3d implement label (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
57 XtManageChild(w);
c7dcd2ab2d3d implement label (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
58 ctn->add(ctn, w);
c7dcd2ab2d3d implement label (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
59
c7dcd2ab2d3d implement label (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
60 XmStringFree(label);
c7dcd2ab2d3d implement label (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
61 return w;
c7dcd2ab2d3d implement label (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
62 }
c7dcd2ab2d3d implement label (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
63
c7dcd2ab2d3d implement label (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
64 UIWIDGET ui_label_create(UiObject* obj, UiLabelArgs args) {
c7dcd2ab2d3d implement label (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
65 return label_create(obj, args, XmALIGNMENT_CENTER);
c7dcd2ab2d3d implement label (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
66 }
c7dcd2ab2d3d implement label (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
67
c7dcd2ab2d3d implement label (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
68 UIWIDGET ui_llabel_create(UiObject* obj, UiLabelArgs args) {
c7dcd2ab2d3d implement label (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
69 return label_create(obj, args, XmALIGNMENT_BEGINNING);
c7dcd2ab2d3d implement label (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
70 }
c7dcd2ab2d3d implement label (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
71
c7dcd2ab2d3d implement label (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
72 UIWIDGET ui_rlabel_create(UiObject* obj, UiLabelArgs args) {
c7dcd2ab2d3d implement label (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
73 return label_create(obj, args, XmALIGNMENT_END);
c7dcd2ab2d3d implement label (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
74 }
429
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
75
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
76
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
77 /* ------------------------------ progressbar ------------------------------ */
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
78
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
79 static void ui_destroy_progressbar(Widget w, UiProgressBar *pb, XtPointer d) {
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
80 // TODO: free other stuff
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
81 free(pb);
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
82 }
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
83
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
84 static void ui_progressbar_expose(Widget widget, UiProgressBar *pb, XtPointer c) {
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
85 Display *dp = XtDisplay(widget);
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
86 Window w = XtWindow(widget);
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
87 if(!pb->gc) {
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
88 XGCValues gcvals;
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
89 gcvals.foreground = pb->color;
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
90 pb->gc = XCreateGC(dp, w, (GCForeground), &gcvals);
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
91 }
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
92
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
93 Dimension width = widget->core.width;
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
94 Dimension height = widget->core.height;
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
95
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
96 double value = (pb->value - pb->min) / (pb->max - pb->min);
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
97 Dimension valueW = (double)width * value;
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
98
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
99 XClearArea(dp, w, 0, 0, width, height, False);
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
100 XFillRectangle(dp, w, pb->gc, 0, 0, valueW, widget->core.height);
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
101 }
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
102
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
103 UIWIDGET ui_progressbar_create(UiObject *obj, UiProgressbarArgs args) {
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
104 Arg xargs[16];
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
105 int n = 0;
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
106
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
107 UiContainerPrivate *ctn = ui_obj_container(obj);
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
108 UI_APPLY_LAYOUT(ctn->layout, args);
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
109
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
110 Widget parent = ctn->prepare(ctn, xargs, &n);
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
111
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
112 char *name = args.name ? (char*)args.name : "progressbar";
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
113 Widget frame = XmCreateFrame(parent, name, xargs, n);
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
114
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
115 // create a button and get some informations about the height, shadow, highlight, ....
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
116 // we want the frame to have the same dimensions as a normal button
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
117 Widget test = XmCreatePushButton(frame, "button", NULL, 0);
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
118 XtManageChild(test);
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
119 Dimension h, highlightThickness, shadowThickness;
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
120 Pixel highlightColor;
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
121 XtVaGetValues(test, XmNheight, &h, XmNhighlightThickness, &highlightThickness,
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
122 XmNshadowThickness, &shadowThickness, XmNhighlightColor, &highlightColor, NULL);
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
123 XtDestroyWidget(test);
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
124
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
125 // adjust frame
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
126 XtVaSetValues(frame, XmNshadowThickness, shadowThickness, gridMarginLeft, highlightThickness,
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
127 gridMarginRight, highlightThickness, gridMarginTop, highlightThickness,
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
128 gridMarginBottom, highlightThickness, NULL);
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
129
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
130 // create drawing area
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
131 Dimension da_height = h - 2*highlightThickness - 2*shadowThickness;
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
132 n = 0;
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
133 XtSetArg(xargs[n], XmNheight, da_height); n++;
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
134 Widget drawingArea = XmCreateDrawingArea(frame, "progressbar_drawingarea", xargs, n);
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
135 XtManageChild(drawingArea);
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
136
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
137 UiVar* var = uic_widget_var(obj->ctx, obj->ctx, args.value, args.varname, UI_VAR_DOUBLE);
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
138
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
139 UiProgressBar *progressbarData = malloc(sizeof(UiProgressBar));
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
140 progressbarData->widget = drawingArea;
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
141 progressbarData->min = args.min;
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
142 progressbarData->max = args.max == 0 ? 100 : args.max;
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
143 progressbarData->value = 50;
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
144 progressbarData->var = var;
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
145 progressbarData->color = highlightColor;
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
146 progressbarData->gc = NULL; // initialize on first expose
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
147
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
148 if(var) {
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
149 UiDouble *d = var->value;
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
150 progressbarData->value = d->value;
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
151 d->obj = progressbarData;
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
152 d->get = ui_progressbar_get;
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
153 d->set = ui_progressbar_set;
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
154 }
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
155
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
156 XtAddCallback(
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
157 drawingArea,
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
158 XmNexposeCallback,
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
159 (XtCallbackProc)ui_progressbar_expose,
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
160 progressbarData);
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
161
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
162
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
163 XtManageChild(frame);
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
164 return frame;
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
165 }
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
166
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
167 double ui_progressbar_get(UiDouble *d) {
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
168 UiProgressBar *pb = d->obj;
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
169 d->value = pb->value;
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
170 return d->value;
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
171 }
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
172
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
173 void ui_progressbar_set(UiDouble *d, double value) {
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
174 UiProgressBar *pb = d->obj;
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
175 d->value = value;
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
176 pb->value = value;
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
177 ui_progressbar_expose(pb->widget, pb, NULL);
0921f8a5d535 implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 428
diff changeset
178 }

mercurial