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/PushB.h>
52 #include <Xm/Form.h>
53 #include <XmL/Grid.h>
54
55 void cellSelect();
56 void showSelected();
57
58 #define HEADINGFONT "-*-helvetica-bold-o-*--*-100-*-*-*-*-iso8859-1"
59 #define CONTENTFONT "-*-helvetica-medium-r-*--*-100-*-*-*-*-iso8859-1"
60
61 #define check_width
9
62 #define check_height
9
63 static unsigned char check_bits[] = {
64 0x00, 0x01, 0x80, 0x01, 0xc0, 0x00, 0x61, 0x00, 0x37, 0x00, 0x3e, 0x00,
65 0x1c, 0x00, 0x08, 0x00, 0x00, 0x00};
66
67 #define nocheck_width
9
68 #define nocheck_height
9
69 static char nocheck_bits[] = {
70 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
71 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
72
73 static char *data[
20] =
74 {
75 "3|Bob Thompson|bobt@teledyne.com",
76 "12|Darl Simon|ds@atg.org",
77 "14|Jacq Frontier|jf@terrax.com",
78 "19|Patty Lee|patlee@isis.com",
79 "22|Michal Barnes|mickeyb@softorb.com",
80 "23|Dave Schultz|daves@timing.com",
81 "23|Eric Stanley|ericst@aldor.com",
82 "29|Tim Winters|timw@terra.com",
83 "31|Agin Tomitu|agt@umn.edu",
84 "33|Betty Tinner|bett@ost.edu",
85 "37|Tom Smith|tsmith@netwld.com",
86 "38|Rick Wild|raw@mlsoft.com",
87 "41|Al Joyce|aj@ulm.edu",
88 "41|Tim Burtan|timb@autoc.com",
89 "41|George Marlin|gjm@eyeln.com",
90 "41|Bill Boxer|billb@idesk.com",
91 "41|Maria Montez|marm@ohio.edu",
92 "41|Yin Fang|aj@utxs.edu",
93 "41|Suzy Saps|ss@umg.edu",
94 "41|Jerry Rodgers|jr@lyra.com",
95 };
96
97 Pixmap nocheckPix, checkPix;
98 Widget grid;
99
100 main(argc, argv)
101 int argc;
102 char *argv[];
103 {
104 XtAppContext app;
105 Widget shell, form, button;
106 Pixel blackPixel, whitePixel;
107 Pixmap pix;
108 int i;
109
110 shell = XtAppInitialize(&app,
"Grid4",
NULL,
0,
111 &argc, argv,
NULL,
NULL,
0);
112
113
114 blackPixel = BlackPixelOfScreen(XtScreen(shell));
115 whitePixel = WhitePixelOfScreen(XtScreen(shell));
116 checkPix = XCreatePixmapFromBitmapData(XtDisplay(shell),
117 DefaultRootWindow(XtDisplay(shell)),
118 check_bits, check_width, check_height,
119 blackPixel, whitePixel,
120 DefaultDepthOfScreen(XtScreen(shell)));
121 nocheckPix = XCreatePixmapFromBitmapData(XtDisplay(shell),
122 DefaultRootWindow(XtDisplay(shell)),
123 nocheck_bits, nocheck_width, nocheck_height,
124 blackPixel, whitePixel,
125 DefaultDepthOfScreen(XtScreen(shell)));
126
127 form = XtVaCreateManagedWidget(
"form",
128 xmFormWidgetClass, shell,
129 XtVaTypedArg, XmNbackground, XmRString,
"#C0C0C0",
8,
130 XmNshadowThickness,
0,
131 NULL);
132
133 button = XtVaCreateManagedWidget(
"Show Selected",
134 xmPushButtonWidgetClass, form,
135 XtVaTypedArg, XmNbackground, XmRString,
"#C0C0C0",
8,
136 XtVaTypedArg, XmNforeground, XmRString,
"black",
6,
137 XmNbottomAttachment, XmATTACH_FORM,
138 XmNleftAttachment, XmATTACH_FORM,
139 NULL);
140 XtAddCallback(button, XmNactivateCallback, showSelected,
NULL);
141
142
143
144 grid = XtVaCreateManagedWidget(
"grid",
145 xmlGridWidgetClass, form,
146 XtVaTypedArg, XmNbackground, XmRString,
"#C0C0C0",
8,
147 XtVaTypedArg, XmNforeground, XmRString,
"black",
6,
148 XtVaTypedArg, XmNfontList, XmRString,
CONTENTFONT,
149 strlen(
CONTENTFONT) +
1,
150 XmNcolumns,
4,
151 XmNsimpleWidths,
"3c 4c 17c 20c",
152 XmNhorizontalSizePolicy, XmVARIABLE,
153 XmNvsbDisplayPolicy, XmSTATIC,
154 XmNvisibleRows,
13,
155 XmNselectionPolicy, XmSELECT_NONE,
156 XmNhighlightRowMode, True,
157 XmNshadowType, XmSHADOW_ETCHED_IN,
158 XmNtopAttachment, XmATTACH_FORM,
159 XmNleftAttachment, XmATTACH_FORM,
160 XmNrightAttachment, XmATTACH_FORM,
161 XmNbottomAttachment, XmATTACH_WIDGET,
162 XmNbottomWidget, button,
163 NULL);
164 XtAddCallback(grid, XmNselectCallback, cellSelect,
NULL);
165
166
167
168
169 XtVaSetValues(grid,
170 XmNlayoutFrozen, True,
171 NULL);
172
173
174
175 XtVaSetValues(grid,
176 XmNcellDefaults, True,
177 XtVaTypedArg, XmNcellFontList, XmRString,
HEADINGFONT,
178 strlen(
HEADINGFONT) +
1,
179 XtVaTypedArg, XmNcellBackground, XmRString,
"#000080",
8,
180 XtVaTypedArg, XmNcellForeground, XmRString,
"white",
6,
181 XmNcellLeftBorderType, XmBORDER_NONE,
182 XmNcellRightBorderType, XmBORDER_NONE,
183 XmNcellTopBorderType, XmBORDER_NONE,
184 XmNcellBottomBorderType, XmBORDER_NONE,
185 NULL);
186 XtVaSetValues(grid,
187 XmNcellDefaults, True,
188 XmNcolumn,
1,
189 XmNcellAlignment, XmALIGNMENT_RIGHT,
190 NULL);
191 XtVaSetValues(grid,
192 XmNcellDefaults, True,
193 XmNcolumnRangeStart,
2,
194 XmNcolumnRangeEnd,
3,
195 XmNcellAlignment, XmALIGNMENT_LEFT,
196 NULL);
197 XmLGridAddRows(grid, XmHEADING, -
1,
1);
198
199
200 XmLGridSetStrings(grid,
"OD|Qty|Name|EMail Addr");
201
202
203
204 XtVaSetValues(grid,
205 XmNcellDefaults, True,
206 XtVaTypedArg, XmNcellFontList, XmRString,
CONTENTFONT,
207 strlen(
CONTENTFONT) +
1,
208 XtVaTypedArg, XmNcellBackground, XmRString,
"white",
6,
209 XtVaTypedArg, XmNcellForeground, XmRString,
"black",
6,
210 XmNcellBottomBorderType, XmBORDER_LINE,
211 XtVaTypedArg, XmNcellBottomBorderColor, XmRString,
"black",
6,
212 NULL);
213 XtVaSetValues(grid,
214 XmNcellDefaults, True,
215 XmNcolumn,
0,
216 XmNcellType, XmPIXMAP_CELL,
217 NULL);
218 XmLGridAddRows(grid, XmCONTENT, -
1,
20);
219
220
221 for (i =
0; i <
20; i++)
222 {
223 XmLGridSetStringsPos(grid, XmCONTENT, i, XmCONTENT,
1, data[i]);
224 if (i ==
2 || i ==
4 || i ==
5 || i ==
8 || i ==
13)
225 pix = checkPix;
226 else
227 pix = nocheckPix;
228 XtVaSetValues(grid,
229 XmNcolumn,
0,
230 XmNrow, i,
231 XmNcellPixmap, pix,
232 NULL);
233 }
234
235 XtVaSetValues(grid,
236 XmNlayoutFrozen, False,
237 NULL);
238
239 XtRealizeWidget(shell);
240 XtAppMainLoop(app);
241 }
242
243 void showSelected(w, clientData, callData)
244 Widget w;
245 XtPointer clientData;
246 XtPointer callData;
247 {
248 XmLGridRow row;
249 XmLGridColumn column;
250 Pixmap pix;
251 int i, n;
252
253
254
255 printf (
"Selected Rows: ");
256 XtVaGetValues(grid,
257 XmNrows, &n,
258 NULL);
259 for (i =
0; i < n; i++)
260 {
261 row = XmLGridGetRow(grid, XmCONTENT, i);
262 column = XmLGridGetColumn(grid, XmCONTENT,
0);
263 XtVaGetValues(grid,
264 XmNrowPtr, row,
265 XmNcolumnPtr, column,
266 XmNcellPixmap, &pix,
267 NULL);
268 if (pix == checkPix)
269 printf (
"%d ", i);
270 }
271 printf (
"\n");
272 }
273
274 void cellSelect(w, clientData, callData)
275 Widget w;
276 XtPointer clientData;
277 XtPointer callData;
278 {
279 XmLGridCallbackStruct *cbs;
280 XmLGridRow row;
281 XmLGridColumn column;
282 Pixmap pix;
283
284 cbs = (XmLGridCallbackStruct *)callData;
285 if (cbs->reason != XmCR_SELECT_CELL)
286 return;
287 if (cbs->rowType != XmCONTENT)
288 return;
289
290
291 row = XmLGridGetRow(w, cbs->rowType, cbs->row);
292 column = XmLGridGetColumn(w, XmCONTENT,
0);
293 XtVaGetValues(w,
294 XmNrowPtr, row,
295 XmNcolumnPtr, column,
296 XmNcellPixmap, &pix,
297 NULL);
298 if (pix == nocheckPix)
299 pix = checkPix;
300 else
301 pix = nocheckPix;
302 XtVaSetValues(w,
303 XmNrow, cbs->row,
304 XmNcolumn,
0,
305 XmNcellPixmap, pix,
306 NULL);
307 }
308