1 /*
2 * * Generated by X-Designer
3 */
4 /*
5 * *LIBS: -lXm -lXt -lX11
6 */
7
8 #include <X11/Xatom.h>
9 #include <X11/Intrinsic.h>
10 #include <X11/Shell.h>
11
12 #include <Xm/Xm.h>
13 #include <Xm/DialogS.h>
14 #include <Xm/Form.h>
15 #include <Xm/List.h>
16 #include <Xm/ScrollBar.h>
17 #include <Xm/AtomMgr.h>
18 #include <Xm/XmP.h>
19 #include <X11/Xmu/StdSel.h>
20 #include <X11/Xfuncs.h>
21 #include <stdio.h>
22
23 extern void select_callback();
24 Widget appshell = (Widget) NULL;
25
26 Boolean convert_proc();
27 void lose_proc();
28
29 void
select_callback(w,client_data,cd)30 select_callback(w, client_data, cd)
31 Widget w;
32 XtPointer client_data;
33 XtPointer cd;
34 {
35 XmListCallbackStruct *call_data = (XmListCallbackStruct *) cd;
36 if (call_data->selected_item_count)
37 XtOwnSelection(w, XA_PRIMARY, call_data->event->xbutton.time,
38 convert_proc, lose_proc, NULL);
39 else
40 XtDisownSelection(w, XA_PRIMARY,
41 call_data->event->xbutton.time);
42 }
43
44 Boolean
convert_proc(w,selection,target,type_return,value,length,format)45 convert_proc(w, selection, target, type_return, value, length, format)
46 Widget w;
47 Atom *selection, *target, *type_return;
48 XtPointer *value;
49 unsigned long *length;
50 int *format;
51 {
52 Atom COMPOUND_TEXT = XmInternAtom(XtDisplay(w),
53 "COMPOUND_TEXT", False);
54 Atom TARGETS = XmInternAtom(XtDisplay(w), "TARGETS", False);
55 XSelectionRequestEvent *request = XtGetSelectionRequest(w,
56 *selection, (XtRequestId) NULL);
57 if (*target == TARGETS) {
58 Atom *targets;
59 Atom *std_targets;
60 unsigned long std_length;
61 /* Get standard list of targets */
62 XmuConvertStandardSelection(w, request->time, selection, target,
63 type_return, (caddr_t *) & std_targets, &std_length,
64 format);
65 /*
66 * Allocate extra storage for our extra targets and build a
67 * list. We return the list via the value parameter
68 */
69 *length = std_length + 4;
70 *value = (XtPointer) XtMalloc(sizeof(Atom) * (*length));
71 targets = *(Atom **) value;
72 *targets++ = TARGETS;
73 *targets++ = XmInternAtom(XtDisplay(w), "MULTIPLE", False);
74 *targets++ = XA_STRING;
75 *targets++ = COMPOUND_TEXT;
76 /* Append standard list to ours, and free the standard one */
77 bcopy((char *) std_targets, (char *) targets, sizeof(Atom) * std_length);
78 XtFree((char *) std_targets);
79 *type_return = XA_ATOM;
80 *format = 32;
81 return True;
82 } else if (*target == XA_STRING) {
83 char **tmp_value;
84 XTextProperty tmp_prop;
85 int status = 0;
86 XmString *selected_items;
87 int selected_count;
88 int i;
89
90 XtVaGetValues(w, XmNselectedItems, &selected_items,
91 XmNselectedItemCount, &selected_count, 0);
92 if (selected_count == 0)
93 return False;
94
95 tmp_value = (char **) XtMalloc(selected_count * sizeof(char *));
96 for (i = 0; i < selected_count; i++)
97 if (!XmStringGetLtoR(selected_items[i],
98 XmFONTLIST_DEFAULT_TAG, &tmp_value[i]))
99 tmp_value[i] = NULL;
100 status = XmbTextListToTextProperty(XtDisplay(w), tmp_value,
101 selected_count, (XICCEncodingStyle) XStringStyle,
102 &tmp_prop);
103 for (i = 0; i < selected_count; i++)
104 XtFree((char *)tmp_value[i]);
105 XtFree((char *)tmp_value);
106 if (status == Success || status > 0) {
107 *type_return = XA_STRING;
108 *format = 8;
109 *value = (XtPointer) XtMalloc((unsigned) tmp_prop.nitems);
110 memcpy((void *) *value,
111 (void *) tmp_prop.value, (unsigned) tmp_prop.nitems);
112 XFree((char *) tmp_prop.value);
113 *length = tmp_prop.nitems;
114 return True;
115 }
116 } else if (*target == COMPOUND_TEXT) {
117 XmString *selected_items, s1, s2, sep;
118 int selected_count;
119 int i;
120 XrmValue from_val, to_val;
121
122 XtVaGetValues(w, XmNselectedItems, &selected_items,
123 XmNselectedItemCount, &selected_count, 0);
124 if (selected_count == 0)
125 return False;
126
127 s1 = XmStringCopy(selected_items[0]);
128 sep = XmStringSeparatorCreate();
129 for (i = 1; i < selected_count; i++) {
130 s2 = XmStringConcat(s1, sep);
131 XmStringFree(s1);
132 s1 = XmStringConcat(s2, selected_items[i]);
133 XmStringFree(s2);
134 }
135 from_val.addr = (char *) s1;
136 if (_XmCvtXmStringToCT(&from_val, &to_val)) {
137 *type_return = COMPOUND_TEXT;
138 *format = 8;
139 *value = to_val.addr;
140 *length = to_val.size + 1;
141 XmStringFree(s1);
142 XmStringFree(sep);
143 return True;
144 }
145 XmStringFree(s1);
146 XmStringFree(sep);
147 } else if (XmuConvertStandardSelection(w, request->time, selection, target,
148 type_return, (caddr_t *) value, length, format))
149 return True;
150 *value = NULL;
151 *length = 0;
152 return False;
153 }
154
155 void
lose_proc(w,selection)156 lose_proc(w, selection)
157 Widget w;
158 Atom *selection;
159 {
160 XmListDeselectAllItems(w);
161 }
162 void
create_appshell(display,app_name,app_argc,app_argv)163 create_appshell(display, app_name, app_argc, app_argv)
164 Display *display;
165 char *app_name;
166 int app_argc;
167 char **app_argv;
168 {
169 Arg al[64]; /* Arg List */
170 register int ac = 0; /* Arg Count */
171 XmString *list_items; /* For list items */
172 int list_item; /* Index for list_items */
173 Widget form = (Widget) NULL;
174 Widget list_sw = (Widget) NULL;
175 Widget list = (Widget) NULL;
176
177 XtSetArg(al[ac], XmNallowShellResize, TRUE); ac++;
178 XtSetArg(al[ac], XmNtitle, "Primary Selection"); ac++;
179 XtSetArg(al[ac], XmNargc, app_argc); ac++;
180 XtSetArg(al[ac], XmNargv, app_argv); ac++;
181 appshell = XtAppCreateShell(app_name, "XApplication", applicationShellWidgetClass, display, al, ac);
182 ac = 0;
183 XtSetArg(al[ac], XmNautoUnmanage, FALSE); ac++;
184 form = XmCreateForm(appshell, "form", al, ac);
185 ac = 0;
186 XtSetArg(al[ac], XmNvisibleItemCount, 11); ac++;
187 XtSetArg(al[ac], XmNselectionPolicy, XmMULTIPLE_SELECT); ac++;
188 XtSetArg(al[ac], XmNlistSizePolicy, XmRESIZE_IF_POSSIBLE); ac++;
189 XtSetArg(al[ac], XmNitemCount, 4); ac++;
190 list_items = (XmString *) XtMalloc(sizeof(XmString) * 4);
191 list_items[0] = XmStringCreateLtoR("Item1", (XmStringCharSet) XmFONTLIST_DEFAULT_TAG);
192 list_items[1] = XmStringCreateLtoR("Item2", (XmStringCharSet) XmFONTLIST_DEFAULT_TAG);
193 list_items[2] = XmStringCreateLtoR("Item3", (XmStringCharSet) XmFONTLIST_DEFAULT_TAG);
194 list_items[3] = XmStringCreateLtoR("Item4", (XmStringCharSet) XmFONTLIST_DEFAULT_TAG);
195 XtSetArg(al[ac], XmNitems, list_items); ac++;
196 list = XmCreateScrolledList(form, "list", al, ac);
197 XtAddCallback(list, XmNmultipleSelectionCallback, select_callback, NULL);
198
199 ac = 0;
200 list_sw = XtParent(list);
201
202 for (list_item = 0; list_item < 4; list_item++)
203 XmStringFree(list_items[list_item]);
204 XtFree((char *) list_items);
205
206 XtSetArg(al[ac], XmNtopAttachment, XmATTACH_FORM); ac++;
207 XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_FORM); ac++;
208 XtSetArg(al[ac], XmNleftAttachment, XmATTACH_FORM); ac++;
209 XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM); ac++;
210 XtSetValues(list_sw, al, ac);
211 ac = 0;
212 XtManageChild(list);
213 XtManageChild(form);
214 }
215
216
217
218 XtAppContext app_context;
219 Display *display; /* Display */
220
221 int
main(argc,argv)222 main(argc, argv)
223 int argc;
224 char **argv;
225 {
226 XtSetLanguageProc((XtAppContext) NULL, (XtLanguageProc) NULL, (XtPointer) NULL);
227 XtToolkitInitialize();
228 app_context = XtCreateApplicationContext();
229 display = XtOpenDisplay(app_context, NULL, argv[0], "XApplication",
230 NULL, 0, &argc, argv);
231 if (!display) {
232 printf("%s: can't open display, exiting...\n", argv[0]);
233 exit(-1);
234 }
235 create_appshell(display, argv[0], argc, argv);
236 XtRealizeWidget(appshell);
237
238 {
239 static XtWidgetGeometry Expected[] = {
240 CWWidth | CWHeight , 56, 72, 40, 183, 0,0,0, /* form */
241 CWWidth | CWHeight | CWX | CWY, 0, 0, 40, 183, 0,0,0, /* listSW */
242 CWWidth | CWHeight | CWX | CWY, 0, 0, 40, 183, 0,0,0, /* list */
243 };
244 PrintDetails(appshell,Expected);
245 };
246 LessTifTestMainLoop(appshell);
247 exit(0);
248 }
249