1 static char *rcsid = "$Id$";
3 #include "UiIncludes.h"
5 static Widget uicreateconnectionsform();
6 static Widget uicreateconnectionslabel(Widget formwdg);
7 static Widget uicreateconnectionskill(Widget formwdg);
8 static Widget uicreateconnectionsclose(Widget formwdg);
9 static Widget uicreateconnectionsseparator(Widget formwdg, Widget bottomwdg);
11 uicreateconnectionslist(Widget formwdg, Widget topwdg,
13 static void uiconnectionsfreeprevious(void);
14 static void uiconnectionssetitems(char **listitems, void **connections,
16 static void uiconnectionskillcb(Widget wdg, caddr_t ignored,
17 XmListCallbackStruct * calldata);
18 static void uiconnectionsclosecb(Widget wdg, caddr_t ignored,
19 XmListCallbackStruct * calldata);
22 static int uiconnectionsdisplayed = FALSE;
23 static char **uilistitems;
24 static void **uiconnections;
26 static void (*uiconnectionscallback) (void *connection);
29 int UiDisplayConnectionsDialog(listitems, connections, nitems, callback)
33 void (*callback) (void *connection);
35 uiConnectionsGfx_t *connectionsgfx = &uiTopLevel.ConnectionsGfx;
37 uiconnectionsfreeprevious();
39 uiconnectionsdisplayed = TRUE;
40 uilistitems = listitems;
41 uiconnections = connections;
43 uiconnectionscallback = callback;
45 if (connectionsgfx->FormWdg) {
46 XtMapWidget(XtParent(connectionsgfx->FormWdg));
47 uiconnectionssetitems(listitems, connections, nitems);
51 connectionsgfx->FormWdg = uicreateconnectionsform();
52 connectionsgfx->LabelWdg =
53 uicreateconnectionslabel(connectionsgfx->FormWdg);
54 connectionsgfx->KillWdg =
55 uicreateconnectionskill(connectionsgfx->FormWdg);
56 connectionsgfx->CloseWdg =
57 uicreateconnectionsclose(connectionsgfx->FormWdg);
58 connectionsgfx->SeparatorWdg =
59 uicreateconnectionsseparator(connectionsgfx->FormWdg,
60 connectionsgfx->KillWdg);
61 connectionsgfx->ListWdg =
62 uicreateconnectionslist(connectionsgfx->FormWdg,
63 connectionsgfx->LabelWdg,
64 connectionsgfx->SeparatorWdg);
66 uiconnectionssetitems(listitems, connections, nitems);
68 XtManageChild(connectionsgfx->FormWdg);
69 XtRealizeWidget(XtParent(connectionsgfx->FormWdg));
75 int UiConnectionsDialogDisplayed()
77 return uiconnectionsdisplayed;
81 void uiConnectionsUpdateDialog()
83 if (!uiPageInfo.CurrentPage && uiTopLevel.ConnectionsGfx.FormWdg) {
84 uiconnectionsfreeprevious();
85 uiconnectionssetitems((char **) NULL, (void **) NULL, 0);
86 XtUnmapWidget(XtParent(uiTopLevel.ConnectionsGfx.FormWdg));
92 uicreateconnectionsform()
99 topwdg = XtCreateApplicationShell("Connections",
100 topLevelShellWidgetClass,
102 XtVaSetValues(topwdg,
103 XmNtitle, UI_CONNECTIONS_TITLE, NULL);
105 args = uiVaSetArgs(&nargs,
106 XmNresizePolicy, XmRESIZE_NONE,
107 XmNautoUnmanage, FALSE, NULL);
108 formwdg = XmCreateForm(topwdg, "ConnectionsDialog",
116 uicreateconnectionslabel(formwdg)
124 labelstr = XmStringCreateSimple("Open connections");
125 args = uiVaSetArgs(&nargs,
126 XmNlabelString, labelstr,
127 XmNtopAttachment, XmATTACH_FORM,
128 XmNtopOffset, UI_CONNECTIONS_WDG_OFFSET,
129 XmNleftAttachment, XmATTACH_FORM,
130 XmNrightAttachment, XmATTACH_FORM, NULL);
131 labelwdg = XmCreateLabelGadget(formwdg, "ConnectionsLabel", args, nargs);
132 XtManageChild(labelwdg);
133 XmStringFree(labelstr);
140 uicreateconnectionskill(formwdg)
147 args = uiVaSetArgs(&nargs,
148 XmNleftAttachment, XmATTACH_POSITION,
150 XmNrightAttachment, XmATTACH_POSITION,
151 XmNrightPosition, 40,
152 XmNbottomAttachment, XmATTACH_FORM,
153 XmNbottomOffset, UI_CONNECTIONS_WDG_OFFSET, NULL);
154 killwdg = XmCreatePushButtonGadget(formwdg, "Kill", args, nargs);
155 XtAddCallback(killwdg, XmNactivateCallback,
156 (XtCallbackProc) uiconnectionskillcb, (caddr_t) NULL);
157 XtManageChild(killwdg);
164 uicreateconnectionsclose(formwdg)
171 args = uiVaSetArgs(&nargs,
172 XmNleftAttachment, XmATTACH_POSITION,
174 XmNrightAttachment, XmATTACH_POSITION,
175 XmNrightPosition, 95,
176 XmNbottomAttachment, XmATTACH_FORM,
177 XmNbottomOffset, UI_CONNECTIONS_WDG_OFFSET, NULL);
178 closewdg = XmCreatePushButtonGadget(formwdg, "Close", args, nargs);
179 XtAddCallback(closewdg, XmNactivateCallback,
180 (XtCallbackProc) uiconnectionsclosecb, (caddr_t) NULL);
181 XtManageChild(closewdg);
188 uicreateconnectionsseparator(formwdg, bottomwdg)
196 args = uiVaSetArgs(&nargs,
197 XmNbottomAttachment, XmATTACH_WIDGET,
198 XmNbottomWidget, bottomwdg,
199 XmNbottomOffset, UI_CONNECTIONS_WDG_OFFSET,
200 XmNleftAttachment, XmATTACH_FORM,
201 XmNrightAttachment, XmATTACH_FORM, NULL);
202 separatorwdg = XmCreateSeparatorGadget(formwdg, "ConnectionsSeparator",
204 XtManageChild(separatorwdg);
211 uicreateconnectionslist(formwdg, topwdg, bottomwdg)
220 args = uiVaSetArgs(&nargs,
221 XmNvisibleItemCount, 15,
223 XmNselectionPolicy, XmSINGLE_SELECT,
224 XmNlistSizePolicy, XmCONSTANT,
225 XmNscrollBarDisplayPolicy, XmSTATIC,
226 XmNtopAttachment, XmATTACH_WIDGET,
227 XmNtopWidget, topwdg,
228 XmNtopOffset, UI_CONNECTIONS_WDG_OFFSET,
229 XmNbottomAttachment, XmATTACH_WIDGET,
230 XmNbottomWidget, bottomwdg,
231 XmNbottomOffset, UI_CONNECTIONS_WDG_OFFSET,
232 XmNrightAttachment, XmATTACH_FORM,
233 XmNrightOffset, UI_CONNECTIONS_WDG_OFFSET,
234 XmNleftAttachment, XmATTACH_FORM,
235 XmNleftOffset, UI_CONNECTIONS_WDG_OFFSET, NULL);
236 listwdg = XmCreateScrolledList(formwdg, "ConnectionsList", args, nargs);
237 XtManageChild(listwdg);
238 XtAddCallback(listwdg, XmNdefaultActionCallback,
239 (XtCallbackProc) uiconnectionskillcb, (caddr_t) NULL);
245 void uiconnectionsfreeprevious()
252 static void uiconnectionssetitems(listitems, connections, nitems)
257 Widget listwdg = uiTopLevel.ConnectionsGfx.ListWdg;
259 XmString *tmpstr = uiMalloc(nitems * sizeof(XmString));
261 XmListDeleteAllItems(listwdg);
263 for (i = 0; i < nitems; i++)
264 tmpstr[i] = XmStringCreateSimple(listitems[i]);
266 XmListAddItems(listwdg, tmpstr, nitems, 0);
267 for (i = 0; i < nitems; i++)
268 XmStringFree(tmpstr[i]);
269 uiFree((void *) tmpstr);
276 static void uiconnectionskillcb(wdg, ignored, calldata)
279 XmListCallbackStruct *calldata;
281 Widget connectionswdg = uiTopLevel.ConnectionsGfx.ListWdg;
287 if (XmListGetSelectedPos(connectionswdg, &poslist, &poscount)) {
288 uiDefineCursor(uiBusyCursor);
289 if (uiHelpOnActionCB) {
290 (*uiHelpOnActionCB) ("Kill connection");
291 uiHelpOnActionCB = (void (*) (char *actionstring)) NULL;
293 (*uiconnectionscallback) (uiconnections[poslist[0] - 1]);
302 static void uiconnectionsclosecb(wdg, ignored, calldata)
305 XmListCallbackStruct *calldata;
307 XtUnmapWidget(XtParent(uiTopLevel.ConnectionsGfx.FormWdg));
308 uiconnectionsdisplayed = FALSE;