1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <Xm/PushB.h>
4 #include <Xm/SelectioB.h>
5 #include <Xm/Text.h>
6
7 #define XMS(s) XmStringCreateSimple ( s );
8 #define XMG(s,c) XmStringGetLtoR( s, XmSTRING_DEFAULT_CHARSET, &c );
9
10 static void selectionBox ();
11 static void okCB();
12 static void applyCB();
13 static void erCB();
14
main(int argc,char ** argv)15 int main ( int argc, char **argv )
16 {
17 XtAppContext appShell;
18 Widget TheApp;
19 Widget push;
20
21 TheApp = XtAppInitialize ( &appShell, "TEST",
22 NULL, 0, &argc, argv, NULL, NULL, 0 );
23
24 push = XmCreatePushButton ( TheApp, "PushMe", NULL, 0 );
25 XtManageChild (push);
26
27 XtAddCallback ( push, XmNactivateCallback, selectionBox, NULL );
28
29 XtRealizeWidget (TheApp);
30
31
32
33 {
34 static XtWidgetGeometry Expected[] = {
35 CWWidth | CWHeight , 50, 50, 48, 25, 0,0,0, /* PushMe */
36 };
37 PrintDetails(TheApp,Expected);
38 };
39 LessTifTestMainLoop(TheApp);
40
41 exit(0);
42 }
43
selectionBox(Widget w,XtPointer client,XtPointer call_data)44 static void selectionBox ( Widget w, XtPointer client, XtPointer call_data )
45 {
46 int n;
47 Arg args[10];
48 Widget db;
49 XmString str[3];
50
51 str[0] = XMS("I'm a choice");
52 str[1] = XMS("I'm better");
53 str[2] = XMS("I'm the best");
54
55 db = XmCreateSelectionDialog ( w, "TheDB", NULL, 0 );
56
57 n=0;
58 XtSetArg ( args[n], XmNdeleteResponse, XmDESTROY ); n++;
59 XtSetArg ( args[n], XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL ); n++;
60 XtSetArg ( args[n], XmNmustMatch, TRUE ); n++;
61 XtSetArg ( args[n], XmNlistItems, str ); n++;
62 XtSetArg ( args[n], XmNlistItemCount, 3 ); n++;
63 XtSetValues ( db, args, n );
64
65 XmStringFree ( str[0] );
66 XmStringFree ( str[1] );
67 XmStringFree ( str[2] );
68
69 XtAddCallback ( db, XmNokCallback, okCB, NULL );
70 XtAddCallback ( db, XmNapplyCallback, applyCB, NULL );
71 XtAddCallback ( db, XmNnoMatchCallback, erCB, NULL );
72 XtSetSensitive( XmSelectionBoxGetChild(db, XmDIALOG_HELP_BUTTON),FALSE);
73
74 XtManageChild (db);
75 }
76
okCB(Widget w,XtPointer c,XmSelectionBoxCallbackStruct * cbs)77 static void okCB ( Widget w, XtPointer c, XmSelectionBoxCallbackStruct *cbs )
78 {
79 char *search=NULL;
80
81 if ( cbs->value )
82 XMG ( cbs->value, search );
83
84 (void) fprintf ( stderr, "okCB: value:\t\"%s\"\n", cbs->value );
85 (void) fprintf ( stderr, "okCB: search:\t\"%s\"\n", search );
86 }
87
applyCB(Widget w,XtPointer c,XmSelectionBoxCallbackStruct * cbs)88 static void applyCB ( Widget w, XtPointer c, XmSelectionBoxCallbackStruct *cbs )
89 {
90 char *search=NULL;
91
92 if ( cbs->value )
93 XMG ( cbs->value, search );
94
95 (void) fprintf ( stderr, "applyCB: value:\t\"%s\"\n", cbs->value );
96 (void) fprintf ( stderr, "applyCB: search:\t\"%s\"\n", search );
97 }
98
99 #include <Xm/MessageB.h>
100
erCB(w,client,call_data)101 static void erCB ( w, client, call_data )
102 Widget w;
103 XtPointer client;
104 XmSelectionBoxCallbackStruct *call_data;
105 {
106 Widget db;
107 Arg args[10];
108 int n;
109 XmString msg;
110 char *value;
111 char temp[256];
112
113 XMG ( call_data->value, value );
114
115 sprintf ( temp, "\"%s\"", value );
116 XtFree(value);
117
118 msg = XMS (temp);
119
120 n=0;
121 XtSetArg ( args[n], XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL); n++;
122 XtSetArg ( args[n], XmNdeleteResponse, XmDESTROY ); n++;
123 XtSetArg ( args[n], XmNmessageString, msg ); n++;
124
125 db = XmCreateErrorDialog ( XtParent(XtParent(w)), "BadSelection", args, n );
126 XtSetSensitive( XmMessageBoxGetChild (db,XmDIALOG_CANCEL_BUTTON),FALSE);
127 XtSetSensitive( XmMessageBoxGetChild (db,XmDIALOG_HELP_BUTTON), FALSE);
128
129 XmStringFree(msg);
130 XBell(XtDisplay(db), 0 );
131 XtManageChild ( db );
132
133 }
134
135