1 /*
2 $Header: /cvsroot/lesstif/lesstif/test/Xm/list/test9.c,v 1.6 2002/05/01 15:54:45 amai Exp $
3
4 Same as scrolledwindow/test14.c except it shows the sizing
5 DEFECT was in the List widget not the ScrolledWindow widget.
6 */
7
8
9 #include <stdlib.h>
10 #include <stdio.h>
11
12 #include <Xm/ListP.h>
13
14 #include "../../common/Test.h"
15
16 char *days[] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday",
17 "Friday", "Saturday" };
18
output_list_cbs(Widget w,XtPointer client_data,XtPointer call_data)19 void output_list_cbs(Widget w, XtPointer client_data, XtPointer call_data)
20 {
21 XmListCallbackStruct *cbs = (XmListCallbackStruct *)call_data;
22 String buf;
23
24 switch (cbs->reason)
25 {
26 case XmCR_DEFAULT_ACTION:
27 printf ("Default Action Callback\n");
28 /* the only valid items are:
29 reason
30 item
31 item_length
32 item_position
33 event
34 */
35 XmStringGetLtoR(cbs->item, XmFONTLIST_DEFAULT_TAG, &buf);
36 printf (" Item : %s\n", buf);
37 printf (" Item Position: %d\n", cbs->item_position);
38 printf (" Item Length : %d\n", cbs->item_length);
39
40 break;
41 case XmCR_BROWSE_SELECT:
42 printf ("Browse Select Callback\n");
43 /* the only valid items are:
44 reason
45 item
46 item_length
47 item_position
48 event
49 */
50 XmStringGetLtoR(cbs->item, XmFONTLIST_DEFAULT_TAG, &buf);
51 printf (" Item : %s\n", buf);
52 printf (" Item Position: %d\n", cbs->item_position);
53 printf (" Item Length : %d\n", cbs->item_length);
54 break;
55 case XmCR_SINGLE_SELECT:
56 printf ("Single Select Callback\n");
57 /* the only valid items are:
58 reason
59 item
60 item_length
61 item_position
62 event
63 */
64 XmStringGetLtoR(cbs->item, XmFONTLIST_DEFAULT_TAG, &buf);
65 printf (" Item : %s\n", buf);
66 printf (" Item Position: %d\n", cbs->item_position);
67 printf (" Item Length : %d\n", cbs->item_length);
68 break;
69 case XmCR_MULTIPLE_SELECT:
70 printf ("Multiple Select Callback\n");
71 break;
72 case XmCR_EXTENDED_SELECT:
73 printf ("Extended Select Callback\n");
74 break;
75 }
76 }
77
78 int
main(int argc,char ** argv)79 main(int argc, char **argv)
80 {
81 XtAppContext app;
82 Widget toplevel, listw;
83 XmStringTable str_days;
84 int i;
85 Arg al[3];
86 int ac = 0;
87
88 toplevel = XtVaAppInitialize(&app, "BROWSE", NULL, 0,
89 &argc, argv, NULL, NULL);
90
91 str_days = (XmStringTable) XtMalloc(7 * sizeof(XmString*));
92 for(i=0; i<7; ++i)
93 str_days[i] = XmStringCreateSimple(days[i]);
94
95
96 XtSetArg(al[ac], XmNselectionPolicy, XmBROWSE_SELECT); ac++;
97 XtSetArg(al[ac], XmNitemCount, 7); ac++;
98 XtSetArg(al[ac], XmNitems, str_days); ac++;
99
100 listw = XmCreateList( toplevel, "list", al, ac);
101 XtManageChild(listw);
102
103 XtAddCallback(listw, XmNdefaultActionCallback, output_list_cbs, NULL);
104 XtAddCallback(listw, XmNbrowseSelectionCallback, output_list_cbs, NULL);
105 XtAddCallback(listw, XmNbrowseSelectionCallback, XdbPrintTreeCB, toplevel);
106
107 for(i=0; i<7; ++i)
108 XmStringFree(str_days[i]);
109 XtFree((XtPointer)str_days);
110
111 XtRealizeWidget(toplevel);
112
113 XdbPrintTree(toplevel);
114
115
116 {
117 static XtWidgetGeometry Expected[] = {
118 CWWidth | CWHeight , 57, 73, 64, 23, 0,0,0, /* list */
119 };
120 /* toplevel should be replaced with to correct applicationShell */
121 PrintDetails(toplevel, Expected);
122 }
123 LessTifTestMainLoop(toplevel);
124
125 exit(0);
126 }
127