1 /*
2  * $Id: x11dialg.c,v 1.5 2003/02/16 12:43:37 isizaka Exp isizaka $
3  *
4  * This file is part of "Ngraph for X11".
5  *
6  * Copyright (C) 2002, Satoshi ISHIZAKA. isizaka@msa.biglobe.ne.jp
7  *
8  * "Ngraph for X11" is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * "Ngraph for X11" is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21  *
22  */
23 
24 /**
25  *
26  * $Log: x11dialg.c,v $
27  * Revision 1.5  2003/02/16 12:43:37  isizaka
28  * for release 6.13.18
29  *
30  * Revision 1.4  2002/07/06 08:57:25  isizaka
31  * change to GPL.
32  *
33  * Revision 1.3  1999/04/11 06:09:20  isizaka
34  * *** empty log message ***
35  *
36  * Revision 1.2  1999/03/21 12:51:43  isizaka
37  * change SectionDialog, CrossDialog
38  *
39  * Revision 1.1  1999/03/17 13:29:01  isizaka
40  * Initial revision
41  *
42  *
43  **/
44 
45 #include <Xm/XmAll.h>
46 #include <X11/keysym.h>
47 #include <X11/cursorfont.h>
48 #include <sys/types.h>
49 #include <sys/wait.h>
50 #include <signal.h>
51 #include <stdio.h>
52 #include <string.h>
53 #include <stdlib.h>
54 #include <stdarg.h>
55 #include <math.h>
56 #include <time.h>
57 #include <limits.h>
58 
59 #include "motif12.h"
60 
61 #include "ngraph.h"
62 #include "object.h"
63 
64 #include "x11gui.h"
65 #include "x11dialg.h"
66 
67 void ResetEvent();
68 
69 char *fwlinestyle[CLINESTYLE]={"solid","dot","short dash","dash","dot dash",
70                                "2-dot dash","dot 2-dash"};
71 char *fwnumstyle[CNUMSTYLE]={"auto","0","1","2","3","4","5","6","7","8","9"};
72 int fwlinestylelistn[CLINESTYLE]={0,2,2,2,4,6,6};
73 char *fwlinestylelist[CLINESTYLE]={"","100 100","150 150","450 150",
74                                    "450 150 150 150",
75                                    "450 150 150 150 150 150",
76                                    "450 150 450 150 150 150"};
77 char *cblinewidth[CBLINEWIDTH]={"10","20","40","80","120"};
78 char *cbtextpt[CBTEXTPT]={"1200","1600","1800","2000","2400","3000"};
79 char *cbdirection[CBDIRECTION]={"0","9000","18000","27000"};
80 char *cbmarksize[CBMARKSIZE]={"100","200","300","400","500"};
81 char dashes[2]={2,2};
82 
83 struct FileDialog DlgFile;
84 struct FileDialog DlgFileDef;
85 struct EvalDialog DlgEval;
86 struct MathDialog DlgMath;
87 struct MathTextDialog DlgMathText;
88 struct FitDialog DlgFit;
89 struct FitLoadDialog DlgFitLoad;
90 struct FitSaveDialog DlgFitSave;
91 struct FileMoveDialog DlgFileMove;
92 struct FileMaskDialog DlgFileMask;
93 struct FileLoadDialog DlgFileLoad;
94 struct FileMathDialog DlgFileMath;
95 struct SectionDialog DlgSection;
96 struct CrossDialog DlgCross;
97 struct AxisDialog DlgAxis;
98 struct GridDialog DlgGrid;
99 struct ZoomDialog DlgZoom;
100 struct AxisBaseDialog DlgAxisBase;
101 struct AxisPosDialog DlgAxisPos;
102 struct NumDialog DlgNum;
103 struct AxisFontDialog DlgAxisFont;
104 struct GaugeDialog DlgGauge;
105 struct MergeDialog DlgMerge;
106 struct LegendCurveDialog DlgLegendCurve;
107 struct LegendPolyDialog DlgLegendPoly;
108 struct LegendArrowDialog DlgLegendArrow;
109 struct LegendRectDialog DlgLegendRect;
110 struct LegendArcDialog DlgLegendArc;
111 struct LegendMarkDialog DlgLegendMark;
112 struct LegendTextDialog DlgLegendText;
113 struct LegendTextDialog DlgLegendTextDef;
114 struct LegendGaussDialog DlgLegendGauss;
115 struct PageDialog DlgPage;
116 struct SwitchDialog DlgSwitch;
117 struct DirectoryDialog DlgDirectory;
118 struct LoadDialog DlgLoad;
119 struct PrmDialog DlgPrm;
120 struct SaveDialog DlgSave;
121 struct AboutDialog DlgAbout;
122 struct DriverDialog DlgDriver;
123 struct PrintDialog DlgPrinter;
124 struct OutputDataDialog DlgOutputData;
125 struct ScriptDialog DlgScript;
126 struct DefaultDialog DlgDefault;
127 struct SetScriptDialog DlgSetScript;
128 struct PrefScriptDialog DlgPrefScript;
129 struct SetDriverDialog DlgSetDriver;
130 struct PrefDriverDialog DlgPrefDriver;
131 struct MiscDialog DlgMisc;
132 struct ExViewerDialog DlgExViewer;
133 struct ViewerDialog DlgViewer;
134 struct SelectDialog DlgSelect;
135 struct CopyDialog DlgCopy;
136 
initdialog()137 void initdialog()
138 {
139   DlgFile.widget=NULL;
140   DlgFile.resource="data";
141   DlgFile.mark.widget=NULL;
142   DlgFile.mark.resource="markselection";
143   DlgFileDef.widget=NULL;
144   DlgFileDef.resource="datadefault";
145   DlgFileDef.mark.widget=NULL;
146   DlgFileDef.mark.resource="markselection";
147   DlgEval.widget=NULL;
148   DlgEval.resource="evaluation";
149   DlgMath.widget=NULL;
150   DlgMath.resource="math";
151   DlgMathText.widget=NULL;
152   DlgMathText.resource="mathtext";
153   DlgFit.widget=NULL;
154   DlgFit.resource="fit";
155   DlgFitLoad.widget=NULL;
156   DlgFitLoad.resource="fitload";
157   DlgFitSave.widget=NULL;
158   DlgFitSave.resource="fitsave";
159   DlgFileMove.widget=NULL;
160   DlgFileMove.resource="datamove";
161   DlgFileMask.widget=NULL;
162   DlgFileMask.resource="datamask";
163   DlgFileLoad.widget=NULL;
164   DlgFileLoad.resource="dataload";
165   DlgFileMath.widget=NULL;
166   DlgFileMath.resource="datamath";
167   DlgSection.widget=NULL;
168   DlgSection.resource="section";
169   DlgCross.widget=NULL;
170   DlgCross.resource="cross";
171   DlgAxis.widget=NULL;
172   DlgAxis.resource="axis";
173   DlgGrid.widget=NULL;
174   DlgGrid.resource="grid";
175   DlgZoom.widget=NULL;
176   DlgZoom.resource="zoom";
177   DlgAxisBase.widget=NULL;
178   DlgAxisBase.resource="axisbaseline";
179   DlgAxisPos.widget=NULL;
180   DlgAxisPos.resource="axisposition";
181   DlgNum.widget=NULL;
182   DlgNum.resource="numbering";
183   DlgAxisFont.widget=NULL;
184   DlgAxisFont.resource="axisfont";
185   DlgGauge.widget=NULL;
186   DlgGauge.resource="gauge";
187   DlgMerge.widget=NULL;
188   DlgMerge.resource="merge";
189   DlgLegendCurve.widget=NULL;
190   DlgLegendCurve.resource="curve";
191   DlgLegendPoly.widget=NULL;
192   DlgLegendPoly.resource="polygon";
193   DlgLegendArrow.widget=NULL;
194   DlgLegendArrow.resource="line";
195   DlgLegendRect.widget=NULL;
196   DlgLegendRect.resource="rectangle";
197   DlgLegendArc.widget=NULL;
198   DlgLegendArc.resource="arc";
199   DlgLegendMark.widget=NULL;
200   DlgLegendMark.resource="mark";
201   DlgLegendMark.mark.widget=NULL;
202   DlgLegendMark.mark.resource="markselection";
203   DlgLegendText.widget=NULL;
204   DlgLegendText.resource="text";
205   DlgLegendTextDef.widget=NULL;
206   DlgLegendTextDef.resource="textdefault";
207   DlgLegendGauss.widget=NULL;
208   DlgLegendGauss.resource="gauss";
209   DlgPage.widget=NULL;
210   DlgPage.resource="page";
211   DlgSwitch.widget=NULL;
212   DlgSwitch.resource="drawobj";
213   DlgDirectory.widget=NULL;
214   DlgDirectory.resource="directory";
215   DlgLoad.widget=NULL;
216   DlgLoad.resource="load";
217   DlgPrm.widget=NULL;
218   DlgPrm.resource="loadprm";
219   DlgSave.widget=NULL;
220   DlgSave.resource="save";
221   DlgAbout.widget=NULL;
222   DlgAbout.resource="about";
223   DlgDriver.widget=NULL;
224   DlgDriver.resource="driver";
225   DlgPrinter.widget=NULL;
226   DlgPrinter.resource="print";
227   DlgOutputData.widget=NULL;
228   DlgOutputData.resource="outputdata";
229   DlgScript.widget=NULL;
230   DlgScript.resource="addin";
231   DlgDefault.widget=NULL;
232   DlgDefault.resource="savedefault";
233   DlgSetScript.widget=NULL;
234   DlgSetScript.resource="setscript";
235   DlgPrefScript.widget=NULL;
236   DlgPrefScript.resource="prefscript";
237   DlgSetDriver.widget=NULL;
238   DlgSetDriver.resource="setdriver";
239   DlgPrefDriver.widget=NULL;
240   DlgPrefDriver.resource="prefdriver";
241   DlgMisc.widget=NULL;
242   DlgMisc.resource="misc";
243   DlgExViewer.widget=NULL;
244   DlgExViewer.resource="extviewer";
245   DlgViewer.widget=NULL;
246   DlgViewer.resource="viewer";
247   DlgSelect.widget=NULL;
248   DlgSelect.resource="multi_select";
249   DlgCopy.widget=NULL;
250   DlgCopy.resource="single_select";
251 }
252 
SelectDialogAllCB(Widget w,XtPointer client_data,XtPointer call_data)253 void SelectDialogAllCB(Widget w,XtPointer client_data,XtPointer call_data)
254 {
255   struct SelectDialog *data;
256 
257   data=(struct SelectDialog *)client_data;
258   data->ret=IDSALL;
259   data->CloseWindow(XtParent(w),data);
260 }
261 
SelectDialogDblCB(Widget w,XtPointer client_data,XtPointer call_data)262 void SelectDialogDblCB(Widget w,XtPointer client_data,XtPointer call_data)
263 {
264   struct SelectDialog *data;
265 
266   data=(struct SelectDialog *)client_data;
267   data->ret=IDOK;
268   data->CloseWindow(XtParent(w),data);
269 }
270 
SelectDialogSetup(Widget w,void * data,int makewidget)271 void SelectDialogSetup(Widget w,void *data,int makewidget)
272 {
273   Arg al[20];
274   Cardinal ac;
275   XmString xs;
276   char *s;
277   struct SelectDialog *d;
278   int i,*seldata,selnum;
279   Widget list,button;
280 
281   d=(struct SelectDialog *)data;
282   if (makewidget) {
283     ac=0;
284     XtSetArg(al[ac],XmNlistSizePolicy,XmCONSTANT); ac++;
285     XtSetArg(al[ac],XmNscrollBarDisplayPolicy,XmSTATIC); ac++;
286     XtSetArg(al[ac],XmNselectionPolicy,XmEXTENDED_SELECT); ac++;
287     XtManageChild(list=XmCreateScrolledList(w,"list",al,ac));
288     XtAddCallback(list,XmNdefaultActionCallback,SelectDialogDblCB,data);
289     ac=0;
290     XtManageChild(button=XmCreatePushButton(w,"All",al,ac));
291     XtAddCallback(button,XmNdisarmCallback,SelectDialogAllCB,data);
292   }
293   XmListDeleteAllItems(XtNameToWidget(w,"*list"));
294   for (i=0;i<=chkobjlastinst(d->Obj);i++) {
295     s=d->cb(d->Obj,i);
296     if (s!=NULL) xs=XmStringCreateLocalized(s);
297     else xs=XmStringCreateLocalized("");
298     XmListAddItem(XtNameToWidget(w,"*list"),xs,0);
299     XmStringFree(xs);
300     memfree(s);
301   }
302   if (makewidget) {
303     XtManageChild(d->widget);
304     d->widget=NULL;
305     XtVaSetValues(XtNameToWidget(w,"*list"),XmNwidth,200,NULL);
306   }
307   if (d->isel!=NULL) {
308     seldata=arraydata(d->isel);
309     selnum=arraynum(d->isel);
310     XtVaSetValues(XtNameToWidget(w,"*list"),
311                   XmNselectionPolicy,XmMULTIPLE_SELECT,NULL);
312     for (i=0;i<selnum;i++) {
313       XmListSelectPos(XtNameToWidget(w,"*list"),seldata[i]+1,FALSE);
314     }
315     XtVaSetValues(XtNameToWidget(w,"*list"),
316                   XmNselectionPolicy,XmEXTENDED_SELECT,NULL);
317   }
318 }
319 
SelectDialogClose(Widget w,void * data)320 void SelectDialogClose(Widget w,void *data)
321 {
322   int i,a;
323   struct SelectDialog *d;
324   int num;
325   int *selected;
326 
327   d=(struct SelectDialog *)data;
328   if (d->ret==IDOK) {
329     XmListGetSelectedPos(XtNameToWidget(w,"*list"),&selected,&num);
330     if (num!=0) {
331       for (i=0;i<num;i++) {
332         a=selected[i]-1;
333         arrayadd(d->sel,&a);
334       }
335       XtFree((char *)selected);
336     }
337   } else if (d->ret==IDSALL) {
338     for (i=0;i<=chkobjlastinst(d->Obj);i++) arrayadd(d->sel,&i);
339     d->ret=IDOK;
340   }
341 }
342 
SelectDialog(struct SelectDialog * data,struct objlist * obj,char * (* callback)(struct objlist * obj,int id),struct narray * array,struct narray * iarray)343 void SelectDialog(struct SelectDialog *data,
344                   struct objlist *obj,
345                   char *(*callback)(struct objlist *obj,int id),
346                   struct narray *array,struct narray *iarray)
347 {
348   data->SetupWindow=SelectDialogSetup;
349   data->CloseWindow=SelectDialogClose;
350   data->Obj=obj;
351   data->cb=callback;
352   arrayinit(array,sizeof(int));
353   data->sel=array;
354   data->isel=iarray;
355 }
356 
CopyDialogDblCB(Widget w,XtPointer client_data,XtPointer call_data)357 void CopyDialogDblCB(Widget w,XtPointer client_data,XtPointer call_data)
358 {
359   struct SelectDialog *data;
360   XmListCallbackStruct *d;
361 
362   data=(struct SelectDialog *)client_data;
363   d=(XmListCallbackStruct *)call_data;
364   data->ret=IDOK;
365   data->CloseWindow(XtParent(w),data);
366 }
367 
CopyDialogSetup(Widget w,void * data,int makewidget)368 void CopyDialogSetup(Widget w,void *data,int makewidget)
369 {
370   Arg al[20];
371   Cardinal ac;
372   XmString xs;
373   char *s;
374   struct CopyDialog *d;
375   int i;
376   Widget list;
377 
378   d=(struct CopyDialog *)data;
379   if (makewidget) {
380     ac=0;
381     XtSetArg(al[ac],XmNlistSizePolicy,XmCONSTANT); ac++;
382     XtSetArg(al[ac],XmNscrollBarDisplayPolicy,XmSTATIC); ac++;
383     XtSetArg(al[ac],XmNselectionPolicy,XmBROWSE_SELECT); ac++;
384     XtManageChild(list=XmCreateScrolledList(w,"list",al,ac));
385     XtAddCallback(list,XmNdefaultActionCallback,CopyDialogDblCB,data);
386   }
387   XmListDeleteAllItems(XtNameToWidget(w,"*list"));
388   for (i=0;i<=chkobjlastinst(d->Obj);i++) {
389     s=d->cb(d->Obj,i);
390     if (s!=NULL) xs=XmStringCreateLocalized(s);
391     else xs=XmStringCreateLocalized("");
392     XmListAddItem(XtNameToWidget(w,"*list"),xs,0);
393     XmStringFree(xs);
394     memfree(s);
395   }
396   if (d->Id>=0)
397     XmListSelectPos(XtNameToWidget(w,"*list"),d->Id+1,FALSE);
398   if (makewidget) {
399     XtManageChild(d->widget);
400     d->widget=NULL;
401     XtVaSetValues(XtNameToWidget(w,"*list"),XmNwidth,200,NULL);
402   }
403 }
404 
CopyDialogClose(Widget w,void * data)405 void CopyDialogClose(Widget w,void *data)
406 {
407   struct CopyDialog *d;
408   int *selected;
409   int num;
410 
411   d=(struct CopyDialog *)data;
412   if (d->ret==IDCANCEL) return;
413   XmListGetSelectedPos(XtNameToWidget(w,"*list"),&selected,&num);
414   if (num!=0) {
415     d->sel=selected[0]-1;
416     XtFree((char *)selected);
417   } else d->sel=-1;
418 }
419 
CopyDialog(struct CopyDialog * data,struct objlist * obj,int id,char * (* callback)(struct objlist * obj,int id))420 void CopyDialog(struct CopyDialog *data,
421                   struct objlist *obj,int id,
422                   char *(*callback)(struct objlist *obj,int id))
423 {
424   data->SetupWindow=CopyDialogSetup;
425   data->CloseWindow=CopyDialogClose;
426   data->Obj=obj;
427   data->Id=id;
428   data->cb=callback;
429   data->sel=id;
430 }
431 
CopyClick(Widget parent,struct objlist * obj,int Id,char * (* callback)(struct objlist * obj,int id))432 int CopyClick(Widget parent,struct objlist *obj,int Id,
433               char *(*callback)(struct objlist *obj,int id))
434 {
435   int sel;
436 
437   CopyDialog(&DlgCopy,obj,Id,callback);
438   if (DialogExecute(parent,&DlgCopy)==IDOK) sel=DlgCopy.sel;
439   else sel=-1;
440   return sel;
441 }
442 
SetObjFieldFromText(Widget w,char * res,struct objlist * Obj,int Id,char * field)443 int SetObjFieldFromText(Widget w,char *res,struct objlist *Obj,int Id,
444                         char *field)
445 {
446   char *buf;
447 
448   if (res==NULL) XtVaGetValues(w,XmNvalue,&buf,NULL);
449   else XtVaGetValues(XtNameToWidget(w,res),XmNvalue,&buf,NULL);
450   if (sputobjfield(Obj,Id,field,buf)!=0) {
451     XtFree(buf);
452     return -1;
453   }
454   XtFree(buf);
455   return 0;
456 }
457 
SetTextFromObjField(Widget w,char * res,struct objlist * Obj,int Id,char * field)458 void SetTextFromObjField(Widget w,char *res,struct objlist *Obj,int Id,
459                          char *field)
460 {
461   char *buf;
462 
463   sgetobjfield(Obj,Id,field,NULL,&buf,FALSE,FALSE,FALSE);
464   if (res==NULL) XtVaSetValues(w,XmNvalue,buf,NULL);
465   else XtVaSetValues(XtNameToWidget(w,res),XmNvalue,buf,NULL);
466   memfree(buf);
467 }
468 
SetComboListFromObjField(Widget w,char * res,struct objlist * Obj,int Id,char * field)469 void SetComboListFromObjField(Widget w,char *res,struct objlist *Obj,int Id,
470                               char *field)
471 {
472   char *buf;
473   XmString xs;
474 
475   sgetobjfield(Obj,Id,field,NULL,&buf,FALSE,FALSE,FALSE);
476   if (buf!=NULL) {
477     xs=XmStringCreateLocalized(buf);
478     XmListSelectItem(w,xs,FALSE);
479     XmStringFree(xs);
480     memfree(buf);
481   }
482 }
483 
SetObjFieldFromToggle(Widget w,char * res,struct objlist * Obj,int Id,char * field)484 int SetObjFieldFromToggle(Widget w,char *res,struct objlist *Obj,int Id,
485                           char *field)
486 {
487   int a;
488 
489   a=XmToggleButtonGetState(XtNameToWidget(w,res));
490   a=a?TRUE:FALSE;
491   if (putobj(Obj,field,Id,&a)==-1) return -1;
492   return 0;
493 }
494 
SetToggleFromObjField(Widget w,char * res,struct objlist * Obj,int Id,char * field)495 void SetToggleFromObjField(Widget w,char *res,struct objlist *Obj,int Id,
496                            char *field)
497 {
498   int a;
499 
500   getobj(Obj,field,Id,0,NULL,&a);
501   XmToggleButtonSetState(XtNameToWidget(w,res),a,TRUE);
502 }
503 
SetObjFieldFromStyle(Widget w,char * res,struct objlist * Obj,int Id,char * field)504 int SetObjFieldFromStyle(Widget w,char *res,struct objlist *Obj,int Id,
505                          char *field)
506 {
507   int j;
508   char *buf;
509 
510   XtVaGetValues(GetComboBoxText(w,res),XmNvalue,&buf,NULL);
511   for (j=0;j<CLINESTYLE;j++) {
512     if (strcmp(buf,fwlinestyle[j])==0) {
513       if (sputobjfield(Obj,Id,field,fwlinestylelist[j])!=0) {
514         XtFree(buf);
515         return -1;
516       }
517       break;
518     }
519   }
520   if (j==CLINESTYLE) {
521     if (sputobjfield(Obj,Id,field,buf)!=0) {
522       XtFree(buf);
523       return -1;
524     }
525   }
526   XtFree(buf);
527   return 0;
528 }
529 
SetStyleFromObjField(Widget w,char * res,struct objlist * Obj,int Id,char * field)530 void SetStyleFromObjField(Widget w,char *res,struct objlist *Obj,int Id,
531                           char *field)
532 {
533   int i,j;
534   struct narray *array;
535   int stylenum;
536   int *style,a;
537   XmString xs;
538   char *s;
539   int count;
540 
541   XtVaGetValues(GetComboBoxList(w,res),XmNitemCount,&count,NULL);
542   if (count==0) {
543     XmListDeleteAllItems(GetComboBoxList(w,res));
544     for (j=0;j<CLINESTYLE;j++) {
545       xs=XmStringCreateLocalized(fwlinestyle[j]);
546       XmListAddItem(GetComboBoxList(w,res),xs,0);
547       XmStringFree(xs);
548     }
549     SetComboBoxVisibleItemCount(w,res,j);
550   }
551   getobj(Obj,field,Id,0,NULL,&array);
552   stylenum=arraynum(array);
553   style=(int *)arraydata(array);
554   for (j=0;j<CLINESTYLE;j++) {
555     if (stylenum==fwlinestylelistn[j]) {
556       s=fwlinestylelist[j];
557       for (i=0;i<fwlinestylelistn[j];i++) {
558         a=strtol(s,&s,10);
559         if (style[i]!=a) break;
560       }
561       if (i==fwlinestylelistn[j]) goto match;
562     }
563   }
564   SetTextFromObjField(GetComboBoxText(w,res),NULL,Obj,Id,field);
565   return;
566 match:
567   XmListSelectPos(GetComboBoxList(w,res),j+1,TRUE);
568 }
569 
SetObjFieldFromList(Widget w,char * res,struct objlist * Obj,int Id,char * field)570 int SetObjFieldFromList(Widget w,char *res,struct objlist *Obj,int Id,
571                         char *field)
572 {
573   int *selected,pos,count;
574 
575   XmListGetSelectedPos(GetComboBoxList(w,res),&selected,&count);
576   if (count!=0) {
577     pos=selected[0]-1;
578     XtFree((char *)selected);
579     if (putobj(Obj,field,Id,&pos)==-1) return -1;
580   }
581   return 0;
582 }
583 
SetListFromObjField(Widget w,char * res,struct objlist * Obj,int Id,char * field)584 void SetListFromObjField(Widget w,char *res,struct objlist *Obj,int Id,
585                          char *field)
586 {
587   char **enumlist;
588   int j,a;
589   XmString xs;
590   int count;
591 
592   XtVaGetValues(GetComboBoxList(w,res),XmNitemCount,&count,NULL);
593   if (count==0) {
594     XmListDeleteAllItems(GetComboBoxList(w,res));
595     enumlist=(char **)chkobjarglist(Obj,field);
596     for (j=0;enumlist[j]!=NULL;j++) {
597       xs=XmStringCreateLocalized(enumlist[j]);
598       XmListAddItem(GetComboBoxList(w,res),xs,0);
599       XmStringFree(xs);
600     }
601     SetComboBoxVisibleItemCount(w,res,j);
602   }
603   getobj(Obj,field,Id,0,NULL,&a);
604   XmListSelectPos(GetComboBoxList(w,res),a+1,TRUE);
605 }
606 
SetComboList(Widget w,char * res,char ** list,int num)607 void SetComboList(Widget w,char *res,char **list,int num)
608 {
609   int j;
610   XmString xs;
611   int count;
612 
613   XtVaGetValues(GetComboBoxList(w,res),XmNitemCount,&count,NULL);
614   if (count==0) {
615     XmListDeleteAllItems(GetComboBoxList(w,res));
616     for (j=0;j<num;j++) {
617       xs=XmStringCreateLocalized(list[j]);
618       XmListAddItem(GetComboBoxList(w,res),xs,0);
619       XmStringFree(xs);
620     }
621     SetComboBoxVisibleItemCount(w,res,j);
622   }
623   XmListDeselectAllItems(GetComboBoxList(w,res));
624 }
625 
SetComboList2(Widget w,char * res,char ** list,int num)626 void SetComboList2(Widget w,char *res,char **list,int num)
627 {
628   int j;
629   XmString xs;
630 
631   XmListDeleteAllItems(GetComboBoxList(w,res));
632   for (j=0;j<num;j++) {
633     xs=XmStringCreateLocalized(list[j]);
634     XmListAddItem(GetComboBoxList(w,res),xs,0);
635     XmStringFree(xs);
636   }
637   SetComboBoxVisibleItemCount(w,res,j);
638   XmListDeselectAllItems(GetComboBoxList(w,res));
639 }
640 
GetComboBoxText(Widget w,char * res)641 Widget GetComboBoxText(Widget w,char *res)
642 {
643   if (res==NULL) return XtNameToWidget(w,COMBOTEXT);
644   else return XtNameToWidget(XtNameToWidget(w,res),COMBOTEXT);
645 }
646 
GetComboBoxList(Widget w,char * res)647 Widget GetComboBoxList(Widget w,char *res)
648 {
649   if (res==NULL) return XtNameToWidget(w,COMBOLIST);
650   else return XtNameToWidget(XtNameToWidget(w,res),COMBOLIST);
651 }
652 
SetComboBoxVisibleItemCount(Widget w,char * res,int count)653 void SetComboBoxVisibleItemCount(Widget w,char *res,int count)
654 {
655   if ((count<=0) || (count>30)) count=10;
656   XtVaSetValues(GetComboBoxList(w,res),XmNvisibleItemCount,count-1,NULL);
657 }
658