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