1 static char *rcsid = "$Id: UiList.c,v 1.1 1992/03/26 18:13:50 kny Exp kny $";
4 #include "UiIncludes.h"
7 static void uilistfreeprevious(void);
8 static void uilistsetitems(char **listitems, int nitems);
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);
22 static uiPage_t *uilistpage = (uiPage_t *) NULL;
23 static char **uilistitems;
24 static char **uiaddresses;
26 static void (*uilistcallback) (char *topaddress, char *address,
30 int UiDisplayListDialog(listitems, addresses, nitems, callback)
34 void (*callback) (char *topaddress, char *address, char *parentaddress);
36 uiListGfx_t *listgfx = &uiTopLevel.ListGfx;
40 uilistpage = uiPageInfo.CurrentPage;
41 uilistitems = listitems;
42 uiaddresses = addresses;
44 uilistcallback = callback;
46 if (listgfx->FormWdg) {
47 XtMapWidget(XtParent(listgfx->FormWdg));
49 uiWidgetPlacement(XtParent(listgfx->FormWdg),
50 uiTopLevel.GlobalSettings.ListPlacement);
52 uilistsetitems(listitems, nitems);
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,
62 listgfx->ListWdg = uicreatelistlist(listgfx->FormWdg, listgfx->LabelWdg,
63 listgfx->SeparatorWdg);
65 uilistsetitems(listitems, nitems);
67 XtManageChild(listgfx->FormWdg);
68 XtRealizeWidget(XtParent(listgfx->FormWdg));
70 uiWidgetPlacement(XtParent(listgfx->FormWdg),
71 uiTopLevel.GlobalSettings.ListPlacement);
77 void uiListUpdateDialog(page)
80 if (uiTopLevel.ListGfx.FormWdg && (page == uilistpage)) {
82 uilistsetitems((char **) NULL, 0);
83 uilistpage = (uiPage_t *) NULL;
84 XtUnmapWidget(XtParent(uiTopLevel.ListGfx.FormWdg));
97 topwdg = XtCreateApplicationShell("List",
98 topLevelShellWidgetClass,
100 XtVaSetValues(topwdg,
101 XmNtitle, UI_LIST_TITLE, NULL);
103 args = uiVaSetArgs(&nargs,
104 XmNresizePolicy, XmRESIZE_NONE,
105 XmNautoUnmanage, FALSE, NULL);
106 formwdg = XmCreateForm(topwdg, "ListDialog", args, nargs);
113 uicreatelistlabel(formwdg)
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);
137 uicreatelistopen(formwdg)
144 args = uiVaSetArgs(&nargs,
145 XmNleftAttachment, XmATTACH_POSITION,
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);
161 uicreatelistclose(formwdg)
168 args = uiVaSetArgs(&nargs,
169 XmNleftAttachment, XmATTACH_POSITION,
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);
185 uicreatelistseparator(formwdg, bottomwdg)
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",
201 XtManageChild(separatorwdg);
208 uicreatelistlist(formwdg, topwdg, bottomwdg)
217 args = uiVaSetArgs(&nargs,
218 XmNvisibleItemCount, 15,
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);
242 void uilistfreeprevious()
244 if (uilistpage && uinitems) {
245 uiFree((void *) uiaddresses);
248 uiFree(uilistitems[uinitems]);
255 static void uilistsetitems(listitems, nitems)
259 Widget listwdg = uiTopLevel.ListGfx.ListWdg;
261 XmString *tmpstr = uiMalloc(nitems * sizeof(XmString));
263 XmListDeleteAllItems(listwdg);
265 for (i = 0; i < nitems; i++)
266 tmpstr[i] = XmStringCreateSimple(listitems[i]);
268 XmListAddItems(listwdg, tmpstr, nitems, 0);
269 for (i = 0; i < nitems; i++)
270 XmStringFree(tmpstr[i]);
271 uiFree((void *) tmpstr);
276 static void uilistopencb(wdg, ignored, calldata)
279 XmListCallbackStruct *calldata;
281 Widget listwdg = uiTopLevel.ListGfx.ListWdg;
287 if (XmListGetSelectedPos(listwdg, &poslist, &poscount)) {
288 uiDefineCursor(uiBusyCursor);
289 if (uiHelpOnActionCB) {
290 (*uiHelpOnActionCB) ("Get page");
291 uiHelpOnActionCB = (void (*) (char *actionstring)) NULL;
294 HTAnchor_address((HTAnchor *)
295 uilistpage->HText->node_anchor);
296 (*uilistcallback) (uiaddresses[poslist[0] - 1],
297 uilistpage->Hierarchy->Address,
308 static void uilistclosecb(wdg, ignored, calldata)
311 XmListCallbackStruct *calldata;
313 XtUnmapWidget(XtParent(uiTopLevel.ListGfx.FormWdg));