1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50 #include <Xm/Xm.h>
51 #include <Xm/Form.h>
52 #include <Xm/PushB.h>
53 #include <XmL/Tree.h>
54
55 #define sphere_width
16
56 #define sphere_height
16
57 static unsigned char sphere_bits[] = {
58 0x00, 0x00, 0x00, 0x00, 0xc0, 0x07, 0xe0, 0x0f, 0xf0, 0x1f, 0x38, 0x3f,
59 0xb8, 0x3f, 0xf8, 0x3f, 0xf8, 0x3f, 0xf8, 0x3f, 0xf0, 0x1f, 0xe0, 0x0f,
60 0xc0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
61 #define monitor_width
16
62 #define monitor_height
16
63 static unsigned char monitor_bits[] = {
64 0x00, 0x00, 0xf8, 0x3f, 0xf8, 0x3f, 0x18, 0x30, 0x58, 0x37, 0x18, 0x30,
65 0x58, 0x37, 0x18, 0x30, 0xf8, 0x3f, 0xf8, 0x3f, 0x80, 0x03, 0x80, 0x03,
66 0xf0, 0x1f, 0xf0, 0x1f, 0x00, 0x00, 0x00, 0x00};
67
68 #if 0
69 void
70 hide_cb(Widget w, XtPointer clientData, XtPointer cb_data)
71 {
72 Widget tree = (Widget) clientData;
73
74 XmLGridHideRightColumn(tree);
75 }
76 void
77 show_cb(Widget w, XtPointer clientData, XtPointer cb_data)
78 {
79 Widget tree = (Widget) clientData;
80
81 XmLGridUnhideRightColumn(tree);
82 }
83 #endif
84
85
86 main(argc, argv)
87 int argc;
88 char *argv[];
89 {
90 XtAppContext app;
91 Widget shell, tree, form, hideB, showB;
92 XmLTreeRowDefinition *rows;
93 Pixmap monitorPixmap, spherePixmap;
94 Pixel black, white;
95 int i, n, size;
96 static struct
97 {
98 Boolean expands;
99 int level;
100 char *string;
101 } data[] =
102 {
103 { True,
0,
"Root" },
104 { True,
1,
"Parent A" },
105 { False,
2,
"Node A1" },
106 { False,
2,
"Node A2" },
107 { True,
2,
"Parent B" },
108 { False,
3,
"Node B1" },
109 { False,
3,
"Node B2" },
110 { True,
1,
"Parent C" },
111 { False,
2,
"Node C1" },
112 { True,
1,
"Parent D" },
113 { False,
2,
"Node D1" },
114 };
115
116 shell = XtAppInitialize(&app,
"Tree3",
NULL,
0,
117 &argc, argv,
NULL,
NULL,
0);
118
119 black = BlackPixelOfScreen(XtScreen(shell));
120 white = WhitePixelOfScreen(XtScreen(shell));
121 spherePixmap = XCreatePixmapFromBitmapData(XtDisplay(shell),
122 DefaultRootWindow(XtDisplay(shell)),
123 sphere_bits, sphere_width, sphere_height,
124 black, white,
125 DefaultDepthOfScreen(XtScreen(shell)));
126 monitorPixmap = XCreatePixmapFromBitmapData(XtDisplay(shell),
127 DefaultRootWindow(XtDisplay(shell)),
128 monitor_bits, monitor_width, monitor_height,
129 black, white,
130 DefaultDepthOfScreen(XtScreen(shell)));
131
132 form = XtVaCreateManagedWidget(
"form",
133 xmFormWidgetClass, shell,
134 XtVaTypedArg, XmNbackground, XmRString,
"#C0C0C0",
8,
135 XmNshadowThickness,
0,
136 NULL);
137
138 #if 0
139 hideB = XtVaCreateManagedWidget(
"hide",
140 xmPushButtonWidgetClass, form,
141 XmNleftAttachment, XmATTACH_NONE,
142 XmNtopAttachment, XmATTACH_POSITION,
143 XmNtopPosition,
30,
144 XmNbottomAttachment, XmATTACH_NONE,
145 XmNrightAttachment, XmATTACH_FORM,
146 NULL);
147
148 showB = XtVaCreateManagedWidget(
"show",
149 xmPushButtonWidgetClass, form,
150 XmNleftAttachment, XmATTACH_NONE,
151 XmNtopAttachment, XmATTACH_POSITION,
152 XmNtopPosition,
30,
153 XmNbottomAttachment, XmATTACH_NONE,
154 XmNrightAttachment, XmATTACH_WIDGET,
155 XmNrightWidget, hideB,
156 NULL);
157 #endif
158
159
160
161
162
163 tree = XtVaCreateManagedWidget(
"tree",
164 xmlTreeWidgetClass, form,
165 XtVaTypedArg, XmNbackground, XmRString,
"#C0C0C0",
8,
166 XtVaTypedArg, XmNforeground, XmRString,
"black",
6,
167 XtVaTypedArg, XmNblankBackground, XmRString,
"white",
6,
168 XtVaTypedArg, XmNselectBackground, XmRString,
"#000080",
8,
169 XtVaTypedArg, XmNselectForeground, XmRString,
"white",
6,
170 XtVaTypedArg, XmNconnectingLineColor, XmRString,
"#808080",
8,
171 XmNhorizontalSizePolicy, XmRESIZE_IF_POSSIBLE,
172 XmNallowColumnResize, True,
173 XmNheadingRows,
1,
174 XmNvisibleRows,
14,
175 XmNcolumns,
3,
176 XmNvisibleColumns,
1,
177 XmNhideUnhideButtons, True,
178 XmNsimpleWidths,
"80c 40c 40c",
179 XmNsimpleHeadings,
"All Folders|SIZE|DATA2",
180 XmNselectionPolicy, XmSELECT_MULTIPLE_ROW,
181 XmNhighlightRowMode, True,
182 XmNglobalPixmapWidth,
16,
183 XmNglobalPixmapHeight,
16,
184 XmNleftAttachment, XmATTACH_FORM,
185 XmNtopAttachment, XmATTACH_FORM,
186 XmNbottomAttachment, XmATTACH_FORM,
187 XmNrightAttachment, XmATTACH_FORM,
188 #if 0
189 XmNrightAttachment, XmATTACH_WIDGET,
190 XmNrightWidget, showB,
191 #endif
192 XmNdebugLevel,
2,
193 NULL);
194
195
196 XtVaSetValues(tree,
197 XmNcellDefaults, True,
198 XtVaTypedArg, XmNcellBackground, XmRString,
"white",
6,
199 XmNcellEditable, True,
200 XmNcellLeftBorderType, XmBORDER_NONE,
201 XmNcellRightBorderType, XmBORDER_NONE,
202 XmNcellTopBorderType, XmBORDER_NONE,
203 XmNcellBottomBorderType, XmBORDER_NONE,
204 NULL);
205
206 #if 0
207 XtAddCallback(hideB, XmNactivateCallback, hide_cb, (XtPointer)tree);
208 XtAddCallback(showB, XmNactivateCallback, show_cb, (XtPointer)tree);
209 #endif
210
211
212
213 n =
11;
214 size =
sizeof(XmLTreeRowDefinition) * n;
215 rows = (XmLTreeRowDefinition *)malloc(size);
216 for (i =
0; i < n; i++)
217 {
218 rows[i].level = data[i].level;
219 rows[i].expands = data[i].expands;
220 rows[i].isExpanded = True;
221 if (data[i].expands)
222 rows[i].pixmap = spherePixmap;
223 else
224 rows[i].pixmap = monitorPixmap;
225 rows[i].pixmask = XmUNSPECIFIED_PIXMAP;
226 rows[i].string = XmStringCreateSimple(data[i].string);
227 }
228 XmLTreeAddRows(tree, rows, n, -
1);
229
230
231
232 for (i =
0; i < n; i++)
233 {
234 XmStringFree(rows[i].string);
235 XmLGridSetStringsPos(tree, XmCONTENT, i, XmCONTENT,
1,
"1032|1123");
236 }
237 free((
char *)rows);
238 XtRealizeWidget(shell);
239 XtAppMainLoop(app);
240 }
241