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/Grid.h>
54
55 void showSelected();
56
57 static char *data =
58 "Country|Media|Price\n\
59 Europe|CD-ROM|$29\n\
60 Yugoslovia|Floppy|$39\n\
61 North America|Tape|$29\n\
62 South America|CD-ROM|$49\n\
63 Japan|Tape|$49\n\
64 Russia|Floppy|$49\n\
65 Poland|CD-ROM|$39\n\
66 Norway|CD-ROM|$29\n\
67 England|Tape|$49\n\
68 Jordan|CD-ROM|$39";
69
70 Widget grid;
71
72 main(argc, argv)
73 int argc;
74 char *argv[];
75 {
76 XtAppContext app;
77 Widget shell, form, button;
78 XmString str;
79
80 shell = XtAppInitialize(&app,
"Grid2",
NULL,
0,
81 &argc, argv,
NULL,
NULL,
0);
82
83 form = XtVaCreateManagedWidget(
"form",
84 xmFormWidgetClass, shell,
85 XtVaTypedArg, XmNbackground, XmRString,
"#C0C0C0",
8,
86 XmNmarginWidth,
5,
87 XmNmarginHeight,
5,
88 XmNverticalSpacing,
5,
89 XmNshadowThickness,
0,
90 NULL);
91
92 str = XmStringCreateSimple(
"Print Selected");
93 button = XtVaCreateManagedWidget(
"button",
94 xmPushButtonWidgetClass, form,
95 XtVaTypedArg, XmNbackground, XmRString,
"#C0C0C0",
8,
96 XtVaTypedArg, XmNforeground, XmRString,
"black",
6,
97 XmNbottomAttachment, XmATTACH_FORM,
98 XmNrightAttachment, XmATTACH_FORM,
99 XmNlabelString, str,
100 NULL);
101 XmStringFree(str);
102 XtAddCallback(button, XmNactivateCallback, showSelected,
NULL);
103
104
105
106 grid = XtVaCreateManagedWidget(
"grid",
107 xmlGridWidgetClass, form,
108 XtVaTypedArg, XmNbackground, XmRString,
"#C0C0C0",
8,
109 XtVaTypedArg, XmNforeground, XmRString,
"black",
6,
110 XtVaTypedArg, XmNselectBackground, XmRString,
"#000080",
8,
111 XtVaTypedArg, XmNselectForeground, XmRString,
"white",
6,
112 XtVaTypedArg, XmNblankBackground, XmRString,
"white",
6,
113 XmNheadingRows,
1,
114 XmNvisibleRows,
7,
115 XmNcolumns,
3,
116 XmNsimpleWidths,
"20c 10c 10c",
117 XmNhorizontalSizePolicy, XmVARIABLE,
118 XmNvsbDisplayPolicy, XmSTATIC,
119 XmNhighlightRowMode, True,
120 XmNselectionPolicy, XmSELECT_MULTIPLE_ROW,
121 XmNshadowThickness,
0,
122 XmNtopAttachment, XmATTACH_FORM,
123 XmNbottomAttachment, XmATTACH_WIDGET,
124 XmNbottomWidget, button,
125 XmNleftAttachment, XmATTACH_FORM,
126 XmNrightAttachment, XmATTACH_FORM,
127 NULL);
128
129
130 XtVaSetValues(grid,
131 XmNcellDefaults, True,
132 XtVaTypedArg, XmNcellBackground, XmRString,
"white",
6,
133 XmNcellLeftBorderType, XmBORDER_NONE,
134 XmNcellRightBorderType, XmBORDER_NONE,
135 XmNcellTopBorderType, XmBORDER_NONE,
136 XmNcellBottomBorderType, XmBORDER_NONE,
137 NULL);
138
139 XtVaSetValues(grid,
140 XmNcellDefaults, True,
141 XmNcolumnRangeStart,
0,
142 XmNcolumnRangeEnd,
1,
143 XmNcellAlignment, XmALIGNMENT_LEFT,
144 NULL);
145
146 XtVaSetValues(grid,
147 XmNcellDefaults, True,
148 XmNcolumn,
2,
149 XmNcellAlignment, XmALIGNMENT_RIGHT,
150 NULL);
151
152 XtVaSetValues(grid,
153 XmNrows,
10,
154 NULL);
155 XmLGridSetStrings(grid, data);
156
157 XtRealizeWidget(shell);
158
159 XtAppMainLoop(app);
160 }
161
162 void showSelected(w, clientData, callData)
163 Widget w;
164 XtPointer clientData;
165 XtPointer callData;
166 {
167 int i, count, *pos;
168
169 printf (
"Selected Rows: ");
170 count = XmLGridGetSelectedRowCount(grid);
171 if (count)
172 {
173 pos = (
int *)malloc(
sizeof(
int) * count);
174 XmLGridGetSelectedRows(grid, pos, count);
175 for (i =
0; i < count; i++)
176 printf (
"%d ", pos[i]);
177 free((
char *)pos);
178 }
179 else
180 printf (
"none");
181 printf (
"\n");
182 }
183