More compile fixes
[erwise] / Ui / UiList.c
1 static char *rcsid = "$Id: UiList.c,v 1.1 1992/03/26 18:13:50 kny Exp kny $";
2
3
4 #include "UiIncludes.h"
5
6
7 static void uilistfreeprevious(void);
8 static void uilistsetitems(char **listitems, int nitems);
9
10 static Widget uicreatelistform(void);
11 static Widget uicreatelistlabel(Widget parent);
12 static Widget uicreatelistopen(Widget parent);
13 static Widget uicreatelistclose(Widget parent);
14 static Widget uicreatelistseparator(Widget parent, Widget bottomwdg);
15 static Widget uicreatelistlist(Widget parent, Widget topwdg, Widget bottomwdg);
16 static void uilistopencb(Widget wdg, caddr_t ignored,
17                           XmListCallbackStruct * calldata);
18 static void uilistclosecb(Widget wdg, caddr_t ignored,
19                            XmListCallbackStruct * calldata);
20
21
22 static uiPage_t *uilistpage = (uiPage_t *) NULL;
23 static char **uilistitems;
24 static char **uiaddresses;
25 static int uinitems;
26 static void (*uilistcallback) (char *topaddress, char *address,
27                                 char *parentaddress);
28
29
30 int UiDisplayListDialog(listitems, addresses, nitems, callback)
31 char **listitems;
32 char **addresses;
33 int nitems;
34 void (*callback) (char *topaddress, char *address, char *parentaddress);
35 {
36     uiListGfx_t *listgfx = &uiTopLevel.ListGfx;
37
38     uilistfreeprevious();
39
40     uilistpage = uiPageInfo.CurrentPage;
41     uilistitems = listitems;
42     uiaddresses = addresses;
43     uinitems = nitems;
44     uilistcallback = callback;
45
46     if (listgfx->FormWdg) {
47         XtMapWidget(XtParent(listgfx->FormWdg));
48
49         uiWidgetPlacement(XtParent(listgfx->FormWdg),
50                           uiTopLevel.GlobalSettings.ListPlacement);
51
52         uilistsetitems(listitems, nitems);
53
54         return UI_OK;
55     }
56     listgfx->FormWdg = uicreatelistform();
57     listgfx->LabelWdg = uicreatelistlabel(listgfx->FormWdg);
58     listgfx->OpenWdg = uicreatelistopen(listgfx->FormWdg);
59     listgfx->CloseWdg = uicreatelistclose(listgfx->FormWdg);
60     listgfx->SeparatorWdg = uicreatelistseparator(listgfx->FormWdg,
61                                                   listgfx->OpenWdg);
62     listgfx->ListWdg = uicreatelistlist(listgfx->FormWdg, listgfx->LabelWdg,
63                                         listgfx->SeparatorWdg);
64
65     uilistsetitems(listitems, nitems);
66
67     XtManageChild(listgfx->FormWdg);
68     XtRealizeWidget(XtParent(listgfx->FormWdg));
69
70     uiWidgetPlacement(XtParent(listgfx->FormWdg),
71                       uiTopLevel.GlobalSettings.ListPlacement);
72
73     return UI_OK;
74 }
75
76
77 void uiListUpdateDialog(page)
78 uiPage_t *page;
79 {
80     if (uiTopLevel.ListGfx.FormWdg && (page == uilistpage)) {
81         uilistfreeprevious();
82         uilistsetitems((char **) NULL, 0);
83         uilistpage = (uiPage_t *) NULL;
84         XtUnmapWidget(XtParent(uiTopLevel.ListGfx.FormWdg));
85     }
86 }
87
88
89 static Widget
90  uicreatelistform()
91 {
92     ArgList args;
93     Cardinal nargs;
94     Widget formwdg;
95     Widget topwdg;
96
97     topwdg = XtCreateApplicationShell("List",
98                                       topLevelShellWidgetClass,
99                                       NULL, 0);
100     XtVaSetValues(topwdg,
101                   XmNtitle, UI_LIST_TITLE, NULL);
102
103     args = uiVaSetArgs(&nargs,
104                        XmNresizePolicy, XmRESIZE_NONE,
105                        XmNautoUnmanage, FALSE, NULL);
106     formwdg = XmCreateForm(topwdg, "ListDialog", args, nargs);
107
108     return formwdg;
109 }
110
111
112 static Widget
113  uicreatelistlabel(formwdg)
114 Widget formwdg;
115 {
116     ArgList args;
117     Cardinal nargs;
118     XmString labelstr;
119     Widget labelwdg;
120
121     labelstr = XmStringCreateSimple("List of references");
122     args = uiVaSetArgs(&nargs,
123                        XmNlabelString, labelstr,
124                        XmNtopAttachment, XmATTACH_FORM,
125                        XmNtopOffset, UI_LIST_WDG_OFFSET,
126                        XmNleftAttachment, XmATTACH_FORM,
127                        XmNrightAttachment, XmATTACH_FORM, NULL);
128     labelwdg = XmCreateLabelGadget(formwdg, "ListLabel", args, nargs);
129     XtManageChild(labelwdg);
130     XmStringFree(labelstr);
131
132     return labelwdg;
133 }
134
135
136 static Widget
137  uicreatelistopen(formwdg)
138 Widget formwdg;
139 {
140     ArgList args;
141     Cardinal nargs;
142     Widget openwdg;
143
144     args = uiVaSetArgs(&nargs,
145                        XmNleftAttachment, XmATTACH_POSITION,
146                        XmNleftPosition, 5,
147                        XmNrightAttachment, XmATTACH_POSITION,
148                        XmNrightPosition, 40,
149                        XmNbottomAttachment, XmATTACH_FORM,
150                        XmNbottomOffset, UI_LIST_WDG_OFFSET, NULL);
151     openwdg = XmCreatePushButtonGadget(formwdg, "Open", args, nargs);
152     XtAddCallback(openwdg, XmNactivateCallback,
153                   (XtCallbackProc) uilistopencb, (caddr_t) NULL);
154     XtManageChild(openwdg);
155
156     return openwdg;
157 }
158
159
160 static Widget
161  uicreatelistclose(formwdg)
162 Widget formwdg;
163 {
164     ArgList args;
165     Cardinal nargs;
166     Widget closewdg;
167
168     args = uiVaSetArgs(&nargs,
169                        XmNleftAttachment, XmATTACH_POSITION,
170                        XmNleftPosition, 60,
171                        XmNrightAttachment, XmATTACH_POSITION,
172                        XmNrightPosition, 95,
173                        XmNbottomAttachment, XmATTACH_FORM,
174                        XmNbottomOffset, UI_LIST_WDG_OFFSET, NULL);
175     closewdg = XmCreatePushButtonGadget(formwdg, "Close", args, nargs);
176     XtAddCallback(closewdg, XmNactivateCallback,
177                   (XtCallbackProc) uilistclosecb, (caddr_t) NULL);
178     XtManageChild(closewdg);
179
180     return closewdg;
181 }
182
183
184 static Widget
185  uicreatelistseparator(formwdg, bottomwdg)
186 Widget formwdg;
187 Widget bottomwdg;
188 {
189     ArgList args;
190     Cardinal nargs;
191     Widget separatorwdg;
192
193     args = uiVaSetArgs(&nargs,
194                        XmNbottomAttachment, XmATTACH_WIDGET,
195                        XmNbottomWidget, bottomwdg,
196                        XmNbottomOffset, UI_LIST_WDG_OFFSET,
197                        XmNleftAttachment, XmATTACH_FORM,
198                        XmNrightAttachment, XmATTACH_FORM, NULL);
199     separatorwdg = XmCreateSeparatorGadget(formwdg, "ListSeparator",
200                                            args, nargs);
201     XtManageChild(separatorwdg);
202
203     return separatorwdg;
204 }
205
206
207 static Widget
208  uicreatelistlist(formwdg, topwdg, bottomwdg)
209 Widget formwdg;
210 Widget topwdg;
211 Widget bottomwdg;
212 {
213     ArgList args;
214     Cardinal nargs;
215     Widget listwdg;
216
217     args = uiVaSetArgs(&nargs,
218                        XmNvisibleItemCount, 15,
219                        XmNwidth, 300,
220                        XmNselectionPolicy, XmSINGLE_SELECT,
221                        XmNlistSizePolicy, XmCONSTANT,
222                        XmNscrollBarDisplayPolicy, XmSTATIC,
223                        XmNtopAttachment, XmATTACH_WIDGET,
224                        XmNtopWidget, topwdg,
225                        XmNtopOffset, UI_LIST_WDG_OFFSET,
226                        XmNbottomAttachment, XmATTACH_WIDGET,
227                        XmNbottomWidget, bottomwdg,
228                        XmNbottomOffset, UI_LIST_WDG_OFFSET,
229                        XmNrightAttachment, XmATTACH_FORM,
230                        XmNrightOffset, UI_LIST_WDG_OFFSET,
231                        XmNleftAttachment, XmATTACH_FORM,
232                        XmNleftOffset, UI_LIST_WDG_OFFSET, NULL);
233     listwdg = XmCreateScrolledList(formwdg, "ListList", args, nargs);
234     XtManageChild(listwdg);
235     XtAddCallback(listwdg, XmNdefaultActionCallback,
236                   (XtCallbackProc) uilistopencb, (caddr_t) NULL);
237
238     return listwdg;
239 }
240
241
242 void uilistfreeprevious()
243 {
244     if (uilistpage && uinitems) {
245         uiFree((void *) uiaddresses);
246
247         while (uinitems--)
248             uiFree(uilistitems[uinitems]);
249
250         uiFree(uilistitems);
251     }
252 }
253
254
255 static void uilistsetitems(listitems, nitems)
256 char **listitems;
257 int nitems;
258 {
259     Widget listwdg = uiTopLevel.ListGfx.ListWdg;
260     int i;
261     XmString *tmpstr = uiMalloc(nitems * sizeof(XmString));
262
263     XmListDeleteAllItems(listwdg);
264     if (nitems) {
265         for (i = 0; i < nitems; i++)
266             tmpstr[i] = XmStringCreateSimple(listitems[i]);
267
268         XmListAddItems(listwdg, tmpstr, nitems, 0);
269         for (i = 0; i < nitems; i++)
270             XmStringFree(tmpstr[i]);
271         uiFree((void *) tmpstr);
272     }
273 }
274
275
276 static void uilistopencb(wdg, ignored, calldata)
277 Widget wdg;
278 caddr_t ignored;
279 XmListCallbackStruct *calldata;
280 {
281     Widget listwdg = uiTopLevel.ListGfx.ListWdg;
282     int *poslist;
283     int poscount;
284     char *parentaddress;
285
286     if (uinitems)
287         if (XmListGetSelectedPos(listwdg, &poslist, &poscount)) {
288             uiDefineCursor(uiBusyCursor);
289             if (uiHelpOnActionCB) {
290                 (*uiHelpOnActionCB) ("Get page");
291                 uiHelpOnActionCB = (void (*) (char *actionstring)) NULL;
292             } else {
293                 parentaddress =
294                     HTAnchor_address((HTAnchor *)
295                                      uilistpage->HText->node_anchor);
296                 (*uilistcallback) (uiaddresses[poslist[0] - 1],
297                                    uilistpage->Hierarchy->Address,
298                                    parentaddress);
299             }
300
301             uiUndefineCursor();
302
303             XtFree(poslist);
304         }
305 }
306
307
308 static void uilistclosecb(wdg, ignored, calldata)
309 Widget wdg;
310 caddr_t ignored;
311 XmListCallbackStruct *calldata;
312 {
313     XtUnmapWidget(XtParent(uiTopLevel.ListGfx.FormWdg));
314 }