1 /***********************************************************************/
2 /* Open Visualization Data Explorer                                    */
3 /* (C) Copyright IBM Corp. 1989,1999                                   */
4 /* ALL RIGHTS RESERVED                                                 */
5 /* This code licensed under the                                        */
6 /*    "IBM PUBLIC LICENSE - Open Visualization Data Explorer"          */
7 /***********************************************************************/
8 
9 #include <dxconfig.h>
10 #include "../base/defines.h"
11 
12 
13 
14 
15 #include "DXApplication.h"
16 #include "StartServerDialog.h"
17 #include "StartOptionsDialog.h"
18 #include "DXChild.h"
19 
20 #include <Xm/DialogS.h>
21 #include <Xm/Form.h>
22 #include <Xm/Label.h>
23 #include <Xm/Text.h>
24 #include <Xm/Separator.h>
25 #include <Xm/PushB.h>
26 
27 Boolean StartServerDialog::ClassInitialized = FALSE;
28 String StartServerDialog::DefaultResources[] =
29 {
30     ".dialogTitle:			Start Server...",
31     "*hostLabel.labelString:		Hostname:",
32 //    "*hostText.width:			200",
33     "*connectButton.labelString:	Connect",
34     "*cancelButton.labelString:		Cancel",
35     "*optionsButton.labelString:	Options...",
36 //    "*XmPushButton.width:		75",
37 //    "*XmPushButton.height:		25",
38     NULL
39 };
40 
41 
42 
okCallback(Dialog * clientData)43 boolean StartServerDialog::okCallback(Dialog *clientData)   // AJ
44 {
45     StartServerDialog  *d = (StartServerDialog*)clientData;
46 
47 
48     char *s = XmTextGetString(d->text);
49 
50     int autoStart;
51     const char *server;
52     const char *executive;
53     const char *workingDirectory;
54     const char *executiveFlags;
55     int port;
56     int memorySize;
57 
58     this->unmanage();
59 
60     theDXApplication->setBusyCursor(TRUE);
61 
62     theDXApplication->getServerParameters(
63 	&autoStart,
64 	&server,
65 	&executive,
66 	&workingDirectory,
67 	&executiveFlags,
68 	&port,
69 	&memorySize);
70 
71     theDXApplication->setServerParameters(
72 	autoStart,
73 	s,
74 	executive,
75 	workingDirectory,
76 	executiveFlags,
77 	port,
78 	memorySize);
79 
80     DXChild *c = theDXApplication->startServer();
81     theDXApplication->completeConnection(c);
82 
83     theDXApplication->setBusyCursor(FALSE);
84 
85     if(s)   XtFree(s);     //   AJ
86 
87     return FALSE;	// Unmanaged above
88 }
cancelCallback(Dialog *)89 void StartServerDialog::cancelCallback(Dialog *)
90 {
91 }
92 
StartServerDialog_TextCB(Widget,XtPointer clientData,XtPointer)93 extern "C" void StartServerDialog_TextCB(Widget,
94 					XtPointer clientData,
95 					XtPointer)
96 {
97     StartServerDialog *d = (StartServerDialog*)clientData;
98 
99     d->okCallback(d);
100 }
101 
StartServerDialog_OptionsCB(Widget,XtPointer clientData,XtPointer)102 extern "C" void StartServerDialog_OptionsCB(Widget,
103 					XtPointer clientData,
104 					XtPointer)
105 {
106     StartServerDialog *d = (StartServerDialog*)clientData;
107 
108     d->optionsCallback(d);
109 }
110 
optionsCallback(StartServerDialog * clientData)111 void StartServerDialog::optionsCallback(StartServerDialog *clientData)
112 {
113     StartServerDialog  *d = (StartServerDialog*) clientData;
114 
115     if (this->optionsDialog == NULL)
116 	this->optionsDialog = new StartOptionsDialog(this->getRootWidget());
117     d->optionsDialog->post();
118 }
119 
StartServerDialog_FocusEH(Widget,XtPointer clientData,XEvent * event,Boolean *)120 extern "C" void StartServerDialog_FocusEH(Widget,
121 					XtPointer clientData,
122 					XEvent* event,
123 					Boolean *)
124 {
125     StartServerDialog *d = (StartServerDialog*)clientData;
126 
127     XSetInputFocus(XtDisplay(d->text),
128 		   XtWindow(d->text),
129 		   RevertToPointerRoot,
130 		   CurrentTime);
131 }
132 
createDialog(Widget parent)133 Widget StartServerDialog::createDialog(Widget parent)
134 {
135     Arg  arg[5];
136     int  n = 0;
137 
138     XtSetArg(arg[n], XmNautoUnmanage, False);  n++;
139 
140     Widget w = this->CreateMainForm(parent, this->name, arg, n);
141 
142     Widget label = XtVaCreateManagedWidget("hostLabel",
143 	xmLabelWidgetClass,
144 	w,
145 	XmNtopAttachment,	XmATTACH_FORM,
146 	XmNtopOffset,		10,
147 	XmNleftAttachment,	XmATTACH_FORM,
148 	XmNleftOffset,		5,
149 	NULL);
150 
151     this->text = XtVaCreateManagedWidget("hostText",
152 	xmTextWidgetClass,
153 	w,
154 	XmNtopAttachment,	XmATTACH_FORM,
155 	XmNtopOffset,		10,
156 	XmNleftAttachment, 	XmATTACH_WIDGET,
157 	XmNleftWidget,		label,
158 	XmNleftOffset,		10,
159 	XmNrightAttachment,	XmATTACH_FORM,
160 	XmNrightOffset,		5,
161 	XmNeditMode,		XmSINGLE_LINE_EDIT,
162 	NULL);
163 
164     Widget separator = XtVaCreateManagedWidget("connectSeparator",
165 	xmSeparatorWidgetClass,
166 	w,
167 	XmNleftAttachment,   XmATTACH_FORM,
168 	XmNleftOffset,       2,
169 	XmNrightAttachment,  XmATTACH_FORM,
170 	XmNrightOffset,      2,
171 	XmNtopOffset,        9,
172 	XmNtopAttachment,    XmATTACH_WIDGET,
173 	XmNtopWidget,        this->text,
174 	NULL);
175 
176 
177     this->ok = XtVaCreateManagedWidget("connectButton",
178 	xmPushButtonWidgetClass,
179 	w,
180 	XmNleftAttachment,   XmATTACH_FORM,
181 	XmNleftOffset,       9,
182 	XmNtopAttachment,    XmATTACH_WIDGET,
183 	XmNtopWidget,        separator,
184 	XmNtopOffset,        9,
185 	XmNbottomAttachment, XmATTACH_FORM,
186 	XmNbottomOffset,     9,
187 	XmNuserData,	     (XtPointer)this,
188 #ifdef sun4
189 //	XmNheight,	     40,
190 //	XmNwidth,	     90,
191 #endif
192 	XmNshowAsDefault,    2,
193 	NULL);
194 
195     this->options = XtVaCreateManagedWidget("optionsButton",
196 	xmPushButtonWidgetClass,
197 	w,
198 	XmNleftAttachment,   XmATTACH_POSITION,
199 	XmNleftPosition,     50,
200 	XmNleftOffset,       -30,
201 	XmNtopAttachment,    XmATTACH_WIDGET,
202 	XmNtopWidget,        separator,
203 	XmNtopOffset,        17,
204 	XmNbottomAttachment, XmATTACH_FORM,
205 	XmNbottomOffset,     9 + 8,
206 	XmNuserData,	     (XtPointer)this,
207 	NULL);
208 
209     this->cancel = XtVaCreateManagedWidget("cancelButton",
210 	xmPushButtonWidgetClass,
211 	w,
212         XmNrightAttachment,  XmATTACH_FORM,
213         XmNrightOffset,      9,
214 	XmNtopAttachment,    XmATTACH_WIDGET,
215 	XmNtopWidget,        separator,
216 	XmNtopOffset,        17,
217 	XmNbottomAttachment, XmATTACH_FORM,
218 	XmNbottomOffset,     9 + 8,
219 	XmNuserData,	     (XtPointer)this,
220 	NULL);
221 
222     XtAddCallback(this->text,
223 		  XmNactivateCallback,
224 		  (XtCallbackProc)StartServerDialog_TextCB,
225 		  (XtPointer)this);
226 
227     XtAddCallback(this->options,
228 		  XmNactivateCallback,
229 		  (XtCallbackProc)StartServerDialog_OptionsCB,
230 		  (XtPointer)this);
231 
232     XtAddEventHandler(w,
233 		  EnterWindowMask,
234 		  False,
235 		  (XtEventHandler)(XtEventHandler)StartServerDialog_FocusEH,
236 		  (XtPointer)this);
237 
238     return w;
239 }
240 
241 
StartServerDialog(char * name,Widget parent)242 StartServerDialog::StartServerDialog(char *name, Widget parent) :
243     Dialog(name, parent)
244 {
245     this->optionsDialog = NULL;
246 
247 }
StartServerDialog(Widget parent)248 StartServerDialog::StartServerDialog(Widget parent) :
249     Dialog("startServerDialog", parent)
250 {
251     this->optionsDialog = NULL;
252 
253     if (NOT StartServerDialog::ClassInitialized)
254     {
255         StartServerDialog::ClassInitialized = TRUE;
256 	this->installDefaultResources(theApplication->getRootWidget());
257     }
258 }
259 
~StartServerDialog()260 StartServerDialog::~StartServerDialog()
261 {
262     if (this->optionsDialog)
263 	delete this->optionsDialog;
264 }
265 
266 //
267 // Install the default resources for this class.
268 //
installDefaultResources(Widget baseWidget)269 void StartServerDialog::installDefaultResources(Widget  baseWidget)
270 {
271     this->setDefaultResources(baseWidget, StartServerDialog::DefaultResources);
272     this->Dialog::installDefaultResources( baseWidget);
273 }
274 
manage()275 void StartServerDialog::manage()
276 {
277     this->Dialog::manage();
278 
279     const char *server;
280     theDXApplication->getServerParameters(
281 	NULL,
282 	&server,
283 	NULL,
284 	NULL,
285 	NULL,
286 	NULL,
287 	NULL);
288     XmTextSetString(this->text, (char *)server);
289 }
290 
unmanage()291 void StartServerDialog::unmanage()
292 {
293     if (this->optionsDialog)
294 	this->optionsDialog->unmanage();
295     this->Dialog::unmanage();
296 }
297