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