Sat, 04 Jan 2025 16:30:06 +0100
add resize handler to 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); |
430
ea949c0109d8
add resize handler to progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
429
diff
changeset
|
87 | if(w == 0) { |
ea949c0109d8
add resize handler to progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
429
diff
changeset
|
88 | return; |
ea949c0109d8
add resize handler to progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
429
diff
changeset
|
89 | } |
429
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
90 | if(!pb->gc) { |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
91 | XGCValues gcvals; |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
92 | gcvals.foreground = pb->color; |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
93 | pb->gc = XCreateGC(dp, w, (GCForeground), &gcvals); |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
94 | } |
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 | Dimension width = widget->core.width; |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
97 | Dimension height = widget->core.height; |
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 | double value = (pb->value - pb->min) / (pb->max - pb->min); |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
100 | Dimension valueW = (double)width * value; |
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 | XClearArea(dp, w, 0, 0, width, height, False); |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
103 | 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
|
104 | } |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
105 | |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
106 | UIWIDGET ui_progressbar_create(UiObject *obj, UiProgressbarArgs args) { |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
107 | Arg xargs[16]; |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
108 | int n = 0; |
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 | UiContainerPrivate *ctn = ui_obj_container(obj); |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
111 | UI_APPLY_LAYOUT(ctn->layout, args); |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
112 | |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
113 | Widget parent = ctn->prepare(ctn, 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 | char *name = args.name ? (char*)args.name : "progressbar"; |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
116 | Widget frame = XmCreateFrame(parent, name, xargs, n); |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
117 | |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
118 | // 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
|
119 | // 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
|
120 | Widget test = XmCreatePushButton(frame, "button", NULL, 0); |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
121 | XtManageChild(test); |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
122 | Dimension h, highlightThickness, shadowThickness; |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
123 | Pixel highlightColor; |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
124 | XtVaGetValues(test, XmNheight, &h, XmNhighlightThickness, &highlightThickness, |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
125 | XmNshadowThickness, &shadowThickness, XmNhighlightColor, &highlightColor, NULL); |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
126 | XtDestroyWidget(test); |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
127 | |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
128 | // adjust frame |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
129 | XtVaSetValues(frame, XmNshadowThickness, shadowThickness, gridMarginLeft, highlightThickness, |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
130 | gridMarginRight, highlightThickness, gridMarginTop, highlightThickness, |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
131 | gridMarginBottom, highlightThickness, NULL); |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
132 | |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
133 | // create drawing area |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
134 | Dimension da_height = h - 2*highlightThickness - 2*shadowThickness; |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
135 | n = 0; |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
136 | XtSetArg(xargs[n], XmNheight, da_height); n++; |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
137 | Widget drawingArea = XmCreateDrawingArea(frame, "progressbar_drawingarea", xargs, n); |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
138 | XtManageChild(drawingArea); |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
139 | |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
140 | 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
|
141 | |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
142 | UiProgressBar *progressbarData = malloc(sizeof(UiProgressBar)); |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
143 | progressbarData->widget = drawingArea; |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
144 | progressbarData->min = args.min; |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
145 | progressbarData->max = args.max == 0 ? 100 : args.max; |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
146 | progressbarData->value = 50; |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
147 | progressbarData->var = var; |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
148 | progressbarData->color = highlightColor; |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
149 | progressbarData->gc = NULL; // initialize on first expose |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
150 | |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
151 | if(var) { |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
152 | UiDouble *d = var->value; |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
153 | progressbarData->value = d->value; |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
154 | d->obj = progressbarData; |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
155 | d->get = ui_progressbar_get; |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
156 | d->set = ui_progressbar_set; |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
157 | } |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
158 | |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
159 | XtAddCallback( |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
160 | drawingArea, |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
161 | XmNexposeCallback, |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
162 | (XtCallbackProc)ui_progressbar_expose, |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
163 | progressbarData); |
430
ea949c0109d8
add resize handler to progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
429
diff
changeset
|
164 | XtAddCallback( |
ea949c0109d8
add resize handler to progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
429
diff
changeset
|
165 | drawingArea, |
ea949c0109d8
add resize handler to progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
429
diff
changeset
|
166 | XmNresizeCallback, |
ea949c0109d8
add resize handler to progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
429
diff
changeset
|
167 | (XtCallbackProc)ui_progressbar_expose, |
ea949c0109d8
add resize handler to progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
429
diff
changeset
|
168 | progressbarData); |
429
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
169 | |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
170 | |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
171 | XtManageChild(frame); |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
172 | return frame; |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
173 | } |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
174 | |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
175 | double ui_progressbar_get(UiDouble *d) { |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
176 | UiProgressBar *pb = d->obj; |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
177 | d->value = pb->value; |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
178 | return d->value; |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
179 | } |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
180 | |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
181 | void ui_progressbar_set(UiDouble *d, double value) { |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
182 | UiProgressBar *pb = d->obj; |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
183 | d->value = value; |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
184 | pb->value = value; |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
185 | ui_progressbar_expose(pb->widget, pb, NULL); |
0921f8a5d535
implement progressbar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
428
diff
changeset
|
186 | } |