1 /*****************************************************************************
2   FILE           : $Source: /projects/higgs1/SNNS/CVS/SNNS/xgui/sources/ui_edit.c,v $
3   SHORTNAME      : edit.c
4   SNNS VERSION   : 4.2
5 
6   PURPOSE        : callbacks for editing sites and f-types
7   NOTES          :
8 
9   AUTHOR         : Tilman Sommer
10   DATE           : 25.9.1990
11 
12   CHANGED BY     :
13   RCS VERSION    : $Revision: 2.7 $
14   LAST CHANGE    : $Date: 1998/03/03 14:10:22 $
15 
16     Copyright (c) 1990-1995  SNNS Group, IPVR, Univ. Stuttgart, FRG
17     Copyright (c) 1996-1998  SNNS Group, WSI, Univ. Tuebingen, FRG
18 
19 ******************************************************************************/
20 #include <config.h>
21 
22 #include <stdio.h>
23 #include <stdlib.h>
24 
25 #include "ui.h"
26 
27 #include <X11/Xaw3d/List.h>
28 
29 #include "kr_ui.h"
30 
31 #include "ui_infoP.h"  /* ui_info_displayList() */
32 #include "ui_lists.h"
33 #include "ui_xWidgets.h"
34 #include "ui_confirmer.h"
35 #include "ui_utilP.h"
36 #include "ui_action.h"
37 
38 #include "ui_edit.ph"
39 
40 
41 /*****************************************************************************
42   FUNCTION : ui_edit_setCurrentSite
43 
44   PURPOSE  : makes this side current in the panel
45   RETURNS  : void
46   NOTES    :
47 
48   UPDATE   : 1.2.1990
49 ******************************************************************************/
50 
ui_edit_setCurrentSite(char * name)51 void ui_edit_setCurrentSite (char *name)
52 
53 {
54     bool successful;
55     char *siteName, *func;
56 
57 
58     if (name != NULL) {
59 	successful = krui_getFirstSiteTableEntry(&siteName, &func);
60 	while (successful) {
61 	    if (strcmp(siteName,name) == 0) { /* site entry found */
62 		sprintf(ui_edit_siteName, "%s", name);
63 		ui_xSetString(ui_edit_siteNameWidget, ui_edit_siteName);
64 		sprintf(ui_edit_siteFuncName, "%s", func);
65 		ui_xSetLabel(ui_edit_siteFuncNameWidget, ui_edit_siteFuncName);
66 		return;
67 	    } else
68 		successful = krui_getNextSiteTableEntry(&siteName, &func);
69 	}
70     }
71     /* no such site was found or (name == NULL) */
72     ui_xSetString(ui_edit_siteNameWidget, "");
73     ui_xSetLabel(ui_edit_siteFuncNameWidget, "");
74 }
75 
76 
77 /*****************************************************************************
78   FUNCTION : ui_edit_selectFunction
79 
80   PURPOSE  : popup a list with all site functions
81   RETURNS  : void
82   NOTES    :
83 
84   UPDATE   : 1.2.1990
85 ******************************************************************************/
86 
ui_edit_selectFunction(Widget w,int type,caddr_t call_data)87 void  ui_edit_selectFunction (Widget w, int type, caddr_t call_data)
88 
89 {
90     static struct SimpleListType listFunc;
91 
92     switch (type) {
93       case UI_EDIT_SITE_FUNC:
94 	sprintf(listFunc.msg,"%s","Select site function:");
95 	listFunc.unitPtr  = NULL;
96 	listFunc.widgetPtr= w;
97 	listFunc.listType = UI_LIST_SITE_FUNC;
98 	ui_info_displayList(w, (struct SimpleListType *) &listFunc, NULL);
99 	sprintf(ui_edit_siteFuncName,"%s",ui_list_returnName);
100 	ui_xSetLabel(ui_edit_siteFuncNameWidget, ui_edit_siteFuncName);
101 	break;
102       case UI_EDIT_ACT_FUNC:
103 	sprintf(listFunc.msg,"%s","Select f-type activation function:");
104 	listFunc.unitPtr  = NULL;
105 	listFunc.widgetPtr= w;
106 	listFunc.listType = UI_LIST_FTYPE_ACT_FUNC;
107 	ui_info_displayList(w, (struct SimpleListType *) &listFunc, NULL);
108 	sprintf(ui_edit_actFuncName,"%s",ui_list_returnName);
109 	ui_xSetLabel(ui_edit_actFuncNameWidget, ui_edit_actFuncName);
110 	break;
111       case UI_EDIT_OUT_FUNC:
112 	sprintf(listFunc.msg,"%s","Select f-type output function:");
113 	listFunc.unitPtr  = NULL;
114 	listFunc.widgetPtr= w;
115 	listFunc.listType = UI_LIST_FTYPE_OUT_FUNC;
116 	ui_info_displayList(w, (struct SimpleListType *) &listFunc, NULL);
117 	sprintf(ui_edit_outFuncName,"%s",ui_list_returnName);
118 	ui_xSetLabel(ui_edit_outFuncNameWidget, ui_edit_outFuncName);
119 	break;
120     }
121 }
122 
123 
124 /*****************************************************************************
125   FUNCTION : ui_edit_setSite
126 
127   PURPOSE  : change name and function of the current selected site
128   RETURNS  : void
129   NOTES    : This site is highlighted.
130              Callback from a SET-Button.
131 
132   UPDATE   : 20.9.90
133 ******************************************************************************/
134 
ui_edit_setSite(Widget w,struct SimpleListType * listDescriptorPtr,caddr_t call)135 void  ui_edit_setSite(Widget w, struct SimpleListType *listDescriptorPtr,
136 	caddr_t call)
137 
138 {
139     XawListReturnStruct  *listStructPtr;
140 
141     listStructPtr = XawListShowCurrent(listDescriptorPtr->listWidget);
142 
143     if (listStructPtr->list_index == XAW_LIST_NONE) {
144 	ui_confirmOk("No site in the site list selected!");
145 	return;
146     }
147 
148     ui_xStringFromAsciiWidget(ui_edit_siteNameWidget, ui_edit_siteName,
149 			      MAX_NAME_LENGTH);
150     ui_correctName(ui_edit_siteName);
151     ui_checkError(krui_changeSiteTableEntry(listStructPtr->string,
152 					    ui_edit_siteName,
153 					    ui_edit_siteFuncName));
154     if (ui_kernelError < 0)
155 	ui_confirmOk("Name or function invalid!");
156     else {
157 	free((listDescriptorPtr->listPtr)[listStructPtr->list_index]);
158 	(listDescriptorPtr->listPtr)[listStructPtr->list_index] =
159 	    XtNewString(ui_edit_siteName);
160 	XawListChange(listDescriptorPtr->listWidget,
161 		      listDescriptorPtr->listPtr,
162 		      listDescriptorPtr->noOfItems, 0, True);
163     }
164 }
165 
166 
167 /*****************************************************************************
168   FUNCTION : ui_edit_listSetSite
169 
170   PURPOSE  : callback. Called when a site in the site list was seleted.
171   RETURNS  : void
172   NOTES    :
173 
174   UPDATE   : 28.8.1990
175 ******************************************************************************/
176 
ui_edit_listSetSite(Widget w,int editType,XawListReturnStruct * listStructPtr)177 void ui_edit_listSetSite (Widget w, int editType,
178 	XawListReturnStruct *listStructPtr) /* call_data of list widgets */
179 
180 {
181     switch (editType) {
182       case UI_EDIT_FTYPE:
183 	break;
184       case UI_EDIT_SITE:
185 	ui_edit_setCurrentSite(listStructPtr->string);
186 	break;
187     }
188 }
189 
190 
191 /*****************************************************************************
192   FUNCTION : ui_edit_newSite
193 
194   PURPOSE  : callback. Called when the creation of a new site was requested.
195   RETURNS  : void
196   NOTES    :
197 
198   UPDATE   : 1.2.1990
199 ******************************************************************************/
200 
ui_edit_newSite(Widget w,struct SimpleListType * listDescriptorPtr,caddr_t call)201 void  ui_edit_newSite (Widget w, struct SimpleListType *listDescriptorPtr,
202      caddr_t call)
203 
204 {
205     ui_xStringFromAsciiWidget(ui_edit_siteNameWidget, ui_edit_siteName,
206 			      MAX_NAME_LENGTH);
207     ui_correctName(ui_edit_siteName);
208     if ((strlen(ui_edit_siteName) == 0) OR (strlen(ui_edit_siteFuncName) == 0)) {
209 	ui_confirmOk("Invalid name or function!");
210 	return;
211     }
212 
213     ui_checkError(krui_createSiteTableEntry(ui_edit_siteName,
214 					    ui_edit_siteFuncName));
215     if (ui_kernelError >= 0) {
216 	if (ui_list_noOfSites++ == 0) {
217 	    /* first entry is "*** no sites ***" */
218 	    free((listDescriptorPtr->listPtr)[0]);
219 	    (listDescriptorPtr->listPtr)[0] =
220 		XtNewString(ui_edit_siteName);
221 	} else
222 	    ui_xAddListEntry(listDescriptorPtr, ui_edit_siteName);
223 	XawListChange(listDescriptorPtr->listWidget, listDescriptorPtr->listPtr,
224 		      listDescriptorPtr->noOfItems, 0, True);
225     }
226 }
227 
228 
229 /*****************************************************************************
230   FUNCTION : ui_edit_deleteSite
231 
232   PURPOSE  : callback. Called when a site should be deleted
233   RETURNS  : void
234   NOTES    :
235 
236   UPDATE   : 1.2.1990
237 ******************************************************************************/
238 
ui_edit_deleteSite(Widget w,struct SimpleListType * listDescriptorPtr,caddr_t call)239 void  ui_edit_deleteSite (Widget w, struct SimpleListType *listDescriptorPtr,
240      caddr_t call)
241 
242 {
243     XawListReturnStruct   *listStructPtr;
244     int                   i;
245 
246     listStructPtr = XawListShowCurrent(listDescriptorPtr->listWidget);
247 
248     if ((listStructPtr->list_index == XAW_LIST_NONE) OR
249 	(ui_list_noOfSites <= 0))
250 	return; /* no site selected */
251 
252     ui_checkError(krui_deleteSiteTableEntry(listStructPtr->string));
253 
254     /* remove this entry from the array */
255     free((listDescriptorPtr->listPtr)[listStructPtr->list_index]);
256     for (i = listStructPtr->list_index + 1;
257 	 i <= listDescriptorPtr->noOfItems - 1; i++)
258 	(listDescriptorPtr->listPtr)[i-1] = (listDescriptorPtr->listPtr)[i];
259     if (ui_list_noOfSites-- == 1) { /* last site deleted */
260 	(listDescriptorPtr->listPtr)[0] = XtNewString("*** no sites");
261     XawListChange(listDescriptorPtr->listWidget,
262 		  listDescriptorPtr->listPtr,
263 		  1, 0, True);
264     } else
265 	XawListChange(listDescriptorPtr->listWidget,
266 		      listDescriptorPtr->listPtr,
267 		      --listDescriptorPtr->noOfItems, 0, True);
268 }
269 
270 
271 /*****************************************************************************
272   FUNCTION : ui_edit_displayFType
273 
274   PURPOSE  : display given ftype
275   RETURNS  : void
276   NOTES    :
277 
278   UPDATE   : 20.9.1990
279 ******************************************************************************/
280 
ui_edit_displayFType(char * name,struct SimpleListType * listDescriptorPtr)281 static void  ui_edit_displayFType(char *name,
282 	struct SimpleListType *listDescriptorPtr)
283 
284 {
285     if (krui_setFTypeEntry(name)) {
286 	sprintf(ui_edit_ftypeName,   "%s", krui_getFTypeName());
287 	sprintf(ui_edit_actFuncName, "%s", krui_getFTypeActFuncName());
288 	sprintf(ui_edit_outFuncName, "%s", krui_getFTypeOutFuncName());
289 	ui_list_buildList(listDescriptorPtr);
290 
291 	ui_xSetString(ui_edit_ftypeNameWidget , ui_edit_ftypeName);
292 	ui_xSetLabel(ui_edit_actFuncNameWidget, ui_edit_actFuncName);
293 	ui_xSetLabel(ui_edit_outFuncNameWidget, ui_edit_outFuncName);
294 
295 	XawListChange(listDescriptorPtr->listWidget,
296 		      listDescriptorPtr->listPtr,
297 		      listDescriptorPtr->noOfItems, 0, True);
298     } else {
299 	ui_xSetString(ui_edit_ftypeNameWidget , "");
300 	ui_xSetLabel(ui_edit_actFuncNameWidget, "");
301 	ui_xSetLabel(ui_edit_outFuncNameWidget, "");
302 
303 	listDescriptorPtr->noOfItems = 0;
304 	ui_xAddListEntry(listDescriptorPtr, "*** no sites ***");
305 	ui_list_noOfSites = 0;
306 	XawListChange(listDescriptorPtr->listWidget,
307 		      listDescriptorPtr->listPtr,
308 		      listDescriptorPtr->noOfItems, 0, True);
309     }
310 }
311 
312 
313 /*****************************************************************************
314   FUNCTION : ui_edit_displayFirstFType
315 
316   PURPOSE  : display first ftype
317   RETURNS  : void
318   NOTES    :
319 
320   UPDATE   : 20.9.1990
321 ******************************************************************************/
322 
ui_edit_displayFirstFType(struct SimpleListType * listDescriptorPtr)323 void  ui_edit_displayFirstFType (struct SimpleListType *listDescriptorPtr)
324 
325 {
326     if (krui_setFirstFTypeEntry()) {
327 	sprintf(ui_edit_ftypeName,   "%s", krui_getFTypeName());
328 	ui_edit_displayFType(ui_edit_ftypeName, listDescriptorPtr);
329     }
330 }
331 
332 
333 /*****************************************************************************
334   FUNCTION : ui_edit_ftypeAddSite
335 
336   PURPOSE  : popup site list
337              if a site was choosen add it to the list
338   RETURNS  : void
339   NOTES    :
340 
341   UPDATE   : 20.9.1990
342 ******************************************************************************/
343 
ui_edit_ftypeAddSite(Widget w,struct SimpleListType * listDescriptorPtr,caddr_t call)344 void  ui_edit_ftypeAddSite (Widget w,
345 	struct SimpleListType *listDescriptorPtr, caddr_t call)
346 
347 {
348     static struct SimpleListType listSites;
349 
350     sprintf(listSites.msg,"%s","Select site to add:");
351     listSites.unitPtr  = NULL;
352     listSites.widgetPtr= w;
353     listSites.listType = UI_LIST_SITE;
354     ui_info_displayList(w, (struct SimpleListType *) &listSites, NULL);
355     if (ui_list_returnIndex != XAW_LIST_NONE) {
356 	if (ui_list_noOfFTypeSites++ == 0) {
357 	    /* first entry is "*** no sites ***" */
358 	    /* replace the first dummy entry     */
359 	    free((listDescriptorPtr->listPtr)[0]);
360 	    (listDescriptorPtr->listPtr)[0] =
361 		XtNewString(ui_list_returnName);
362 	} else
363 	    ui_xAddListEntry(listDescriptorPtr, ui_list_returnName);
364 	XawListChange(listDescriptorPtr->listWidget, listDescriptorPtr->listPtr,
365 		      listDescriptorPtr->noOfItems, 0, True);
366     }
367 }
368 
369 
370 /*****************************************************************************
371   FUNCTION : ui_edit_ftypeDeleteSite
372 
373   PURPOSE  : remove highlighted site from list
374   RETURNS  : void
375   NOTES    :
376 
377   UPDATE   : 20.9.1990
378 ******************************************************************************/
379 
ui_edit_ftypeDeleteSite(Widget w,struct SimpleListType * listDescriptorPtr,caddr_t call)380 void  ui_edit_ftypeDeleteSite (Widget w,
381 	struct SimpleListType *listDescriptorPtr, caddr_t call)
382 
383 {
384     XawListReturnStruct   *listStructPtr;
385     int                   i;
386 
387     listStructPtr = XawListShowCurrent(listDescriptorPtr->listWidget);
388 
389     if ((listStructPtr->list_index == XAW_LIST_NONE) OR
390 	(ui_list_noOfFTypeSites <= 0))
391 	return; /* no site selected */
392 
393     /* remove this entry from the array */
394     free((listDescriptorPtr->listPtr)[listStructPtr->list_index]);
395     for (i = listStructPtr->list_index + 1;
396 	 i <= listDescriptorPtr->noOfItems - 1; i++)
397 	(listDescriptorPtr->listPtr)[i-1] = (listDescriptorPtr->listPtr)[i];
398     if (ui_list_noOfFTypeSites-- == 1) { /* last site deleted */
399 	(listDescriptorPtr->listPtr)[0] = XtNewString("*** no sites");
400     XawListChange(listDescriptorPtr->listWidget,
401 		  listDescriptorPtr->listPtr,
402 		  1, 0, True);
403     } else
404 	XawListChange(listDescriptorPtr->listWidget,
405 		      listDescriptorPtr->listPtr,
406 		      --listDescriptorPtr->noOfItems, 0, True);
407 }
408 
409 
410 /*****************************************************************************
411   FUNCTION : ui_edit_chooseFType
412 
413   PURPOSE  : display a list of all existingf f-types
414   RETURNS  : void
415   NOTES    :
416 
417   UPDATE   : 20.9.1990
418 ******************************************************************************/
419 
ui_edit_chooseFType(Widget w,struct SimpleListType * listDescriptorPtr,caddr_t call)420 void  ui_edit_chooseFType (Widget  w,
421      struct SimpleListType *listDescriptorPtr, caddr_t call)
422 
423 {
424     static struct SimpleListType listFTypes;
425 
426     if (krui_setFirstFTypeEntry()) {
427 	sprintf(listFTypes.msg,"%s","Choose f-type to edit:");
428 	listFTypes.unitPtr  = NULL;
429 	listFTypes.widgetPtr= w;
430 	listFTypes.listType = UI_LIST_FTYPE_NAME;
431 	ui_info_displayList(w, (struct SimpleListType *) &listFTypes, NULL);
432 	sprintf(ui_edit_ftypeName,"%s", ui_list_returnName);
433 	ui_edit_displayFType(ui_edit_ftypeName, listDescriptorPtr);
434     }
435 }
436 
437 
438 /*****************************************************************************
439   FUNCTION : ui_edit_setFType
440 
441   PURPOSE  : update ftype name and functions; sites remain unchanged
442   RETURNS  : void
443   NOTES    :
444 
445   UPDATE   : 20.9.1990
446 ******************************************************************************/
447 
ui_edit_setFType(Widget w,struct SimpleListType * listDescriptorPtr,caddr_t call)448 void  ui_edit_setFType (Widget w,
449      struct SimpleListType *listDescriptorPtr, caddr_t call)
450 
451 {
452     char buf[MAX_NAME_LENGTH];
453 
454     if (NOT krui_setFTypeEntry(ui_edit_ftypeName)) {
455 	sprintf(buf,"Invalid f-type: %s", ui_edit_ftypeName);
456 	ui_confirmOk(buf);
457 	return;
458     }
459 
460     ui_xStringFromAsciiWidget(ui_edit_ftypeNameWidget, buf,
461 			      MAX_NAME_LENGTH);
462     ui_correctName(buf);
463     if (strcmp(buf,ui_edit_ftypeName) != 0) {
464 	strcpy(ui_edit_ftypeName, buf);
465 	ui_checkError(krui_setFTypeName(ui_edit_ftypeName));
466     }
467     ui_checkError(krui_setFTypeActFunc(ui_edit_actFuncName));
468     ui_checkError(krui_setFTypeOutFunc(ui_edit_outFuncName));
469 }
470 
471 
472 /*****************************************************************************
473   FUNCTION : ui_edit_newFType
474 
475   PURPOSE  : create a new f-type
476   RETURNS  : void
477   NOTES    :
478 
479   UPDATE   : 20.9.1990
480 ******************************************************************************/
481 
ui_edit_newFType(Widget w,struct SimpleListType * listDescriptorPtr,caddr_t call)482 void  ui_edit_newFType (Widget w,
483      struct SimpleListType *listDescriptorPtr, caddr_t call)
484 
485 {
486     ui_xStringFromAsciiWidget(ui_edit_ftypeNameWidget, ui_edit_ftypeName,
487 			      MAX_NAME_LENGTH);
488     ui_correctName(ui_edit_ftypeName);
489 
490     if (strlen(ui_edit_ftypeName) > 0) {
491 	ui_checkError(krui_createFTypeEntry(ui_edit_ftypeName,
492 					    ui_edit_actFuncName,
493 					    ui_edit_outFuncName,
494 					    ui_list_noOfFTypeSites,
495 					    listDescriptorPtr->listPtr));
496 	if (ui_kernelError < 0)
497 	    ui_confirmOk("Creation of this f-type failed!");
498     } else
499 	ui_confirmOk("No f-type name given!");
500 }
501 
502 
503 /*****************************************************************************
504   FUNCTION : ui_edit_deleteFType
505 
506   PURPOSE  : delete f-type with the given name
507   RETURNS  : void
508   NOTES    :
509 
510   UPDATE   : 20.9.1990
511 ******************************************************************************/
512 
ui_edit_deleteFType(Widget w,struct SimpleListType * listDescriptorPtr,caddr_t call)513 void  ui_edit_deleteFType(Widget w,
514      struct SimpleListType *listDescriptorPtr, caddr_t call)
515 
516 {
517     ui_xStringFromAsciiWidget(ui_edit_ftypeNameWidget, ui_edit_ftypeName,
518 			      MAX_NAME_LENGTH);
519     ui_correctName(ui_edit_ftypeName);
520     ui_checkError(krui_deleteFTypeEntry(ui_edit_ftypeName));
521     if (ui_kernelError < 0) {
522 	char buf[MAX_NAME_LENGTH];
523 	sprintf(buf,"Can't delete f-type: %s",ui_edit_ftypeName);
524 	ui_confirmOk(buf);
525     } else
526 	ui_edit_displayFirstFType(listDescriptorPtr);
527 }
528 
529 
530 
531 
532 
533 
534 
535 
536 
537 /* end of file */
538 /* lines: 570 */
539