1 /*
2 * $Header: /cvsroot/lesstif/lesstif/test/Xm/list/test3.c,v 1.11 2002/05/01 15:54:45 amai Exp $
3 * More versatile test.
4 */
5
6 #include <stdlib.h>
7 #include <stdio.h>
8
9 #include <Xm/List.h>
10 #include <Xm/PushB.h>
11 #include <Xm/BulletinB.h>
12 #include <Xm/Xm.h>
13 #include <Xm/TextF.h>
14 #include <Xm/RowColumn.h>
15
16 #include "../../common/Test.h"
17
18 char *days[] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday",
19 "Friday", "Saturday" };
20
21 Widget list;
22
ShowSelect(Widget w,XtPointer client,XtPointer call)23 void ShowSelect(Widget w, XtPointer client, XtPointer call)
24 {
25 XmListCallbackStruct *cbp = (XmListCallbackStruct *)call;
26 char *s = (char *)client;
27 int i;
28
29 switch (cbp->reason)
30 {
31 case XmCR_SINGLE_SELECT:
32 fprintf(stderr, "ShowSelect(%s): #%d", s, 1);
33 fprintf(stderr, " %d", cbp->item_position);
34 fprintf(stderr, "\n");
35 break;
36 case XmCR_MULTIPLE_SELECT:
37 case XmCR_EXTENDED_SELECT:
38 fprintf(stderr, "ShowSelect(%s): #%d", s, cbp->selected_item_count);
39 for (i=0; i<cbp->selected_item_count; i++)
40 fprintf(stderr, " %d", cbp->selected_item_positions[i]);
41 fprintf(stderr, "\n");
42 break;
43 }
44 }
45
change_list(Widget w,XtPointer client,XtPointer call)46 void change_list(Widget w, XtPointer client, XtPointer call)
47 {
48 XtRemoveAllCallbacks(list, XmNsingleSelectionCallback);
49 XtRemoveAllCallbacks(list, XmNmultipleSelectionCallback);
50 XtRemoveAllCallbacks(list, XmNbrowseSelectionCallback);
51 XtRemoveAllCallbacks(list, XmNextendedSelectionCallback);
52
53 XtVaSetValues(list, XmNselectionPolicy, client, NULL);
54
55 XtAddCallback(list, XmNsingleSelectionCallback, ShowSelect, (XtPointer)"XmSINGLE_SELECT");
56 XtAddCallback(list, XmNmultipleSelectionCallback, ShowSelect, (XtPointer)"XmMULTIPLE_SELECT");
57 XtAddCallback(list, XmNbrowseSelectionCallback, ShowSelect, (XtPointer)"XmBROWSE_SELECT");
58 XtAddCallback(list, XmNextendedSelectionCallback, ShowSelect, (XtPointer)"XmEXTENDED_SELECT");
59 }
60
61 Widget tf;
62
position(Widget w,XtPointer client,XtPointer call)63 void position(Widget w, XtPointer client, XtPointer call)
64 {
65 char *s;
66 int n;
67
68 XtVaGetValues(tf, XmNvalue, &s, NULL);
69 n = atoi(s);
70 /*
71 XtFree(s);
72 */
73
74 XmListSelectPos(list, n, False);
75 }
76
deselect(Widget w,XtPointer client,XtPointer call)77 void deselect(Widget w, XtPointer client, XtPointer call)
78 {
79 XmListDeselectPos(list, -1);
80 }
81
replace(Widget w,XtPointer client,XtPointer call)82 void replace(Widget w, XtPointer client, XtPointer call)
83 {
84 XmString l[1];
85
86 l[0] = XmStringCreateSimple("Yow");
87
88 XmListReplaceItemsPos(list, l, 1, 3);
89 }
90
talk(Widget w,XtPointer client,XtPointer call)91 void talk(Widget w, XtPointer client, XtPointer call)
92 {
93 char *s = (char *)client;
94
95 fprintf(stderr, "Callback %s\n", s);
96 }
97
98 int
main(int argc,char ** argv)99 main(int argc, char **argv)
100 {
101 XtAppContext app;
102 Widget top, bb, w, pd, om, msb, pb;
103 XmStringTable str_days;
104 int i;
105 Arg al[10];
106 int ac;
107
108 top = XtVaAppInitialize(&app, "MULTIPLE", NULL, 0,
109 &argc, argv, NULL, NULL);
110
111 bb = XtVaCreateManagedWidget("bb", xmBulletinBoardWidgetClass, top,
112 NULL);
113
114 /* option menu */
115 pd = XmCreatePulldownMenu(bb, "pulldown", NULL, 0);
116 w = XtVaCreateManagedWidget("XmSINGLE_SELECT",
117 xmPushButtonWidgetClass, pd, NULL);
118 XtAddCallback(w, XmNactivateCallback, change_list, (XtPointer)XmSINGLE_SELECT);
119
120 w = XtVaCreateManagedWidget("XmBROWSE_SELECT",
121 xmPushButtonWidgetClass, pd, NULL);
122 XtAddCallback(w, XmNactivateCallback, change_list, (XtPointer)XmBROWSE_SELECT);
123
124 msb = XtVaCreateManagedWidget("XmMULTIPLE_SELECT",
125 xmPushButtonWidgetClass, pd, NULL);
126 XtAddCallback(w, XmNactivateCallback, change_list, (XtPointer)XmMULTIPLE_SELECT);
127
128 w = XtVaCreateManagedWidget("XmEXTENDED_SELECT",
129 xmPushButtonWidgetClass, pd, NULL);
130 XtAddCallback(w, XmNactivateCallback, change_list, (XtPointer)XmEXTENDED_SELECT);
131
132 ac = 0;
133 XtSetArg(al[ac], XmNsubMenuId, pd); ac++;
134 XtSetArg(al[ac], XmNmenuHistory, msb); ac++;
135 XtSetArg(al[ac], XmNx, 200); ac++;
136 XtSetArg(al[ac], XmNy, 10); ac++;
137 om = XmCreateOptionMenu(bb, "option", al, ac);
138 XtManageChild(om);
139
140 /* textfield */
141 tf = XtVaCreateManagedWidget("textfield", xmTextFieldWidgetClass, bb,
142 XmNx, 200,
143 XmNy, 100,
144 NULL);
145 XtAddCallback(tf, XmNactivateCallback, position, NULL);
146 XtAddCallback(tf, XmNfocusCallback, talk, XmNfocusCallback);
147 XtAddCallback(tf, XmNlosingFocusCallback, talk, XmNlosingFocusCallback);
148
149 pb = XtVaCreateManagedWidget("deselect", xmPushButtonWidgetClass, bb,
150 XmNx, 200,
151 XmNy, 150,
152 NULL);
153 XtAddCallback(pb, XmNactivateCallback, deselect, NULL);
154
155 pb = XtVaCreateManagedWidget("replace", xmPushButtonWidgetClass, bb,
156 XmNx, 120,
157 XmNy, 150,
158 NULL);
159 XtAddCallback(pb, XmNactivateCallback, replace, NULL);
160
161 /* list */
162 str_days = (XmStringTable) XtMalloc(7 * sizeof(XmString*));
163 for(i=0; i<7; ++i)
164 str_days[i] = XmStringCreateSimple(days[i]);
165
166 list = XtVaCreateManagedWidget( "test_of_list",
167 xmListWidgetClass, bb,
168 XmNselectionPolicy, XmMULTIPLE_SELECT,
169 XmNitemCount, 7,
170 XmNvisibleItemCount, 7,
171 XmNitems, str_days,
172 NULL );
173 XtAddCallback(list, XmNsingleSelectionCallback, ShowSelect, (XtPointer)"XmSINGLE_SELECT");
174 XtAddCallback(list, XmNmultipleSelectionCallback, ShowSelect, (XtPointer)"XmMULTIPLE_SELECT");
175 XtAddCallback(list, XmNbrowseSelectionCallback, ShowSelect, (XtPointer)"XmBROWSE_SELECT");
176 XtAddCallback(list, XmNextendedSelectionCallback, ShowSelect, (XtPointer)"XmEXTENDED_SELECT");
177
178 for(i=0; i<7; ++i)
179 XmStringFree(str_days[i]);
180 XtFree((XtPointer)str_days);
181
182 XtRealizeWidget(top);
183
184
185 {
186 static XtWidgetGeometry Expected[] = {
187 CWWidth | CWHeight , 56, 72, 363, 186, 0,0,0, /* bb */
188 CWWidth | CWHeight | CWX | CWY, 200, 10, 152, 35, 0,0,0, /* option */
189 CWWidth | CWHeight | CWX | CWY, 3, 3, 4, 29, 0,0,0, /* OptionLabel */
190 CWWidth | CWHeight | CWX | CWY, 10, 3, 139, 29, 0,0,0, /* OptionButton */
191 CWWidth | CWHeight | CWX | CWY, 200, 100, 138, 31, 0,0,0, /* textfield */
192 CWWidth | CWHeight | CWX | CWY, 200, 150, 60, 25, 0,0,0, /* deselect */
193 CWWidth | CWHeight | CWX | CWY, 120, 150, 54, 25, 0,0,0, /* replace */
194 CWWidth | CWHeight | CWX | CWY, 10, 10, 64, 119, 0,0,0, /* test_of_list */
195 };
196 /* toplevel should be replaced with to correct applicationShell */
197 PrintDetails(top, Expected);
198 }
199 LessTifTestMainLoop(top);
200
201 exit(0);
202 }
203