earlybrowserreborn - Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 roytam 1 static char *rcsid = "$Id$";
2  
3 #include "UiIncludes.h"
4  
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);
10 static Widget
11  uicreateconnectionslist(Widget formwdg, Widget topwdg,
12                           Widget bottomwdg);
13 static void uiconnectionsfreeprevious(void);
14 static void uiconnectionssetitems(char **listitems, void **connections,
15                                    int nitems);
16 static void uiconnectionskillcb(Widget wdg, caddr_t ignored,
17                                  XmListCallbackStruct * calldata);
18 static void uiconnectionsclosecb(Widget wdg, caddr_t ignored,
19                                   XmListCallbackStruct * calldata);
20  
21  
22 static int uiconnectionsdisplayed = FALSE;
23 static char **uilistitems;
24 static void **uiconnections;
25 static int uinitems;
26 static void (*uiconnectionscallback) (void *connection);
27  
28  
29 int UiDisplayConnectionsDialog(listitems, connections, nitems, callback)
30 char **listitems;
31 void **connections;
32 int nitems;
33 void (*callback) (void *connection);
34 {
35     uiConnectionsGfx_t *connectionsgfx = &uiTopLevel.ConnectionsGfx;
36  
37     uiconnectionsfreeprevious();
38  
39     uiconnectionsdisplayed = TRUE;
40     uilistitems = listitems;
41     uiconnections = connections;
42     uinitems = nitems;
43     uiconnectionscallback = callback;
44  
45     if (connectionsgfx->FormWdg) {
46         XtMapWidget(XtParent(connectionsgfx->FormWdg));
47         uiconnectionssetitems(listitems, connections, nitems);
48  
49         return UI_OK;
50     }
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);
65  
66     uiconnectionssetitems(listitems, connections, nitems);
67  
68     XtManageChild(connectionsgfx->FormWdg);
69     XtRealizeWidget(XtParent(connectionsgfx->FormWdg));
70  
71     return UI_OK;
72 }
73  
74  
75 int UiConnectionsDialogDisplayed()
76 {
77     return uiconnectionsdisplayed;
78 }
79  
80  
81 void uiConnectionsUpdateDialog()
82 {
83     if (!uiPageInfo.CurrentPage && uiTopLevel.ConnectionsGfx.FormWdg) {
84         uiconnectionsfreeprevious();
85         uiconnectionssetitems((char **) NULL, (void **) NULL, 0);
86         XtUnmapWidget(XtParent(uiTopLevel.ConnectionsGfx.FormWdg));
87     }
88 }
89  
90  
91 static Widget
92  uicreateconnectionsform()
93 {
94     ArgList args;
95     Cardinal nargs;
96     Widget formwdg;
97     Widget topwdg;
98  
99     topwdg = XtCreateApplicationShell("Connections",
100                                       topLevelShellWidgetClass,
101                                       NULL, 0);
102     XtVaSetValues(topwdg,
103                   XmNtitle, UI_CONNECTIONS_TITLE, NULL);
104  
105     args = uiVaSetArgs(&nargs,
106                        XmNresizePolicy, XmRESIZE_NONE,
107                        XmNautoUnmanage, FALSE, NULL);
108     formwdg = XmCreateForm(topwdg, "ConnectionsDialog",
109                            args, nargs);
110  
111     return formwdg;
112 }
113  
114  
115 static Widget
116  uicreateconnectionslabel(formwdg)
117 Widget formwdg;
118 {
119     ArgList args;
120     Cardinal nargs;
121     XmString labelstr;
122     Widget labelwdg;
123  
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);
134  
135     return labelwdg;
136 }
137  
138  
139 static Widget
140  uicreateconnectionskill(formwdg)
141 Widget formwdg;
142 {
143     ArgList args;
144     Cardinal nargs;
145     Widget killwdg;
146  
147     args = uiVaSetArgs(&nargs,
148                        XmNleftAttachment, XmATTACH_POSITION,
149                        XmNleftPosition, 5,
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);
158  
159     return killwdg;
160 }
161  
162  
163 static Widget
164  uicreateconnectionsclose(formwdg)
165 Widget formwdg;
166 {
167     ArgList args;
168     Cardinal nargs;
169     Widget closewdg;
170  
171     args = uiVaSetArgs(&nargs,
172                        XmNleftAttachment, XmATTACH_POSITION,
173                        XmNleftPosition, 60,
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);
182  
183     return closewdg;
184 }
185  
186  
187 static Widget
188  uicreateconnectionsseparator(formwdg, bottomwdg)
189 Widget formwdg;
190 Widget bottomwdg;
191 {
192     ArgList args;
193     Cardinal nargs;
194     Widget separatorwdg;
195  
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",
203                                            args, nargs);
204     XtManageChild(separatorwdg);
205  
206     return separatorwdg;
207 }
208  
209  
210 static Widget
211  uicreateconnectionslist(formwdg, topwdg, bottomwdg)
212 Widget formwdg;
213 Widget topwdg;
214 Widget bottomwdg;
215 {
216     ArgList args;
217     Cardinal nargs;
218     Widget listwdg;
219  
220     args = uiVaSetArgs(&nargs,
221                        XmNvisibleItemCount, 15,
222                        XmNwidth, 300,
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);
240  
241     return listwdg;
242 }
243  
244  
245 void uiconnectionsfreeprevious()
246 {
247     if (uinitems)
248         uiFree(uilistitems);
249 }
250  
251  
252 static void uiconnectionssetitems(listitems, connections, nitems)
253 char **listitems;
254 void **connections;
255 int nitems;
256 {
257     Widget listwdg = uiTopLevel.ConnectionsGfx.ListWdg;
258     int i;
259     XmString *tmpstr = uiMalloc(nitems * sizeof(XmString));
260  
261     XmListDeleteAllItems(listwdg);
262     if (nitems) {
263         for (i = 0; i < nitems; i++)
264             tmpstr[i] = XmStringCreateSimple(listitems[i]);
265  
266         XmListAddItems(listwdg, tmpstr, nitems, 0);
267         for (i = 0; i < nitems; i++)
268             XmStringFree(tmpstr[i]);
269         uiFree((void *) tmpstr);
270     }
271 }
272  
273  
274  
275  
276 static void uiconnectionskillcb(wdg, ignored, calldata)
277 Widget wdg;
278 caddr_t ignored;
279 XmListCallbackStruct *calldata;
280 {
281     Widget connectionswdg = uiTopLevel.ConnectionsGfx.ListWdg;
282     int *poslist;
283     int poscount;
284     char *parentaddress;
285  
286     if (uinitems)
287         if (XmListGetSelectedPos(connectionswdg, &poslist, &poscount)) {
288             uiDefineCursor(uiBusyCursor);
289             if (uiHelpOnActionCB) {
290                 (*uiHelpOnActionCB) ("Kill connection");
291                 uiHelpOnActionCB = (void (*) (char *actionstring)) NULL;
292             } else
293                 (*uiconnectionscallback) (uiconnections[poslist[0] - 1]);
294  
295             uiUndefineCursor();
296  
297             XtFree(poslist);
298         }
299 }
300  
301  
302 static void uiconnectionsclosecb(wdg, ignored, calldata)
303 Widget wdg;
304 caddr_t ignored;
305 XmListCallbackStruct *calldata;
306 {
307     XtUnmapWidget(XtParent(uiTopLevel.ConnectionsGfx.FormWdg));
308     uiconnectionsdisplayed = FALSE;
309 }