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 <XmL/Tree.h>
52
53 main(argc, argv)
54 int argc;
55 char *argv[];
56 {
57 XtAppContext app;
58 Widget shell, tree;
59 int i, n, size;
60 XmString str;
61 XmLTreeRowDefinition *rows;
62 static struct
63 {
64 Boolean expands;
65 int level;
66 char *string;
67 } data[] =
68 {
69 { True,
0,
"Root" },
70 { True,
1,
"Level 1 Parent" },
71 { False,
2,
"1st Child of Level 1 Parent" },
72 { False,
2,
"2nd Child of Level 1 Parent" },
73 { True,
2,
"Level 2 Parent" },
74 { False,
3,
"Child of Level 2 Parent" },
75 { True,
1,
"Level 1 Parent" },
76 { False,
2,
"Child of Level 1 Parent" },
77 };
78
79 shell = XtAppInitialize(&app,
"Tree2",
NULL,
0,
80 &argc, argv,
NULL,
NULL,
0);
81
82 tree = XtVaCreateManagedWidget(
"tree",
83 xmlTreeWidgetClass, shell,
84 XtVaTypedArg, XmNbackground, XmRString,
"#C0C0C0",
6,
85 XtVaTypedArg, XmNforeground, XmRString,
"black",
6,
86 XtVaTypedArg, XmNblankBackground, XmRString,
"white",
6,
87 XtVaTypedArg, XmNselectBackground, XmRString,
"#000080",
8,
88 XtVaTypedArg, XmNselectForeground, XmRString,
"white",
6,
89 XtVaTypedArg, XmNconnectingLineColor, XmRString,
"#808080",
8,
90 XmNvisibleRows,
10,
91 XmNwidth,
250,
92 NULL);
93 XtVaSetValues(tree,
94 XmNcellDefaults, True,
95 XtVaTypedArg, XmNcellBackground, XmRString,
"white",
6,
96 NULL);
97
98
99
100 n =
8;
101 size =
sizeof(XmLTreeRowDefinition) * n;
102 rows = (XmLTreeRowDefinition *)malloc(size);
103 for (i =
0; i < n; i++)
104 {
105 rows[i].level = data[i].level;
106 rows[i].expands = data[i].expands;
107 rows[i].isExpanded = True;
108 rows[i].pixmap = XmUNSPECIFIED_PIXMAP;
109 rows[i].pixmask = XmUNSPECIFIED_PIXMAP;
110 rows[i].string = XmStringCreateSimple(data[i].string);
111 }
112 XmLTreeAddRows(tree, rows, n, -
1);
113
114
115 for (i =
0; i < n; i++)
116 XmStringFree(rows[i].string);
117 free((
char *)rows);
118
119 XtRealizeWidget(shell);
120 XtAppMainLoop(app);
121 }
122