1 /*
2  * $Id: x11axis.c,v 1.10 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: x11axis.c,v $
27  * Revision 1.10  2003/02/16 12:43:37  isizaka
28  * for release 6.13.18
29  *
30  * Revision 1.9  2002/07/06 08:57:25  isizaka
31  * change to GPL.
32  *
33  * Revision 1.8  2001/03/23 12:17:43  isizaka
34  * for 6.3.13
35  *
36  * Revision 1.7  2000/10/28 14:48:05  isizaka
37  * AxisDialogFile: type is preserved.
38  *
39  * Revision 1.6  1999/05/08 13:31:30  isizaka
40  * for release 6.03.02
41  *
42  * Revision 1.5  1999/04/15 12:14:26  isizaka
43  * for release 6.03.01
44  *
45  * Revision 1.4  1999/04/11 06:09:20  isizaka
46  * *** empty log message ***
47  *
48  * Revision 1.3  1999/03/21 12:51:03  isizaka
49  * change axis initialization
50  *
51  * Revision 1.2  1999/03/20 12:32:54  isizaka
52  * use ComboBox for axis setting
53  *
54  * Revision 1.1  1999/03/17 13:28:29  isizaka
55  * Initial revision
56  *
57  *
58  **/
59 
60 #include <Xm/XmAll.h>
61 #include <X11/keysym.h>
62 #include <stdlib.h>
63 #include <stdio.h>
64 #include <unistd.h>
65 
66 #include "motif12.h"
67 
68 #include "ngraph.h"
69 #include "object.h"
70 #include "nstring.h"
71 
72 #include "x11gui.h"
73 #include "x11dialg.h"
74 #include "x11menu.h"
75 #include "ox11menu.h"
76 #include "x11graph.h"
77 #include "x11file.h"
78 #include "x11view.h"
79 #include "x11axis.h"
80 #include "x11commn.h"
81 
AxisCB(struct objlist * obj,int id)82 char *AxisCB(struct objlist *obj,int id)
83 {
84   char *s;
85   int dir;
86   char *valstr;
87   char *name;
88 
89   if ((s=(char *)memalloc(128))==NULL) return NULL;
90   getobj(obj,"direction",id,0,NULL,&dir);
91   getobj(obj,"group",id,0,NULL,&name);
92   if (name==NULL) name="";
93   sgetobjfield(obj,id,"type",NULL,&valstr,FALSE,FALSE,FALSE);
94   sprintf(s,"%-5d %-10s %.6s dir:%d",id,name,valstr,dir);
95   memfree(valstr);
96   return s;
97 }
98 
GridCB(struct objlist * obj,int id)99 char *GridCB(struct objlist *obj,int id)
100 {
101   char *s,*s1,*s2;
102 
103   if ((s=(char *)memalloc(128))==NULL) return NULL;
104   getobj(obj,"axis_x",id,0,NULL,&s1);
105   getobj(obj,"axis_y",id,0,NULL,&s2);
106   sprintf(s,"%-5d %.8s %.8s",id,s1,s2);
107   return s;
108 }
109 
GridDialogSetupItem(Widget w,struct GridDialog * d,int id)110 void GridDialogSetupItem(Widget w,struct GridDialog *d,int id)
111 {
112   char *valstr;
113   int i,j;
114   int lastinst;
115   struct objlist *aobj;
116   char *name;
117   XmString xs;
118 
119   aobj=getobject("axis");
120   lastinst=chkobjlastinst(aobj);
121   XmListDeleteAllItems(GetComboBoxList(w,"*axisx"));
122   XmListDeleteAllItems(GetComboBoxList(w,"*axisy"));
123   for (j=0;j<=lastinst;j++) {
124     getobj(aobj,"group",j,0,NULL,&name);
125     if (name==NULL) name="";
126     xs=XmStringCreateLocalized(name);
127     XmListAddItem(GetComboBoxList(w,"*axisx"),xs,0);
128     XmListAddItem(GetComboBoxList(w,"*axisy"),xs,0);
129     XmStringFree(xs);
130   }
131   SetComboBoxVisibleItemCount(w,"*axisx",j);
132   SetComboBoxVisibleItemCount(w,"*axisy",j);
133   sgetobjfield(d->Obj,id,"axis_x",NULL,&valstr,FALSE,FALSE,FALSE);
134   for (i=0;(valstr[i]!='\0') && (valstr[i]!=':');i++);
135   if (valstr[i]==':') i++;
136   XtVaSetValues(GetComboBoxText(w,"*axisx"),XmNvalue,valstr+i,NULL);
137   memfree(valstr);
138   sgetobjfield(d->Obj,id,"axis_y",NULL,&valstr,FALSE,FALSE,FALSE);
139   for (i=0;(valstr[i]!='\0') && (valstr[i]!=':');i++);
140   if (valstr[i]==':') i++;
141   XtVaSetValues(GetComboBoxText(w,"*axisy"),XmNvalue,valstr+i,NULL);
142   memfree(valstr);
143   SetStyleFromObjField(w,"*style1",d->Obj,id,"style1");
144   SetStyleFromObjField(w,"*style2",d->Obj,id,"style2");
145   SetStyleFromObjField(w,"*style3",d->Obj,id,"style3");
146   SetComboList(w,"*wid1",cblinewidth,CBLINEWIDTH);
147   SetTextFromObjField(GetComboBoxText(w,"*wid1"),NULL,d->Obj,id,"width1");
148   SetComboListFromObjField(GetComboBoxList(w,"*wid1"),NULL,d->Obj,id,"width1");
149   SetComboList(w,"*wid2",cblinewidth,CBLINEWIDTH);
150   SetTextFromObjField(GetComboBoxText(w,"*wid2"),NULL,d->Obj,id,"width2");
151   SetComboListFromObjField(GetComboBoxList(w,"*wid2"),NULL,d->Obj,id,"width2");
152   SetComboList(w,"*wid3",cblinewidth,CBLINEWIDTH);
153   SetTextFromObjField(GetComboBoxText(w,"*wid3"),NULL,d->Obj,id,"width3");
154   SetComboListFromObjField(GetComboBoxList(w,"*wid3"),NULL,d->Obj,id,"width3");
155   SetToggleFromObjField(w,"*Background",d->Obj,id,"background");
156   getobj(d->Obj,"R",id,0,NULL,&d->R);
157   getobj(d->Obj,"G",id,0,NULL,&d->G);
158   getobj(d->Obj,"B",id,0,NULL,&d->B);
159   XtVaSetValues(XtNameToWidget(w,"*col"),XmNbackground,RGB(d->R,d->G,d->B),NULL);
160   getobj(d->Obj,"BR",id,0,NULL,&d->R2);
161   getobj(d->Obj,"BG",id,0,NULL,&d->G2);
162   getobj(d->Obj,"BB",id,0,NULL,&d->B2);
163   XtVaSetValues(XtNameToWidget(w,"*colb"),XmNbackground,RGB(d->R2,d->G2,d->B2),NULL);
164 }
165 
GridDialogCopy(Widget w,XtPointer client_data,XtPointer call_data)166 void GridDialogCopy(Widget w,XtPointer client_data,XtPointer call_data)
167 {
168   struct GridDialog *d;
169   int sel;
170 
171   d=(struct GridDialog *)client_data;
172   if ((sel=CopyClick(d->widget,d->Obj,d->Id,GridCB))!=-1)
173     GridDialogSetupItem(d->widget,d,sel);
174 }
175 
GridDialogDelete(Widget w,XtPointer client_data,XtPointer call_data)176 void GridDialogDelete(Widget w,XtPointer client_data,XtPointer call_data)
177 {
178   struct GridDialog *d;
179 
180   d=(struct GridDialog *)client_data;
181   d->ret=IDDELETE;
182 }
183 
GridDialogAxisX(Widget w,XtPointer client_data,XtPointer call_data)184 void GridDialogAxisX(Widget w,XtPointer client_data,XtPointer call_data)
185 {
186   struct GridDialog *d;
187   XmComboBoxCallbackStruct *dd;
188   char buf[10];
189   int a,oid;
190   struct objlist *aobj;
191 
192   aobj=getobject("axis");
193   d=(struct GridDialog *)client_data;
194   dd=(XmComboBoxCallbackStruct *)call_data;
195 #ifdef ZEROBASECOMBOBOX
196   a=dd->item_position;
197 #else
198   a=dd->item_position-1;
199 #endif
200   if (a<0) return;
201   getobj(aobj,"oid",a,0,NULL,&oid);
202   sprintf(buf,"^%d",oid);
203   XtVaSetValues(GetComboBoxText(d->widget,"*axisx"),XmNvalue,buf,NULL);
204 }
205 
GridDialogAxisY(Widget w,XtPointer client_data,XtPointer call_data)206 void GridDialogAxisY(Widget w,XtPointer client_data,XtPointer call_data)
207 {
208   struct GridDialog *d;
209   XmComboBoxCallbackStruct *dd;
210   char buf[10];
211   int a,oid;
212   struct objlist *aobj;
213 
214   aobj=getobject("axis");
215   d=(struct GridDialog *)client_data;
216   dd=(XmComboBoxCallbackStruct *)call_data;
217 #ifdef ZEROBASECOMBOBOX
218   a=dd->item_position;
219 #else
220   a=dd->item_position-1;
221 #endif
222   if (a<0) return;
223   getobj(aobj,"oid",a,0,NULL,&oid);
224   sprintf(buf,"^%d",oid);
225   XtVaSetValues(GetComboBoxText(d->widget,"*axisy"),XmNvalue,buf,NULL);
226 }
227 
GridDialogColor(Widget w,XtPointer client_data,XtPointer call_data)228 void GridDialogColor(Widget w,XtPointer client_data,XtPointer call_data)
229 {
230   struct GridDialog *d;
231 
232   d=(struct GridDialog *)client_data;
233   GetColor(TopLevel,&d->R,&d->G,&d->B);
234   XtVaSetValues(w,XmNbackground,RGB(d->R,d->G,d->B),NULL);
235 }
236 
GridDialogColorB(Widget w,XtPointer client_data,XtPointer call_data)237 void GridDialogColorB(Widget w,XtPointer client_data,XtPointer call_data)
238 {
239   struct GridDialog *d;
240 
241   d=(struct GridDialog *)client_data;
242   GetColor(TopLevel,&d->R2,&d->G2,&d->B2);
243   XtVaSetValues(w,XmNbackground,RGB(d->R2,d->G2,d->B2),NULL);
244 }
245 
GridDialogSetup(Widget w,void * data,int makewidget)246 void GridDialogSetup(Widget w,void *data,int makewidget)
247 {
248   Arg al[20];
249   Cardinal ac;
250   Widget rc,rc2,rc3,frame,button,combo;
251   struct GridDialog *d;
252   XmString xs;
253   char title[25];
254 
255   d=(struct GridDialog *)data;
256   sprintf(title,"Grid %d",d->Id);
257   xs=XmStringCreateLocalized(title);
258   XtVaSetValues(w,XmNdialogTitle,xs,NULL);
259   XmStringFree(xs);
260 
261   d=(struct GridDialog *)data;
262   if (makewidget) {
263   ac=0;
264   XtManageChild(button=XmCreatePushButton(w,"Delete",al,ac));
265   XtAddCallback(button,XmNdisarmCallback,GridDialogDelete,d);
266   ac=0;
267   XtManageChild(button=XmCreatePushButton(w,"Copy",al,ac));
268   XtAddCallback(button,XmNdisarmCallback,GridDialogCopy,d);
269 
270   ac=0;
271   XtSetArg(al[ac],XmNorientation,XmVERTICAL); ac++;
272   XtManageChild(rc=XmCreateRowColumn(w,"rc",al,ac));
273 
274   ac=0;
275   XtManageChild(frame=XmCreateFrame(rc,"frame",al,ac));
276   ac=0;
277   XtSetArg(al[ac],XmNorientation,XmHORIZONTAL); ac++;
278   XtManageChild(rc2=XmCreateRowColumn(frame,"axisrc",al,ac));
279   ac=0;
280   XtManageChild(XmCreateLabel(rc2,"Axisx",al,ac));
281   ac=0;
282   XtSetArg(al[ac],XmNcomboBoxType,XmDROP_DOWN_COMBO_BOX); ac++;
283   XtManageChild(combo=XmCreateComboBox(rc2,"axisx",al,ac));
284   XtAddCallback(combo,XmNselectionCallback,GridDialogAxisX,d);
285   ac=0;
286   XtManageChild(XmCreateLabel(rc2,"Axisy",al,ac));
287   ac=0;
288   XtSetArg(al[ac],XmNcomboBoxType,XmDROP_DOWN_COMBO_BOX); ac++;
289   XtManageChild(combo=XmCreateComboBox(rc2,"axisy",al,ac));
290   XtAddCallback(combo,XmNselectionCallback,GridDialogAxisY,d);
291 
292   ac=0;
293   XtManageChild(frame=XmCreateFrame(rc,"frame2",al,ac));
294   ac=0;
295   XtSetArg(al[ac],XmNorientation,XmVERTICAL); ac++;
296   XtManageChild(rc2=XmCreateRowColumn(frame,"rc2",al,ac));
297 
298   ac=0;
299   XtSetArg(al[ac],XmNorientation,XmHORIZONTAL); ac++;
300   XtManageChild(rc3=XmCreateRowColumn(rc2,"style1rc",al,ac));
301   ac=0;
302   XtManageChild(XmCreateLabel(rc3,"Style1",al,ac));
303   ac=0;
304   XtSetArg(al[ac],XmNcomboBoxType,XmDROP_DOWN_COMBO_BOX); ac++;
305   XtManageChild(XmCreateComboBox(rc3,"style1",al,ac));
306   ac=0;
307   XtManageChild(XmCreateLabel(rc3,"Width1",al,ac));
308   ac=0;
309   XtSetArg(al[ac],XmNcomboBoxType,XmDROP_DOWN_COMBO_BOX); ac++;
310   XtManageChild(XmCreateComboBox(rc3,"wid1",al,ac));
311 
312   ac=0;
313   XtSetArg(al[ac],XmNorientation,XmHORIZONTAL); ac++;
314   XtManageChild(rc3=XmCreateRowColumn(rc2,"style2rc",al,ac));
315   ac=0;
316   XtManageChild(XmCreateLabel(rc3,"Style2",al,ac));
317   ac=0;
318   XtSetArg(al[ac],XmNcomboBoxType,XmDROP_DOWN_COMBO_BOX); ac++;
319   XtManageChild(XmCreateComboBox(rc3,"style2",al,ac));
320   ac=0;
321   XtManageChild(XmCreateLabel(rc3,"Width2",al,ac));
322   ac=0;
323   XtSetArg(al[ac],XmNcomboBoxType,XmDROP_DOWN_COMBO_BOX); ac++;
324   XtManageChild(XmCreateComboBox(rc3,"wid2",al,ac));
325 
326   ac=0;
327   XtSetArg(al[ac],XmNorientation,XmHORIZONTAL); ac++;
328   XtManageChild(rc3=XmCreateRowColumn(rc2,"style3rc",al,ac));
329   ac=0;
330   XtManageChild(XmCreateLabel(rc3,"Style3",al,ac));
331   ac=0;
332   XtSetArg(al[ac],XmNcomboBoxType,XmDROP_DOWN_COMBO_BOX); ac++;
333   XtManageChild(XmCreateComboBox(rc3,"style3",al,ac));
334   ac=0;
335   XtManageChild(XmCreateLabel(rc3,"Width3",al,ac));
336   ac=0;
337   XtSetArg(al[ac],XmNcomboBoxType,XmDROP_DOWN_COMBO_BOX); ac++;
338   XtManageChild(XmCreateComboBox(rc3,"wid3",al,ac));
339 
340   ac=0;
341   XtSetArg(al[ac],XmNorientation,XmHORIZONTAL); ac++;
342   XtManageChild(rc3=XmCreateRowColumn(rc2,"colorrc",al,ac));
343   ac=0;
344   XtManageChild(XmCreateLabel(rc3,"Color",al,ac));
345   ac=0;
346   XtManageChild(button=XmCreateDrawnButton(rc3,"col",al,ac));
347   XtAddCallback(button,XmNdisarmCallback,GridDialogColor,d);
348   ac=0;
349   XtManageChild(XmCreateToggleButton(rc3,"Background",al,ac));
350   ac=0;
351   XtManageChild(XmCreateLabel(rc3,"BackgroundColor",al,ac));
352   ac=0;
353   xs=XmStringCreateLocalized("   ");
354   XtSetArg(al[ac],XmNlabelString,xs); ac++;
355   XtManageChild(button=XmCreatePushButton(rc3,"colb",al,ac));
356   XtAddCallback(button,XmNdisarmCallback,GridDialogColorB,d);
357   XmStringFree(xs);
358   }
359 
360   GridDialogSetupItem(w,d,d->Id);
361 }
362 
GridDialogClose(Widget w,void * data)363 void GridDialogClose(Widget w,void *data)
364 {
365   struct GridDialog *d;
366   int ret;
367   char *s,*buf;
368   int len;
369 
370   d=(struct GridDialog *)data;
371   if (d->ret!=IDOK) return;
372   ret=d->ret;
373   d->ret=IDLOOP;
374   XtVaGetValues(GetComboBoxText(w,"*axisx"),XmNvalue,&s,NULL);
375   if ((s==NULL) || (strlen(s)==0)) {
376     if (sputobjfield(d->Obj,d->Id,"axis_x",NULL)!=0) return;
377   } else {
378     len=strlen(s);
379     if ((buf=(char *)memalloc(len+6))!=NULL) {
380       strcpy(buf,"axis:");
381       if (s!=NULL) strcat(buf,s);
382       if (sputobjfield(d->Obj,d->Id,"axis_x",buf)!=0) {
383         memfree(buf);
384         return;
385       }
386       memfree(buf);
387     }
388   }
389   XtFree(s);
390   XtVaGetValues(GetComboBoxText(w,"*axisy"),XmNvalue,&s,NULL);
391   if ((s==NULL) || (strlen(s)==0)) {
392     if (sputobjfield(d->Obj,d->Id,"axis_y",NULL)!=0) return;
393   } else {
394     len=strlen(s);
395     if ((buf=(char *)memalloc(len+6))!=NULL) {
396       strcpy(buf,"axis:");
397       if (s!=NULL) strcat(buf,s);
398       if (sputobjfield(d->Obj,d->Id,"axis_y",buf)!=0) {
399         memfree(buf);
400         return;
401       }
402       memfree(buf);
403     }
404   }
405   XtFree(s);
406   if (SetObjFieldFromStyle(w,"*style1",d->Obj,d->Id,"style1")) return;
407   if (SetObjFieldFromStyle(w,"*style2",d->Obj,d->Id,"style2")) return;
408   if (SetObjFieldFromStyle(w,"*style3",d->Obj,d->Id,"style3")) return;
409   if (SetObjFieldFromText(GetComboBoxText(w,"*wid1"),NULL,
410                           d->Obj,d->Id,"width1")) return;
411   if (SetObjFieldFromText(GetComboBoxText(w,"*wid2"),NULL,
412                           d->Obj,d->Id,"width2")) return;
413   if (SetObjFieldFromText(GetComboBoxText(w,"*wid3"),NULL,
414                           d->Obj,d->Id,"width3")) return;
415   if (SetObjFieldFromToggle(w,"*Background",d->Obj,d->Id,"background")) return;
416   if (putobj(d->Obj,"R",d->Id,&(d->R))==-1) return;
417   if (putobj(d->Obj,"G",d->Id,&(d->G))==-1) return;
418   if (putobj(d->Obj,"B",d->Id,&(d->B))==-1) return;
419   if (putobj(d->Obj,"BR",d->Id,&(d->R2))==-1) return;
420   if (putobj(d->Obj,"BG",d->Id,&(d->G2))==-1) return;
421   if (putobj(d->Obj,"BB",d->Id,&(d->B2))==-1) return;
422   d->ret=ret;
423 }
424 
GridDialog(struct GridDialog * data,struct objlist * obj,int id)425 void GridDialog(struct GridDialog *data,struct objlist *obj,int id)
426 {
427   data->SetupWindow=GridDialogSetup;
428   data->CloseWindow=GridDialogClose;
429   data->Obj=obj;
430   data->Id=id;
431 }
432 
433 
SectionDialogSetupItem(Widget w,struct SectionDialog * d)434 void SectionDialogSetupItem(Widget w,struct SectionDialog *d)
435 {
436   char buf[256];
437   XmString xs;
438 
439   sprintf(buf,"%d",d->X);
440   XtVaSetValues(XtNameToWidget(w,"*x"),XmNvalue,buf,NULL);
441   sprintf(buf,"%d",d->Y);
442   XtVaSetValues(XtNameToWidget(w,"*y"),XmNvalue,buf,NULL);
443   if (d->IDX!=-1) sprintf(buf,"id:%d",d->IDX);
444   else buf[0]='\0';
445   xs=XmStringCreateLocalized(buf);
446   XtVaSetValues(XtNameToWidget(w,"*xid"),XmNlabelString,xs,NULL);
447   XmStringFree(xs);
448   if (d->IDY!=-1) sprintf(buf,"id:%d",d->IDY);
449   else buf[0]='\0';
450   xs=XmStringCreateLocalized(buf);
451   XtVaSetValues(XtNameToWidget(w,"*yid"),XmNlabelString,xs,NULL);
452   XmStringFree(xs);
453   if (d->IDU!=-1) sprintf(buf,"id:%d",d->IDU);
454   else buf[0]='\0';
455   xs=XmStringCreateLocalized(buf);
456   XtVaSetValues(XtNameToWidget(w,"*uid"),XmNlabelString,xs,NULL);
457   XmStringFree(xs);
458   if (d->IDR!=-1) sprintf(buf,"id:%d",d->IDR);
459   else buf[0]='\0';
460   xs=XmStringCreateLocalized(buf);
461   XtVaSetValues(XtNameToWidget(w,"*rid"),XmNlabelString,xs,NULL);
462   XmStringFree(xs);
463   if (*(d->IDG)!=-1) sprintf(buf,"id:%d",*(d->IDG));
464   else buf[0]='\0';
465   xs=XmStringCreateLocalized(buf);
466   XtVaSetValues(XtNameToWidget(w,"*gid"),XmNlabelString,xs,NULL);
467   XmStringFree(xs);
468   sprintf(buf,"%d",d->LenX);
469   XtVaSetValues(XtNameToWidget(w,"*width"),XmNvalue,buf,NULL);
470   sprintf(buf,"%d",d->LenY);
471   XtVaSetValues(XtNameToWidget(w,"*height"),XmNvalue,buf,NULL);
472 }
473 
SectionDialogDelete(Widget w,XtPointer client_data,XtPointer call_data)474 void SectionDialogDelete(Widget w,XtPointer client_data,XtPointer call_data)
475 {
476   struct SectionDialog *d;
477 
478   d=(struct SectionDialog *)client_data;
479   d->ret=IDDELETE;
480 }
481 
SectionDialogAxisX(Widget w,XtPointer client_data,XtPointer call_data)482 void SectionDialogAxisX(Widget w,XtPointer client_data,XtPointer call_data)
483 {
484   struct SectionDialog *d;
485 
486   d=(struct SectionDialog *)client_data;
487   if (d->IDX>=0) {
488     AxisDialog(&DlgAxis,d->Obj,d->IDX,FALSE);
489     DialogExecute(d->widget,&DlgAxis);
490   }
491 }
492 
SectionDialogAxisY(Widget w,XtPointer client_data,XtPointer call_data)493 void SectionDialogAxisY(Widget w,XtPointer client_data,XtPointer call_data)
494 {
495   struct SectionDialog *d;
496 
497   d=(struct SectionDialog *)client_data;
498   if (d->IDY>=0) {
499     AxisDialog(&DlgAxis,d->Obj,d->IDY,FALSE);
500     DialogExecute(d->widget,&DlgAxis);
501   }
502 }
503 
SectionDialogAxisU(Widget w,XtPointer client_data,XtPointer call_data)504 void SectionDialogAxisU(Widget w,XtPointer client_data,XtPointer call_data)
505 {
506   struct SectionDialog *d;
507 
508   d=(struct SectionDialog *)client_data;
509   if (d->IDU>=0) {
510     AxisDialog(&DlgAxis,d->Obj,d->IDU,FALSE);
511     DialogExecute(d->widget,&DlgAxis);
512   }
513 }
514 
SectionDialogAxisR(Widget w,XtPointer client_data,XtPointer call_data)515 void SectionDialogAxisR(Widget w,XtPointer client_data,XtPointer call_data)
516 {
517   struct SectionDialog *d;
518 
519   d=(struct SectionDialog *)client_data;
520   if (d->IDR>=0) {
521     AxisDialog(&DlgAxis,d->Obj,d->IDR,FALSE);
522     DialogExecute(d->widget,&DlgAxis);
523   }
524 }
525 
SectionDialogGrid(Widget w,XtPointer client_data,XtPointer call_data)526 void SectionDialogGrid(Widget w,XtPointer client_data,XtPointer call_data)
527 {
528   struct SectionDialog *d;
529   char *ref;
530   int oidx,oidy;
531 
532   d=(struct SectionDialog *)client_data;
533   if (*(d->IDG)==-1) {
534     if ((*(d->IDG)=newobj(d->Obj2))>=0) {
535       if ((ref=(char *)memalloc(15))!=NULL) {
536         getobj(d->Obj,"oid",d->IDX,0,NULL,&oidx);
537         sprintf(ref,"axis:^%d",oidx);
538         putobj(d->Obj2,"axis_x",*(d->IDG),ref);
539       }
540       if ((ref=(char *)memalloc(15))!=NULL) {
541         getobj(d->Obj,"oid",d->IDY,0,NULL,&oidy);
542         sprintf(ref,"axis:^%d",oidy);
543         putobj(d->Obj2,"axis_y",*(d->IDG),ref);
544       }
545     }
546   }
547   if (*(d->IDG)>=0) {
548     GridDialog(&DlgGrid,d->Obj2,*(d->IDG));
549     if (DialogExecute(d->widget,&DlgGrid)==IDDELETE) {
550       delobj(d->Obj2,*(d->IDG));
551       *(d->IDG)=-1;
552     }
553   }
554   SectionDialogSetupItem(d->widget,d);
555   NgraphApp.Changed=TRUE;
556 }
557 
SectionDialogSetup(Widget w,void * data,int makewidget)558 void SectionDialogSetup(Widget w,void *data,int makewidget)
559 {
560   Arg al[20];
561   Cardinal ac;
562   Widget rc,rc2,rc3,button;
563   struct SectionDialog *d;
564   XmString xs;
565 
566   d=(struct SectionDialog *)data;
567   if (makewidget) {
568   ac=0;
569   XtManageChild(button=XmCreatePushButton(w,"Delete",al,ac));
570   XtAddCallback(button,XmNdisarmCallback,SectionDialogDelete,d);
571 
572   ac=0;
573   XtSetArg(al[ac],XmNorientation,XmVERTICAL); ac++;
574   XtManageChild(rc=XmCreateRowColumn(w,"rc",al,ac));
575   ac=0;
576   XtSetArg(al[ac],XmNorientation,XmHORIZONTAL); ac++;
577   XtManageChild(rc2=XmCreateRowColumn(rc,"xrc",al,ac));
578   ac=0;
579   XtManageChild(XmCreateLabel(rc2,"X",al,ac));
580   ac=0;
581   XtManageChild(XmCreateTextField(rc2,"x",al,ac));
582   ac=0;
583   XtManageChild(XmCreateLabel(rc2,"Width",al,ac));
584   ac=0;
585   XtManageChild(XmCreateTextField(rc2,"width",al,ac));
586   ac=0;
587   XtSetArg(al[ac],XmNorientation,XmHORIZONTAL); ac++;
588   XtManageChild(rc2=XmCreateRowColumn(rc,"yrc",al,ac));
589   ac=0;
590   XtManageChild(XmCreateLabel(rc2,"Y",al,ac));
591   ac=0;
592   XtManageChild(XmCreateTextField(rc2,"y",al,ac));
593   ac=0;
594   XtManageChild(XmCreateLabel(rc2,"Height",al,ac));
595   ac=0;
596   XtManageChild(XmCreateTextField(rc2,"height",al,ac));
597 
598   ac=0;
599   XtSetArg(al[ac],XmNorientation,XmHORIZONTAL); ac++;
600   XtManageChild(rc2=XmCreateRowColumn(rc,"buttonrc",al,ac));
601 
602   ac=0;
603   XtSetArg(al[ac],XmNorientation,XmVERTICAL); ac++;
604   XtManageChild(rc3=XmCreateRowColumn(rc2,"bxrc",al,ac));
605   ac=0;
606   XtManageChild(button=XmCreatePushButton(rc3,"Xaxis",al,ac));
607   XtAddCallback(button,XmNdisarmCallback,SectionDialogAxisX,d);
608   ac=0;
609   xs=XmStringCreateLocalized("      ");
610   XtSetArg(al[ac],XmNlabelString,xs); ac++;
611   XtManageChild(XmCreateLabel(rc3,"xid",al,ac));
612   XmStringFree(xs);
613   ac=0;
614   XtSetArg(al[ac],XmNorientation,XmVERTICAL); ac++;
615   XtManageChild(rc3=XmCreateRowColumn(rc2,"byrc",al,ac));
616   ac=0;
617   XtManageChild(button=XmCreatePushButton(rc3,"Yaxis",al,ac));
618   XtAddCallback(button,XmNdisarmCallback,SectionDialogAxisY,d);
619   ac=0;
620   xs=XmStringCreateLocalized("      ");
621   XtSetArg(al[ac],XmNlabelString,xs); ac++;
622   XtManageChild(XmCreateLabel(rc3,"yid",al,ac));
623   XmStringFree(xs);
624   ac=0;
625   XtSetArg(al[ac],XmNorientation,XmVERTICAL); ac++;
626   XtManageChild(rc3=XmCreateRowColumn(rc2,"burc",al,ac));
627   ac=0;
628   XtManageChild(button=XmCreatePushButton(rc3,"Uaxis",al,ac));
629   XtAddCallback(button,XmNdisarmCallback,SectionDialogAxisU,d);
630   ac=0;
631   xs=XmStringCreateLocalized("      ");
632   XtSetArg(al[ac],XmNlabelString,xs); ac++;
633   XtManageChild(XmCreateLabel(rc3,"uid",al,ac));
634   XmStringFree(xs);
635   ac=0;
636   XtSetArg(al[ac],XmNorientation,XmVERTICAL); ac++;
637   XtManageChild(rc3=XmCreateRowColumn(rc2,"brrc",al,ac));
638   ac=0;
639   XtManageChild(button=XmCreatePushButton(rc3,"Raxis",al,ac));
640   XtAddCallback(button,XmNdisarmCallback,SectionDialogAxisR,d);
641   ac=0;
642   xs=XmStringCreateLocalized("      ");
643   XtSetArg(al[ac],XmNlabelString,xs); ac++;
644   XtManageChild(XmCreateLabel(rc3,"rid",al,ac));
645   XmStringFree(xs);
646   ac=0;
647   XtSetArg(al[ac],XmNorientation,XmVERTICAL); ac++;
648   XtManageChild(rc3=XmCreateRowColumn(rc2,"bgrc",al,ac));
649   ac=0;
650   XtManageChild(button=XmCreatePushButton(rc3,"Grid",al,ac));
651   XtAddCallback(button,XmNdisarmCallback,SectionDialogGrid,d);
652   ac=0;
653   xs=XmStringCreateLocalized("      ");
654   XtSetArg(al[ac],XmNlabelString,xs); ac++;
655   XtManageChild(XmCreateLabel(rc3,"gid",al,ac));
656   XmStringFree(xs);
657   }
658 
659   SectionDialogSetupItem(w,d);
660 }
661 
SectionDialogClose(Widget w,void * data)662 void SectionDialogClose(Widget w,void *data)
663 {
664   struct SectionDialog *d;
665   int ret;
666   int type,a;
667   char *buf,*endptr;
668   struct narray group;
669   char *argv[2];
670 
671   d=(struct SectionDialog *)data;
672   if (d->ret!=IDOK) return;
673   ret=d->ret;
674   d->ret=IDLOOP;
675   XtVaGetValues(XtNameToWidget(w,"*x"),XmNvalue,&buf,NULL);
676   a=strtol(buf,&endptr,10);
677   if (endptr[0]!='\0') {
678     XtFree(buf);
679     return;
680   }
681   d->X=a;
682   XtFree(buf);
683   XtVaGetValues(XtNameToWidget(w,"*y"),XmNvalue,&buf,NULL);
684   a=strtol(buf,&endptr,10);
685   if (endptr[0]!='\0') {
686     XtFree(buf);
687     return;
688   }
689   d->Y=a;
690   XtFree(buf);
691   XtVaGetValues(XtNameToWidget(w,"*width"),XmNvalue,&buf,NULL);
692   a=strtol(buf,&endptr,10);
693   if (endptr[0]!='\0') {
694     XtFree(buf);
695     return;
696   }
697   d->LenX=a;
698   XtFree(buf);
699   XtVaGetValues(XtNameToWidget(w,"*height"),XmNvalue,&buf,NULL);
700   a=strtol(buf,&endptr,10);
701   if (endptr[0]!='\0') {
702     XtFree(buf);
703     return;
704   }
705   d->LenY=a;
706   XtFree(buf);
707   if ((d->X!=d->X0) || (d->Y!=d->Y0)
708   || (d->LenX0!=d->LenX) || (d->LenY0!=d->LenY)) {
709     arrayinit(&group,sizeof(int));
710     if (d->Section) type=2;
711     else type=1;
712     arrayadd(&group,&type);
713     arrayadd(&group,&(d->IDX));
714     arrayadd(&group,&(d->IDY));
715     arrayadd(&group,&(d->IDU));
716     arrayadd(&group,&(d->IDR));
717     arrayadd(&group,&(d->X));
718     arrayadd(&group,&(d->Y));
719     arrayadd(&group,&(d->LenX));
720     arrayadd(&group,&(d->LenY));
721     argv[0]=(char *)&group;
722     argv[1]=NULL;
723     exeobj(d->Obj,"group_position",d->IDX,1,argv);
724     arraydel(&group);
725   }
726   d->ret=ret;
727 }
728 
SectionDialog(struct SectionDialog * data,int x,int y,int lenx,int leny,struct objlist * obj,int idx,int idy,int idu,int idr,struct objlist * obj2,int * idg,int section)729 void SectionDialog(struct SectionDialog *data,
730                    int x,int y,int lenx,int leny,
731                    struct objlist *obj,int idx,int idy,int idu,int idr,
732                    struct objlist *obj2,int *idg,int section)
733 {
734   data->SetupWindow=SectionDialogSetup;
735   data->CloseWindow=SectionDialogClose;
736   data->X0=data->X=x;
737   data->Y0=data->Y=y;
738   data->LenX0=data->LenX=lenx;
739   data->LenY0=data->LenY=leny;
740   data->Obj=obj;
741   data->Obj2=obj2;
742   data->IDX=idx;
743   data->IDY=idy;
744   data->IDU=idu;
745   data->IDR=idr;
746   data->IDG=idg;
747   data->Section=section;
748   data->MaxX=menulocal.PaperWidth*(10000.0/menulocal.PaperZoom);
749   data->MaxY=menulocal.PaperHeight*(10000.0/menulocal.PaperZoom);
750 }
751 
CrossDialogSetupItem(Widget w,struct CrossDialog * d)752 void CrossDialogSetupItem(Widget w,struct CrossDialog *d)
753 {
754   char buf[256];
755   XmString xs;
756 
757   sprintf(buf,"%d",d->X);
758   XtVaSetValues(XtNameToWidget(w,"*x"),XmNvalue,buf,NULL);
759   sprintf(buf,"%d",d->Y);
760   XtVaSetValues(XtNameToWidget(w,"*y"),XmNvalue,buf,NULL);
761   if (d->IDX!=-1) sprintf(buf,"id:%d",d->IDX);
762   else buf[0]='\0';
763   xs=XmStringCreateLocalized(buf);
764   XtVaSetValues(XtNameToWidget(w,"*xid"),XmNlabelString,xs,NULL);
765   XmStringFree(xs);
766   if (d->IDY!=-1) sprintf(buf,"id:%d",d->IDY);
767   else buf[0]='\0';
768   xs=XmStringCreateLocalized(buf);
769   XtVaSetValues(XtNameToWidget(w,"*yid"),XmNlabelString,xs,NULL);
770   XmStringFree(xs);
771   sprintf(buf,"%d",d->LenX);
772   XtVaSetValues(XtNameToWidget(w,"*width"),XmNvalue,buf,NULL);
773   sprintf(buf,"%d",d->LenY);
774   XtVaSetValues(XtNameToWidget(w,"*height"),XmNvalue,buf,NULL);
775 }
776 
CrossDialogDelete(Widget w,XtPointer client_data,XtPointer call_data)777 void CrossDialogDelete(Widget w,XtPointer client_data,XtPointer call_data)
778 {
779   struct CrossDialog *d;
780 
781   d=(struct CrossDialog *)client_data;
782   d->ret=IDDELETE;
783 }
784 
CrossDialogAxisX(Widget w,XtPointer client_data,XtPointer call_data)785 void CrossDialogAxisX(Widget w,XtPointer client_data,XtPointer call_data)
786 {
787   struct CrossDialog *d;
788 
789   d=(struct CrossDialog *)client_data;
790   if (d->IDX>=0) {
791     AxisDialog(&DlgAxis,d->Obj,d->IDX,FALSE);
792     DialogExecute(d->widget,&DlgAxis);
793   }
794 }
795 
CrossDialogAxisY(Widget w,XtPointer client_data,XtPointer call_data)796 void CrossDialogAxisY(Widget w,XtPointer client_data,XtPointer call_data)
797 {
798   struct CrossDialog *d;
799 
800   d=(struct CrossDialog *)client_data;
801   if (d->IDY>=0) {
802     AxisDialog(&DlgAxis,d->Obj,d->IDY,FALSE);
803     DialogExecute(d->widget,&DlgAxis);
804   }
805 }
806 
CrossDialogSetup(Widget w,void * data,int makewidget)807 void CrossDialogSetup(Widget w,void *data,int makewidget)
808 {
809   Arg al[20];
810   Cardinal ac;
811   Widget rc,rc2,rc3,button;
812   struct CrossDialog *d;
813   XmString xs;
814 
815   d=(struct CrossDialog *)data;
816   if (makewidget) {
817   ac=0;
818   XtManageChild(button=XmCreatePushButton(w,"Delete",al,ac));
819   XtAddCallback(button,XmNdisarmCallback,CrossDialogDelete,d);
820 
821   ac=0;
822   XtSetArg(al[ac],XmNorientation,XmVERTICAL); ac++;
823   XtManageChild(rc=XmCreateRowColumn(w,"rc",al,ac));
824   ac=0;
825   XtSetArg(al[ac],XmNorientation,XmHORIZONTAL); ac++;
826   XtManageChild(rc2=XmCreateRowColumn(rc,"xrc",al,ac));
827   ac=0;
828   XtManageChild(XmCreateLabel(rc2,"X",al,ac));
829   ac=0;
830   XtManageChild(XmCreateTextField(rc2,"x",al,ac));
831   ac=0;
832   XtManageChild(XmCreateLabel(rc2,"Width",al,ac));
833   ac=0;
834   XtManageChild(XmCreateTextField(rc2,"width",al,ac));
835   ac=0;
836   XtSetArg(al[ac],XmNorientation,XmHORIZONTAL); ac++;
837   XtManageChild(rc2=XmCreateRowColumn(rc,"yrc",al,ac));
838   ac=0;
839   XtManageChild(XmCreateLabel(rc2,"Y",al,ac));
840   ac=0;
841   XtManageChild(XmCreateTextField(rc2,"y",al,ac));
842   ac=0;
843   XtManageChild(XmCreateLabel(rc2,"Height",al,ac));
844   ac=0;
845   XtManageChild(XmCreateTextField(rc2,"height",al,ac));
846 
847   ac=0;
848   XtSetArg(al[ac],XmNorientation,XmHORIZONTAL); ac++;
849   XtManageChild(rc2=XmCreateRowColumn(rc,"buttonrc",al,ac));
850 
851   ac=0;
852   XtSetArg(al[ac],XmNorientation,XmVERTICAL); ac++;
853   XtManageChild(rc3=XmCreateRowColumn(rc2,"bxrc",al,ac));
854   ac=0;
855   XtManageChild(button=XmCreatePushButton(rc3,"Xaxis",al,ac));
856   XtAddCallback(button,XmNdisarmCallback,CrossDialogAxisX,d);
857   ac=0;
858   xs=XmStringCreateLocalized("      ");
859   XtSetArg(al[ac],XmNlabelString,xs); ac++;
860   XtManageChild(XmCreateLabel(rc3,"xid",al,ac));
861   XmStringFree(xs);
862   ac=0;
863   XtSetArg(al[ac],XmNorientation,XmVERTICAL); ac++;
864   XtManageChild(rc3=XmCreateRowColumn(rc2,"byrc",al,ac));
865   ac=0;
866   XtManageChild(button=XmCreatePushButton(rc3,"Yaxis",al,ac));
867   XtAddCallback(button,XmNdisarmCallback,CrossDialogAxisY,d);
868   ac=0;
869   xs=XmStringCreateLocalized("      ");
870   XtSetArg(al[ac],XmNlabelString,xs); ac++;
871   XtManageChild(XmCreateLabel(rc3,"yid",al,ac));
872   XmStringFree(xs);
873   }
874   CrossDialogSetupItem(w,d);
875 }
876 
CrossDialogClose(Widget w,void * data)877 void CrossDialogClose(Widget w,void *data)
878 {
879   struct CrossDialog *d;
880   int ret;
881   int type,a;
882   char *buf,*endptr;
883   struct narray group;
884   char *argv[2];
885 
886   d=(struct CrossDialog *)data;
887   if (d->ret!=IDOK) return;
888   ret=d->ret;
889   d->ret=IDLOOP;
890   XtVaGetValues(XtNameToWidget(w,"*x"),XmNvalue,&buf,NULL);
891   a=strtol(buf,&endptr,10);
892   if (endptr[0]!='\0') {
893     XtFree(buf);
894     return;
895   }
896   d->X=a;
897   XtFree(buf);
898   XtVaGetValues(XtNameToWidget(w,"*y"),XmNvalue,&buf,NULL);
899   a=strtol(buf,&endptr,10);
900   if (endptr[0]!='\0') {
901     XtFree(buf);
902     return;
903   }
904   d->Y=a;
905   XtFree(buf);
906   XtVaGetValues(XtNameToWidget(w,"*width"),XmNvalue,&buf,NULL);
907   a=strtol(buf,&endptr,10);
908   if (endptr[0]!='\0') {
909     XtFree(buf);
910     return;
911   }
912   d->LenX=a;
913   XtFree(buf);
914   XtVaGetValues(XtNameToWidget(w,"*height"),XmNvalue,&buf,NULL);
915   a=strtol(buf,&endptr,10);
916   if (endptr[0]!='\0') {
917     XtFree(buf);
918     return;
919   }
920   d->LenY=a;
921   XtFree(buf);
922   if ((d->X!=d->X0) || (d->Y!=d->Y0)
923   || (d->LenX!=d->LenX0) || (d->LenY!=d->LenY0)) {
924     arrayinit(&group,sizeof(int));
925     type=3;
926     arrayadd(&group,&type);
927     arrayadd(&group,&(d->IDX));
928     arrayadd(&group,&(d->IDY));
929     arrayadd(&group,&(d->X));
930     arrayadd(&group,&(d->Y));
931     arrayadd(&group,&(d->LenX));
932     arrayadd(&group,&(d->LenY));
933     argv[0]=(char *)&group;
934     argv[1]=NULL;
935     exeobj(d->Obj,"group_position",d->IDX,1,argv);
936     arraydel(&group);
937   }
938   if ((d->IDX!=-1) && (d->IDY!=-1)) {
939     exeobj(d->Obj,"adjust",d->IDX,0,NULL);
940     exeobj(d->Obj,"adjust",d->IDY,0,NULL);
941   }
942  d->ret=ret;
943 }
944 
CrossDialog(struct CrossDialog * data,int x,int y,int lenx,int leny,struct objlist * obj,int idx,int idy)945 void CrossDialog(struct CrossDialog *data,
946                  int x,int y,int lenx,int leny,
947                  struct objlist *obj,int idx,int idy)
948 {
949   data->SetupWindow=CrossDialogSetup;
950   data->CloseWindow=CrossDialogClose;
951   data->X0=data->X=x;
952   data->Y0=data->Y=y;
953   data->LenX0=data->LenX=lenx;
954   data->LenY0=data->LenY=leny;
955   data->Obj=obj;
956   data->IDX=idx;
957   data->IDY=idy;
958   data->MaxX=menulocal.PaperWidth*(10000.0/menulocal.PaperZoom);
959   data->MaxY=menulocal.PaperHeight*(10000.0/menulocal.PaperZoom);
960 }
961 
ZoomDialogSetupItem(Widget w,struct ZoomDialog * d)962 void ZoomDialogSetupItem(Widget w,struct ZoomDialog *d)
963 {
964   char buf[64];
965 
966   sprintf(buf,"%d",d->zoom);
967   XtVaSetValues(XtNameToWidget(w,"*zoom"),XmNvalue,buf,NULL);
968 }
969 
ZoomDialogSetup(Widget w,void * data,int makewidget)970 void ZoomDialogSetup(Widget w,void *data,int makewidget)
971 {
972   Arg al[20];
973   Cardinal ac;
974   Widget rc;
975   struct ZoomDialog *d;
976 
977   d=(struct ZoomDialog *)data;
978   if (makewidget) {
979   ac=0;
980   XtSetArg(al[ac],XmNorientation,XmHORIZONTAL); ac++;
981   XtManageChild(rc=XmCreateRowColumn(w,"rc",al,ac));
982   ac=0;
983   XtManageChild(XmCreateLabel(rc,"Zoom",al,ac));
984   ac=0;
985   XtManageChild(XmCreateTextField(rc,"zoom",al,ac));
986   }
987   ZoomDialogSetupItem(w,d);
988 }
989 
ZoomDialogClose(Widget w,void * data)990 void ZoomDialogClose(Widget w,void *data)
991 {
992   struct ZoomDialog *d;
993   int ret,a;
994   char *buf,*endptr;
995 
996   d=(struct ZoomDialog *)data;
997   if (d->ret!=IDOK) return;
998   ret=d->ret;
999   d->ret=IDLOOP;
1000   XtVaGetValues(XtNameToWidget(w,"*zoom"),XmNvalue,&buf,NULL);
1001   a=strtol(buf,&endptr,10);
1002   if (endptr[0]=='\0') d->zoom=a;
1003   else {
1004     XtFree(buf);
1005     return;
1006   }
1007   XtFree(buf);
1008   d->ret=ret;
1009 }
1010 
ZoomDialog(struct ZoomDialog * data)1011 void ZoomDialog(struct ZoomDialog *data)
1012 {
1013   data->SetupWindow=ZoomDialogSetup;
1014   data->CloseWindow=ZoomDialogClose;
1015   data->zoom=20000;
1016 }
1017 
AxisBaseDialogSetupItem(Widget w,struct AxisBaseDialog * d,int id)1018 void AxisBaseDialogSetupItem(Widget w,struct AxisBaseDialog *d,int id)
1019 {
1020   SetStyleFromObjField(w,"*style",d->Obj,id,"style");
1021   SetComboList(w,"*width",cblinewidth,CBLINEWIDTH);
1022   SetTextFromObjField(GetComboBoxText(w,"*width"),NULL,d->Obj,id,"width");
1023   SetComboListFromObjField(GetComboBoxList(w,"*width"),NULL,d->Obj,id,"width");
1024   SetToggleFromObjField(w,"*Baseline",d->Obj,id,"baseline");
1025   SetListFromObjField(w,"*arrow",d->Obj,id,"arrow");
1026   SetTextFromObjField(w,"*arrowlen",d->Obj,id,"arrow_length");
1027   SetTextFromObjField(w,"*arrowwid",d->Obj,id,"arrow_width");
1028   SetListFromObjField(w,"*wave",d->Obj,id,"wave");
1029   SetTextFromObjField(w,"*wavelen",d->Obj,id,"wave_length");
1030   SetComboList(w,"*wavewid",cblinewidth,CBLINEWIDTH);
1031   SetTextFromObjField(GetComboBoxText(w,"*wavewid"),NULL,
1032                       d->Obj,id,"wave_width");
1033   SetComboListFromObjField(GetComboBoxList(w,"*wavewid"),NULL,
1034                       d->Obj,id,"wave_width");
1035   getobj(d->Obj,"R",id,0,NULL,&d->R);
1036   getobj(d->Obj,"G",id,0,NULL,&d->G);
1037   getobj(d->Obj,"B",id,0,NULL,&d->B);
1038   XtVaSetValues(XtNameToWidget(w,"*col"),XmNbackground,RGB(d->R,d->G,d->B),NULL);
1039 }
1040 
AxisBaseDialogColor(Widget w,XtPointer client_data,XtPointer call_data)1041 void AxisBaseDialogColor(Widget w,XtPointer client_data,XtPointer call_data)
1042 {
1043   struct AxisBaseDialog *d;
1044 
1045   d=(struct AxisBaseDialog *)client_data;
1046   GetColor(TopLevel,&d->R,&d->G,&d->B);
1047   XtVaSetValues(w,XmNbackground,RGB(d->R,d->G,d->B),NULL);
1048 }
1049 
AxisBaseDialogCopy(Widget w,XtPointer client_data,XtPointer call_data)1050 void AxisBaseDialogCopy(Widget w,XtPointer client_data,XtPointer call_data)
1051 {
1052   struct AxisBaseDialog *d;
1053   int sel;
1054 
1055   d=(struct AxisBaseDialog *)client_data;
1056   if ((sel=CopyClick(d->widget,d->Obj,d->Id,AxisCB))!=-1)
1057     AxisBaseDialogSetupItem(d->widget,d,sel);
1058 }
1059 
AxisBaseDialogSetup(Widget w,void * data,int makewidget)1060 void AxisBaseDialogSetup(Widget w,void *data,int makewidget)
1061 {
1062   Arg al[20];
1063   Cardinal ac;
1064   Widget rc,rc2,button;
1065   struct AxisBaseDialog *d;
1066 
1067   d=(struct AxisBaseDialog *)data;
1068   if (makewidget) {
1069   ac=0;
1070   XtManageChild(button=XmCreatePushButton(w,"Copy",al,ac));
1071   XtAddCallback(button,XmNdisarmCallback,AxisBaseDialogCopy,d);
1072   ac=0;
1073   XtSetArg(al[ac],XmNorientation,XmVERTICAL); ac++;
1074   XtManageChild(rc=XmCreateRowColumn(w,"rc",al,ac));
1075 
1076   ac=0;
1077   XtSetArg(al[ac],XmNorientation,XmHORIZONTAL); ac++;
1078   XtManageChild(rc2=XmCreateRowColumn(rc,"baselinerc",al,ac));
1079   ac=0;
1080   XtManageChild(XmCreateToggleButton(rc2,"Baseline",al,ac));
1081   ac=0;
1082   XtManageChild(XmCreateLabel(rc2,"Style",al,ac));
1083   ac=0;
1084   XtSetArg(al[ac],XmNcomboBoxType,XmDROP_DOWN_COMBO_BOX); ac++;
1085   XtManageChild(XmCreateComboBox(rc2,"style",al,ac));
1086   ac=0;
1087   XtManageChild(XmCreateLabel(rc2,"Width",al,ac));
1088   ac=0;
1089   XtSetArg(al[ac],XmNcomboBoxType,XmDROP_DOWN_COMBO_BOX); ac++;
1090   XtManageChild(XmCreateComboBox(rc2,"width",al,ac));
1091   ac=0;
1092   XtManageChild(XmCreateLabel(rc2,"Color",al,ac));
1093   ac=0;
1094   XtManageChild(button=XmCreateDrawnButton(rc2,"col",al,ac));
1095   XtAddCallback(button,XmNdisarmCallback,AxisBaseDialogColor,d);
1096 
1097   ac=0;
1098   XtSetArg(al[ac],XmNorientation,XmHORIZONTAL); ac++;
1099   XtManageChild(rc2=XmCreateRowColumn(rc,"arrowrc",al,ac));
1100   ac=0;
1101   XtManageChild(XmCreateLabel(rc2,"Arrow",al,ac));
1102   ac=0;
1103   XtSetArg(al[ac],XmNcomboBoxType,XmDROP_DOWN_LIST); ac++;
1104   XtManageChild(XmCreateComboBox(rc2,"arrow",al,ac));
1105   ac=0;
1106   XtManageChild(XmCreateLabel(rc2,"Length",al,ac));
1107   ac=0;
1108   XtManageChild(XmCreateTextField(rc2,"arrowlen",al,ac));
1109   ac=0;
1110   XtManageChild(XmCreateLabel(rc2,"Width",al,ac));
1111   ac=0;
1112   XtManageChild(XmCreateTextField(rc2,"arrowwid",al,ac));
1113 
1114   ac=0;
1115   XtSetArg(al[ac],XmNorientation,XmHORIZONTAL); ac++;
1116   XtManageChild(rc2=XmCreateRowColumn(rc,"waverc",al,ac));
1117   ac=0;
1118   XtManageChild(XmCreateLabel(rc2,"Wave",al,ac));
1119   ac=0;
1120   XtSetArg(al[ac],XmNcomboBoxType,XmDROP_DOWN_LIST); ac++;
1121   XtManageChild(XmCreateComboBox(rc2,"wave",al,ac));
1122   ac=0;
1123   XtManageChild(XmCreateLabel(rc2,"Length",al,ac));
1124   ac=0;
1125   XtManageChild(XmCreateTextField(rc2,"wavelen",al,ac));
1126   ac=0;
1127   XtManageChild(XmCreateLabel(rc2,"Width",al,ac));
1128   ac=0;
1129   XtSetArg(al[ac],XmNcomboBoxType,XmDROP_DOWN_COMBO_BOX); ac++;
1130   XtManageChild(XmCreateComboBox(rc2,"wavewid",al,ac));
1131   }
1132   AxisBaseDialogSetupItem(w,d,d->Id);
1133 }
1134 
AxisBaseDialogClose(Widget w,void * data)1135 void AxisBaseDialogClose(Widget w,void *data)
1136 {
1137   struct AxisBaseDialog *d;
1138   int ret;
1139 
1140   d=(struct AxisBaseDialog *)data;
1141   if (d->ret!=IDOK) return;
1142   ret=d->ret;
1143   d->ret=IDLOOP;
1144   if (SetObjFieldFromStyle(w,"*style",d->Obj,d->Id,"style")) return;
1145   if (SetObjFieldFromText(GetComboBoxText(w,"*width"),NULL,
1146                           d->Obj,d->Id,"width")) return;
1147   if (SetObjFieldFromToggle(w,"*Baseline",d->Obj,d->Id,"baseline")) return;
1148   if (SetObjFieldFromList(w,"*arrow",d->Obj,d->Id,"arrow")) return;
1149   if (SetObjFieldFromText(w,"*arrowlen",d->Obj,d->Id,"arrow_length")) return;
1150   if (SetObjFieldFromText(w,"*arrowwid",d->Obj,d->Id,"arrow_width")) return;
1151   if (SetObjFieldFromList(w,"*wave",d->Obj,d->Id,"wave")) return;
1152   if (SetObjFieldFromText(w,"*wavelen",d->Obj,d->Id,"wave_length")) return;
1153   if (SetObjFieldFromText(GetComboBoxText(w,"*wavewid"),NULL,
1154                           d->Obj,d->Id,"wave_width")) return;
1155   if (putobj(d->Obj,"R",d->Id,&(d->R))==-1) return;
1156   if (putobj(d->Obj,"G",d->Id,&(d->G))==-1) return;
1157   if (putobj(d->Obj,"B",d->Id,&(d->B))==-1) return;
1158   d->ret=ret;
1159 }
1160 
AxisBaseDialog(struct AxisBaseDialog * data,struct objlist * obj,int id)1161 void AxisBaseDialog(struct AxisBaseDialog *data,struct objlist *obj,int id)
1162 {
1163   data->SetupWindow=AxisBaseDialogSetup;
1164   data->CloseWindow=AxisBaseDialogClose;
1165   data->Obj=obj;
1166   data->Id=id;
1167 }
1168 
AxisPosDialogSetupItem(Widget w,struct AxisPosDialog * d,int id)1169 void AxisPosDialogSetupItem(Widget w,struct AxisPosDialog *d,int id)
1170 {
1171   char *valstr;
1172   int i,j;
1173   int lastinst;
1174   char *name;
1175   XmString xs;
1176 
1177   SetTextFromObjField(w,"*x",d->Obj,id,"x");
1178   SetTextFromObjField(w,"*y",d->Obj,id,"y");
1179   SetTextFromObjField(w,"*len",d->Obj,id,"length");
1180   SetComboList(w,"*direction",cbdirection,CBDIRECTION);
1181   SetTextFromObjField(GetComboBoxText(w,"*direction"),NULL,
1182                       d->Obj,id,"direction");
1183   SetComboListFromObjField(GetComboBoxList(w,"*direction"),NULL,
1184                       d->Obj,id,"direction");
1185   lastinst=chkobjlastinst(d->Obj);
1186   for (j=0;j<=lastinst;j++) {
1187     getobj(d->Obj,"group",j,0,NULL,&name);
1188     if (name==NULL) name="";
1189     xs=XmStringCreateLocalized(name);
1190     XmListAddItem(GetComboBoxList(w,"*adjust"),xs,0);
1191     XmStringFree(xs);
1192   }
1193   SetComboBoxVisibleItemCount(w,"*adjust",j);
1194   sgetobjfield(d->Obj,id,"adjust_axis",NULL,&valstr,FALSE,FALSE,FALSE);
1195   for (i=0;(valstr[i]!='\0') && (valstr[i]!=':');i++);
1196   if (valstr[i]==':') i++;
1197   XtVaSetValues(GetComboBoxText(w,"*adjust"),XmNvalue,valstr+i,NULL);
1198   memfree(valstr);
1199   SetTextFromObjField(w,"*adjustpos",d->Obj,id,"adjust_position");
1200 }
1201 
AxisPosDialogRef(Widget w,XtPointer client_data,XtPointer call_data)1202 void AxisPosDialogRef(Widget w,XtPointer client_data,XtPointer call_data)
1203 {
1204   struct AxisPosDialog *d;
1205   XmComboBoxCallbackStruct *dd;
1206   char buf[10];
1207   int a,oid;
1208 
1209   d=(struct AxisPosDialog *)client_data;
1210   dd=(XmComboBoxCallbackStruct *)call_data;
1211 #ifdef ZEROBASECOMBOBOX
1212   a=dd->item_position;
1213 #else
1214   a=dd->item_position-1;
1215 #endif
1216   if (a<0) return;
1217   getobj(d->Obj,"oid",a,0,NULL,&oid);
1218   sprintf(buf,"^%d",oid);
1219   XtVaSetValues(GetComboBoxText(d->widget,"*adjust"),XmNvalue,buf,NULL);
1220 }
1221 
AxisPosDialogCopy(Widget w,XtPointer client_data,XtPointer call_data)1222 void AxisPosDialogCopy(Widget w,XtPointer client_data,XtPointer call_data)
1223 {
1224   struct AxisPosDialog *d;
1225   int sel;
1226 
1227   d=(struct AxisPosDialog *)client_data;
1228   if ((sel=CopyClick(d->widget,d->Obj,d->Id,AxisCB))!=-1)
1229     AxisPosDialogSetupItem(d->widget,d,sel);
1230 }
1231 
AxisPosDialogSetup(Widget w,void * data,int makewidget)1232 void AxisPosDialogSetup(Widget w,void *data,int makewidget)
1233 {
1234   Arg al[20];
1235   Cardinal ac;
1236   Widget rc,rc2,button,combo;
1237   struct AxisPosDialog *d;
1238 
1239   d=(struct AxisPosDialog *)data;
1240   if (makewidget) {
1241   ac=0;
1242   XtManageChild(button=XmCreatePushButton(w,"Copy",al,ac));
1243   XtAddCallback(button,XmNdisarmCallback,AxisPosDialogCopy,d);
1244   ac=0;
1245   XtSetArg(al[ac],XmNorientation,XmVERTICAL); ac++;
1246   XtManageChild(rc=XmCreateRowColumn(w,"rc",al,ac));
1247   ac=0;
1248   XtSetArg(al[ac],XmNorientation,XmHORIZONTAL); ac++;
1249   XtManageChild(rc2=XmCreateRowColumn(rc,"rc1",al,ac));
1250   ac=0;
1251   XtManageChild(XmCreateLabel(rc2,"X",al,ac));
1252   ac=0;
1253   XtManageChild(XmCreateTextField(rc2,"x",al,ac));
1254   ac=0;
1255   XtManageChild(XmCreateLabel(rc2,"Y",al,ac));
1256   ac=0;
1257   XtManageChild(XmCreateTextField(rc2,"y",al,ac));
1258   ac=0;
1259   XtManageChild(XmCreateLabel(rc2,"Length",al,ac));
1260   ac=0;
1261   XtManageChild(XmCreateTextField(rc2,"len",al,ac));
1262   ac=0;
1263   XtManageChild(XmCreateLabel(rc2,"Dir",al,ac));
1264   ac=0;
1265   XtSetArg(al[ac],XmNcomboBoxType,XmDROP_DOWN_COMBO_BOX); ac++;
1266   XtManageChild(XmCreateComboBox(rc2,"direction",al,ac));
1267 
1268   ac=0;
1269   XtSetArg(al[ac],XmNorientation,XmHORIZONTAL); ac++;
1270   XtManageChild(rc2=XmCreateRowColumn(rc,"rc2",al,ac));
1271   ac=0;
1272   XtManageChild(XmCreateLabel(rc2,"Adjust",al,ac));
1273   ac=0;
1274   XtSetArg(al[ac],XmNcomboBoxType,XmDROP_DOWN_COMBO_BOX); ac++;
1275   XtManageChild(combo=XmCreateComboBox(rc2,"adjust",al,ac));
1276   XtAddCallback(combo,XmNselectionCallback,AxisPosDialogRef,d);
1277   ac=0;
1278   XtManageChild(XmCreateLabel(rc2,"AdjustPosition",al,ac));
1279   ac=0;
1280   XtManageChild(XmCreateTextField(rc2,"adjustpos",al,ac));
1281   }
1282 
1283   AxisPosDialogSetupItem(w,d,d->Id);
1284 }
1285 
AxisPosDialogClose(Widget w,void * data)1286 void AxisPosDialogClose(Widget w,void *data)
1287 {
1288   struct AxisPosDialog *d;
1289   int ret;
1290   char *s,*buf;
1291   int len;
1292 
1293   d=(struct AxisPosDialog *)data;
1294   if (d->ret!=IDOK) return;
1295   ret=d->ret;
1296   d->ret=IDLOOP;
1297   if (SetObjFieldFromText(w,"*x",d->Obj,d->Id,"x")) return;
1298   if (SetObjFieldFromText(w,"*y",d->Obj,d->Id,"y")) return;
1299   if (SetObjFieldFromText(w,"*len",d->Obj,d->Id,"length")) return;
1300   if (SetObjFieldFromText(GetComboBoxText(w,"*direction"),NULL,
1301                           d->Obj,d->Id,"direction")) return;
1302   XtVaGetValues(GetComboBoxText(w,"*adjust"),XmNvalue,&s,NULL);
1303   if ((s==NULL) || (strlen(s)==0)) {
1304     if (sputobjfield(d->Obj,d->Id,"adjust_axis",NULL)!=0) return;
1305   } else {
1306     len=strlen(s);
1307     if ((buf=(char *)memalloc(len+6))!=NULL) {
1308       strcpy(buf,"axis:");
1309       if (s!=NULL) strcat(buf,s);
1310       if (sputobjfield(d->Obj,d->Id,"adjust_axis",buf)!=0) {
1311         memfree(buf);
1312         return;
1313       }
1314       memfree(buf);
1315     }
1316   }
1317   XtFree(s);
1318   if (SetObjFieldFromText(w,"*adjustpos",d->Obj,d->Id,"adjust_position"))
1319     return;
1320   d->ret=ret;
1321 }
1322 
AxisPosDialog(struct AxisPosDialog * data,struct objlist * obj,int id)1323 void AxisPosDialog(struct AxisPosDialog *data,struct objlist *obj,int id)
1324 {
1325   data->SetupWindow=AxisPosDialogSetup;
1326   data->CloseWindow=AxisPosDialogClose;
1327   data->Obj=obj;
1328   data->Id=id;
1329 }
1330 
NumDialogSetupItem(Widget w,struct NumDialog * d,int id)1331 void NumDialogSetupItem(Widget w,struct NumDialog *d,int id)
1332 {
1333   char *format,*endptr;
1334   int j,a;
1335   XmString xs;
1336 
1337   SetListFromObjField(w,"*num",d->Obj,id,"num");
1338   SetTextFromObjField(w,"*begin",d->Obj,id,"num_begin");
1339   SetTextFromObjField(w,"*step",d->Obj,id,"num_step");
1340   SetTextFromObjField(w,"*numnum",d->Obj,id,"num_num");
1341   SetTextFromObjField(w,"*head",d->Obj,id,"num_head");
1342   XmListDeleteAllItems(GetComboBoxList(w,"*fraction"));
1343   for (j=0;j<CNUMSTYLE;j++) {
1344     xs=XmStringCreateLocalized(fwnumstyle[j]);
1345     XmListAddItem(GetComboBoxList(w,"*fraction"),xs,0);
1346     XmStringFree(xs);
1347   }
1348   SetComboBoxVisibleItemCount(w,"*fraction",j);
1349   getobj(d->Obj,"num_format",id,0,NULL,&format);
1350   if (strchr(format,'+')!=NULL)
1351      XmToggleButtonSetState(XtNameToWidget(w,"*Add_plus"),TRUE,TRUE);
1352   else
1353      XmToggleButtonSetState(XtNameToWidget(w,"*Add_plus"),FALSE,TRUE);
1354   if ((strchr(format,'f')==NULL) || (strchr(format,'.')==NULL)) a=0;
1355   else a=strtol(strchr(format,'.')+1,&endptr,10)+1;
1356   if (a<0) a=0;
1357   else if (a>10) a=10;
1358   XmListSelectPos(GetComboBoxList(w,"*fraction"),a+1,TRUE);
1359   SetTextFromObjField(w,"*tail",d->Obj,id,"num_tail");
1360   SetListFromObjField(w,"*align",d->Obj,id,"num_align");
1361   SetListFromObjField(w,"*direction",d->Obj,id,"num_direction");
1362   SetTextFromObjField(w,"*shiftp",d->Obj,id,"num_shift_p");
1363   SetTextFromObjField(w,"*shiftn",d->Obj,id,"num_shift_n");
1364   SetToggleFromObjField(w,"*Log_power",d->Obj,id,"num_log_pow");
1365   SetToggleFromObjField(w,"*No_zero",d->Obj,id,"num_no_zero");
1366   SetTextFromObjField(w,"*norm",d->Obj,id,"num_auto_norm");
1367 }
1368 
NumDialogCopy(Widget w,XtPointer client_data,XtPointer call_data)1369 void NumDialogCopy(Widget w,XtPointer client_data,XtPointer call_data)
1370 {
1371   struct NumDialog *d;
1372   int sel;
1373 
1374   d=(struct NumDialog *)client_data;
1375   if ((sel=CopyClick(d->widget,d->Obj,d->Id,AxisCB))!=-1)
1376     NumDialogSetupItem(d->widget,d,sel);
1377 }
1378 
NumDialogSetup(Widget w,void * data,int makewidget)1379 void NumDialogSetup(Widget w,void *data,int makewidget)
1380 {
1381   Arg al[20];
1382   Cardinal ac;
1383   Widget rc,rc2,rc3,button,frame;
1384   struct NumDialog *d;
1385 
1386   d=(struct NumDialog *)data;
1387   if (makewidget) {
1388   ac=0;
1389   XtManageChild(button=XmCreatePushButton(w,"Copy",al,ac));
1390   XtAddCallback(button,XmNdisarmCallback,NumDialogCopy,d);
1391 
1392   ac=0;
1393   XtSetArg(al[ac],XmNorientation,XmVERTICAL); ac++;
1394   XtManageChild(rc=XmCreateRowColumn(w,"rc",al,ac));
1395 
1396   ac=0;
1397   XtManageChild(frame=XmCreateFrame(rc,"frame",al,ac));
1398   ac=0;
1399   XtSetArg(al[ac],XmNorientation,XmVERTICAL); ac++;
1400   XtManageChild(rc3=XmCreateRowColumn(frame,"rc1",al,ac));
1401   ac=0;
1402   XtSetArg(al[ac],XmNorientation,XmHORIZONTAL); ac++;
1403   XtManageChild(rc2=XmCreateRowColumn(rc3,"numberrc",al,ac));
1404   ac=0;
1405   XtManageChild(XmCreateLabel(rc2,"Numbering",al,ac));
1406   ac=0;
1407   XtSetArg(al[ac],XmNcomboBoxType,XmDROP_DOWN_LIST); ac++;
1408   XtManageChild(XmCreateComboBox(rc2,"num",al,ac));
1409   ac=0;
1410   XtSetArg(al[ac],XmNorientation,XmHORIZONTAL); ac++;
1411   XtManageChild(rc2=XmCreateRowColumn(rc3,"numrc",al,ac));
1412   ac=0;
1413   XtManageChild(XmCreateLabel(rc2,"Begin",al,ac));
1414   ac=0;
1415   XtManageChild(XmCreateTextField(rc2,"begin",al,ac));
1416   ac=0;
1417   XtManageChild(XmCreateLabel(rc2,"Step",al,ac));
1418   ac=0;
1419   XtManageChild(XmCreateTextField(rc2,"step",al,ac));
1420   ac=0;
1421   XtManageChild(XmCreateLabel(rc2,"Num",al,ac));
1422   ac=0;
1423   XtManageChild(XmCreateTextField(rc2,"numnum",al,ac));
1424 
1425   ac=0;
1426   XtManageChild(frame=XmCreateFrame(rc,"frame2",al,ac));
1427   ac=0;
1428   XtSetArg(al[ac],XmNorientation,XmVERTICAL); ac++;
1429   XtManageChild(rc3=XmCreateRowColumn(frame,"rc2",al,ac));
1430   ac=0;
1431   XtSetArg(al[ac],XmNorientation,XmHORIZONTAL); ac++;
1432   XtManageChild(rc2=XmCreateRowColumn(rc3,"formatrc",al,ac));
1433   ac=0;
1434   XtManageChild(XmCreateLabel(rc2,"Format",al,ac));
1435   ac=0;
1436   XtManageChild(XmCreateToggleButton(rc2,"Add_plus",al,ac));
1437   ac=0;
1438   XtManageChild(XmCreateLabel(rc2,"Fraction",al,ac));
1439   ac=0;
1440   XtSetArg(al[ac],XmNcomboBoxType,XmDROP_DOWN_LIST); ac++;
1441   XtManageChild(XmCreateComboBox(rc2,"fraction",al,ac));
1442   ac=0;
1443   XtSetArg(al[ac],XmNorientation,XmHORIZONTAL); ac++;
1444   XtManageChild(rc2=XmCreateRowColumn(rc3,"headrc",al,ac));
1445   ac=0;
1446   XtManageChild(XmCreateLabel(rc2,"Head",al,ac));
1447   ac=0;
1448   XtManageChild(XmCreateTextField(rc2,"head",al,ac));
1449   ac=0;
1450   XtManageChild(XmCreateLabel(rc2,"Tail",al,ac));
1451   ac=0;
1452   XtManageChild(XmCreateTextField(rc2,"tail",al,ac));
1453   ac=0;
1454   XtSetArg(al[ac],XmNorientation,XmHORIZONTAL); ac++;
1455   XtManageChild(rc2=XmCreateRowColumn(rc3,"alignrc",al,ac));
1456   ac=0;
1457   XtManageChild(XmCreateLabel(rc2,"Align",al,ac));
1458   ac=0;
1459   XtSetArg(al[ac],XmNcomboBoxType,XmDROP_DOWN_LIST); ac++;
1460   XtManageChild(XmCreateComboBox(rc2,"align",al,ac));
1461   ac=0;
1462   XtManageChild(XmCreateLabel(rc2,"Dir",al,ac));
1463   ac=0;
1464   XtSetArg(al[ac],XmNcomboBoxType,XmDROP_DOWN_LIST); ac++;
1465   XtManageChild(XmCreateComboBox(rc2,"direction",al,ac));
1466   ac=0;
1467   XtSetArg(al[ac],XmNorientation,XmHORIZONTAL); ac++;
1468   XtManageChild(rc2=XmCreateRowColumn(rc3,"shiftrc",al,ac));
1469   ac=0;
1470   XtManageChild(XmCreateLabel(rc2,"Shiftp",al,ac));
1471   ac=0;
1472   XtManageChild(XmCreateTextField(rc2,"shiftp",al,ac));
1473   ac=0;
1474   XtManageChild(XmCreateLabel(rc2,"Shiftn",al,ac));
1475   ac=0;
1476   XtManageChild(XmCreateTextField(rc2,"shiftn",al,ac));
1477   ac=0;
1478   XtSetArg(al[ac],XmNorientation,XmHORIZONTAL); ac++;
1479   XtManageChild(rc2=XmCreateRowColumn(rc3,"logrc",al,ac));
1480   ac=0;
1481   XtManageChild(XmCreateToggleButton(rc2,"Log_power",al,ac));
1482   ac=0;
1483   XtManageChild(XmCreateToggleButton(rc2,"No_zero",al,ac));
1484   ac=0;
1485   XtSetArg(al[ac],XmNorientation,XmHORIZONTAL); ac++;
1486   XtManageChild(rc2=XmCreateRowColumn(rc3,"autorc",al,ac));
1487   ac=0;
1488   XtManageChild(XmCreateLabel(rc2,"Norm",al,ac));
1489   ac=0;
1490   XtManageChild(XmCreateTextField(rc2,"norm",al,ac));
1491   }
1492   NumDialogSetupItem(w,d,d->Id);
1493 }
1494 
NumDialogClose(Widget w,void * data)1495 void NumDialogClose(Widget w,void *data)
1496 {
1497   struct NumDialog *d;
1498   int ret;
1499   int a,j,*pos,count;
1500   char *format;
1501 
1502   d=(struct NumDialog *)data;
1503   if (d->ret!=IDOK) return;
1504   ret=d->ret;
1505   d->ret=IDLOOP;
1506   if (SetObjFieldFromList(w,"*num",d->Obj,d->Id,"num")) return;
1507   if (SetObjFieldFromText(w,"*begin",d->Obj,d->Id,"num_begin")) return;
1508   if (SetObjFieldFromText(w,"*step",d->Obj,d->Id,"num_step")) return;
1509   if (SetObjFieldFromText(w,"*numnum",d->Obj,d->Id,"num_num")) return;
1510   if (SetObjFieldFromText(w,"*head",d->Obj,d->Id,"num_head")) return;
1511   if ((format=(char *)memalloc(10))==NULL) return;
1512   j=0;
1513   j+=sprintf(format+j,"%%");
1514   if (XmToggleButtonGetState(XtNameToWidget(w,"*Add_plus")))
1515     j+=sprintf(format+j,"%c",'+');
1516   XmListGetSelectedPos(GetComboBoxList(w,"*fraction"),&pos,&count);
1517   if (count!=0) {
1518     a=pos[0]-1;
1519     XtFree((char *)pos);
1520     if (a==0) j+=sprintf(format+j,"%c",'g');
1521     else j+=sprintf(format+j,".%df",a-1);
1522   }
1523   if (putobj(d->Obj,"num_format",d->Id,format)==-1) return;
1524   if (SetObjFieldFromText(w,"*tail",d->Obj,d->Id,"num_tail")) return;
1525   if (SetObjFieldFromList(w,"*align",d->Obj,d->Id,"num_align")) return;
1526   if (SetObjFieldFromList(w,"*direction",d->Obj,d->Id,"num_direction")) return;
1527   if (SetObjFieldFromText(w,"*shiftp",d->Obj,d->Id,"num_shift_p")) return;
1528   if (SetObjFieldFromText(w,"*shiftn",d->Obj,d->Id,"num_shift_n")) return;
1529   if (SetObjFieldFromToggle(w,"*Log_power",d->Obj,d->Id,"num_log_pow")) return;
1530   if (SetObjFieldFromToggle(w,"*No_zero",d->Obj,d->Id,"num_no_zero")) return;
1531   if (SetObjFieldFromText(w,"*norm",d->Obj,d->Id,"num_auto_norm")) return;
1532   d->ret=ret;
1533 }
1534 
NumDialog(struct NumDialog * data,struct objlist * obj,int id)1535 void NumDialog(struct NumDialog *data,struct objlist *obj,int id)
1536 {
1537   data->SetupWindow=NumDialogSetup;
1538   data->CloseWindow=NumDialogClose;
1539   data->Obj=obj;
1540   data->Id=id;
1541 }
1542 
AxisFontDialogSetupItem(Widget w,struct AxisFontDialog * d,int id)1543 void AxisFontDialogSetupItem(Widget w,struct AxisFontDialog *d,int id)
1544 {
1545   int j,selfont;
1546   struct fontmap *fcur;
1547   char *font;
1548   XmString xs;
1549 
1550   SetTextFromObjField(w,"*space",d->Obj,id,"num_space");
1551   SetComboList(w,"*pt",cbtextpt,CBTEXTPT);
1552   SetTextFromObjField(GetComboBoxText(w,"*pt"),NULL,d->Obj,id,"num_pt");
1553   SetComboListFromObjField(GetComboBoxList(w,"*pt"),NULL,d->Obj,id,"num_pt");
1554   SetTextFromObjField(w,"*script",d->Obj,id,"num_script_size");
1555   getobj(d->Obj,"num_font",id,0,NULL,&font);
1556   XmListDeleteAllItems(GetComboBoxList(w,"*font"));
1557   fcur=mxlocal->fontmaproot;
1558   j=0;
1559   selfont=-1;
1560   while (fcur!=NULL) {
1561     if (!(fcur->twobyte)) {
1562       xs=XmStringCreateLocalized(fcur->fontalias);
1563       XmListAddItem(GetComboBoxList(w,"*font"),xs,0);
1564       XmStringFree(xs);
1565       if (strcmp(font,fcur->fontalias)==0) selfont=j;
1566       j++;
1567     }
1568     fcur=fcur->next;
1569   }
1570   SetComboBoxVisibleItemCount(w,"*font",j);
1571   if (selfont!=-1)
1572     XmListSelectPos(GetComboBoxList(w,"*font"),selfont+1,TRUE);
1573 #ifdef JAPANESE
1574   getobj(d->Obj,"num_jfont",id,0,NULL,&font);
1575   XmListDeleteAllItems(GetComboBoxList(w,"*jfont"));
1576   fcur=mxlocal->fontmaproot;
1577   j=0;
1578   selfont=-1;
1579   while (fcur!=NULL) {
1580     if (fcur->twobyte) {
1581       xs=XmStringCreateLocalized(fcur->fontalias);
1582       XmListAddItem(GetComboBoxList(w,"*jfont"),xs,0);
1583       XmStringFree(xs);
1584       if (strcmp(font,fcur->fontalias)==0) selfont=j;
1585       j++;
1586     }
1587     fcur=fcur->next;
1588   }
1589   SetComboBoxVisibleItemCount(w,"*jfont",j);
1590   if (selfont!=-1)
1591     XmListSelectPos(GetComboBoxList(w,"*jfont"),selfont+1,TRUE);
1592 #endif
1593   getobj(d->Obj,"num_R",id,0,NULL,&d->R);
1594   getobj(d->Obj,"num_G",id,0,NULL,&d->G);
1595   getobj(d->Obj,"num_B",id,0,NULL,&d->B);
1596   XtVaSetValues(XtNameToWidget(w,"*col"),XmNbackground,RGB(d->R,d->G,d->B),NULL);
1597 }
1598 
AxisFontDialogColor(Widget w,XtPointer client_data,XtPointer call_data)1599 void AxisFontDialogColor(Widget w,XtPointer client_data,XtPointer call_data)
1600 {
1601   struct AxisFontDialog *d;
1602 
1603   d=(struct AxisFontDialog *)client_data;
1604   GetColor(TopLevel,&d->R,&d->G,&d->B);
1605   XtVaSetValues(w,XmNbackground,RGB(d->R,d->G,d->B),NULL);
1606 }
1607 
AxisFontDialogCopy(Widget w,XtPointer client_data,XtPointer call_data)1608 void AxisFontDialogCopy(Widget w,XtPointer client_data,XtPointer call_data)
1609 {
1610   struct AxisFontDialog *d;
1611   int sel;
1612 
1613   d=(struct AxisFontDialog *)client_data;
1614   if ((sel=CopyClick(d->widget,d->Obj,d->Id,AxisCB))!=-1)
1615     AxisFontDialogSetupItem(d->widget,d,sel);
1616 }
1617 
AxisFontDialogSetup(Widget w,void * data,int makewidget)1618 void AxisFontDialogSetup(Widget w,void *data,int makewidget)
1619 {
1620   Arg al[20];
1621   Cardinal ac;
1622   Widget rc,rc2,button;
1623   struct AxisFontDialog *d;
1624 
1625   d=(struct AxisFontDialog *)data;
1626   if (makewidget) {
1627   ac=0;
1628   XtManageChild(button=XmCreatePushButton(w,"Copy",al,ac));
1629   XtAddCallback(button,XmNdisarmCallback,AxisFontDialogCopy,d);
1630 
1631   ac=0;
1632   XtSetArg(al[ac],XmNorientation,XmVERTICAL); ac++;
1633   XtManageChild(rc=XmCreateRowColumn(w,"rc",al,ac));
1634 
1635   ac=0;
1636   XtSetArg(al[ac],XmNorientation,XmHORIZONTAL); ac++;
1637   XtManageChild(rc2=XmCreateRowColumn(rc,"ptrc",al,ac));
1638   ac=0;
1639   XtManageChild(XmCreateLabel(rc2,"Pt",al,ac));
1640   ac=0;
1641   XtSetArg(al[ac],XmNcomboBoxType,XmDROP_DOWN_COMBO_BOX); ac++;
1642   XtManageChild(XmCreateComboBox(rc2,"pt",al,ac));
1643   ac=0;
1644   XtManageChild(XmCreateLabel(rc2,"Space",al,ac));
1645   ac=0;
1646   XtManageChild(XmCreateTextField(rc2,"space",al,ac));
1647 
1648   ac=0;
1649   XtManageChild(XmCreateLabel(rc2,"Script",al,ac));
1650   ac=0;
1651   XtManageChild(XmCreateTextField(rc2,"script",al,ac));
1652 
1653   ac=0;
1654   XtSetArg(al[ac],XmNorientation,XmHORIZONTAL); ac++;
1655   XtManageChild(rc2=XmCreateRowColumn(rc,"fontrc",al,ac));
1656   ac=0;
1657   XtManageChild(XmCreateLabel(rc2,"Font",al,ac));
1658   ac=0;
1659   XtSetArg(al[ac],XmNcomboBoxType,XmDROP_DOWN_LIST); ac++;
1660   XtManageChild(XmCreateComboBox(rc2,"font",al,ac));
1661 #ifdef JAPANESE
1662   ac=0;
1663   XtSetArg(al[ac],XmNorientation,XmHORIZONTAL); ac++;
1664   XtManageChild(rc2=XmCreateRowColumn(rc,"jfontrc",al,ac));
1665   ac=0;
1666   XtManageChild(XmCreateLabel(rc2,"Jfont",al,ac));
1667   ac=0;
1668   XtSetArg(al[ac],XmNcomboBoxType,XmDROP_DOWN_LIST); ac++;
1669   XtManageChild(XmCreateComboBox(rc2,"jfont",al,ac));
1670 #endif
1671   ac=0;
1672   XtSetArg(al[ac],XmNorientation,XmHORIZONTAL); ac++;
1673   XtManageChild(rc2=XmCreateRowColumn(rc,"colorrc",al,ac));
1674   ac=0;
1675   XtManageChild(XmCreateLabel(rc2,"Color",al,ac));
1676   ac=0;
1677   XtManageChild(button=XmCreateDrawnButton(rc2,"col",al,ac));
1678   XtAddCallback(button,XmNdisarmCallback,AxisFontDialogColor,d);
1679   }
1680   AxisFontDialogSetupItem(w,d,d->Id);
1681 }
1682 
AxisFontDialogClose(Widget w,void * data)1683 void AxisFontDialogClose(Widget w,void *data)
1684 {
1685   struct AxisFontDialog *d;
1686   int ret;
1687   struct fontmap *fcur;
1688   int *selected,num,a,j;
1689 
1690   d=(struct AxisFontDialog *)data;
1691   if (d->ret!=IDOK) return;
1692   ret=d->ret;
1693   d->ret=IDLOOP;
1694   if (SetObjFieldFromText(w,"*space",d->Obj,d->Id,"num_space")) return;
1695   if (SetObjFieldFromText(GetComboBoxText(w,"*pt"),NULL,
1696                           d->Obj,d->Id,"num_pt")) return;
1697   if (SetObjFieldFromText(w,"*script",d->Obj,d->Id,"num_script_size")) return;
1698 
1699   XmListGetSelectedPos(GetComboBoxList(w,"*font"),&selected,&num);
1700   if (num!=0) {
1701     a=selected[0];
1702     fcur=mxlocal->fontmaproot;
1703     j=0;
1704     while (fcur!=NULL) {
1705       if (!(fcur->twobyte)) {
1706         j++;
1707         if (j==a) {
1708           sputobjfield(d->Obj,d->Id,"num_font",fcur->fontalias);
1709           break;
1710         }
1711       }
1712       fcur=fcur->next;
1713     }
1714     XtFree((char *)selected);
1715   }
1716 #ifdef JAPANESE
1717   XmListGetSelectedPos(GetComboBoxList(w,"*jfont"),&selected,&num);
1718   if (num!=0) {
1719     a=selected[0];
1720     fcur=mxlocal->fontmaproot;
1721     j=0;
1722     while (fcur!=NULL) {
1723       if (fcur->twobyte) {
1724         j++;
1725         if (j==a) {
1726           sputobjfield(d->Obj,d->Id,"num_jfont",fcur->fontalias);
1727           break;
1728         }
1729       }
1730       fcur=fcur->next;
1731     }
1732     XtFree((char *)selected);
1733   }
1734 #endif
1735   if (putobj(d->Obj,"num_R",d->Id,&(d->R))==-1) return;
1736   if (putobj(d->Obj,"num_G",d->Id,&(d->G))==-1) return;
1737   if (putobj(d->Obj,"num_B",d->Id,&(d->B))==-1) return;
1738   d->ret=ret;
1739 }
1740 
AxisFontDialog(struct AxisFontDialog * data,struct objlist * obj,int id)1741 void AxisFontDialog(struct AxisFontDialog *data,struct objlist *obj,int id)
1742 {
1743   data->SetupWindow=AxisFontDialogSetup;
1744   data->CloseWindow=AxisFontDialogClose;
1745   data->Obj=obj;
1746   data->Id=id;
1747 }
1748 
GaugeDialogSetupItem(Widget w,struct GaugeDialog * d,int id)1749 void GaugeDialogSetupItem(Widget w,struct GaugeDialog *d,int id)
1750 {
1751   SetListFromObjField(w,"*gauge",d->Obj,id,"gauge");
1752   SetTextFromObjField(w,"*min",d->Obj,id,"gauge_min");
1753   SetTextFromObjField(w,"*max",d->Obj,id,"gauge_max");
1754   SetStyleFromObjField(w,"*style",d->Obj,id,"gauge_style");
1755   SetTextFromObjField(w,"*len1",d->Obj,id,"gauge_length1");
1756   SetComboList(w,"*wid1",cblinewidth,CBLINEWIDTH);
1757   SetTextFromObjField(GetComboBoxText(w,"*wid1"),NULL,
1758                       d->Obj,id,"gauge_width1");
1759   SetComboListFromObjField(GetComboBoxList(w,"*wid1"),NULL,
1760                       d->Obj,id,"gauge_width1");
1761   SetTextFromObjField(w,"*len2",d->Obj,id,"gauge_length2");
1762   SetComboList(w,"*wid2",cblinewidth,CBLINEWIDTH);
1763   SetTextFromObjField(GetComboBoxText(w,"*wid2"),NULL,
1764                       d->Obj,id,"gauge_width2");
1765   SetComboListFromObjField(GetComboBoxList(w,"*wid2"),NULL,
1766                       d->Obj,id,"gauge_width2");
1767   SetTextFromObjField(w,"*len3",d->Obj,id,"gauge_length3");
1768   SetComboList(w,"*wid3",cblinewidth,CBLINEWIDTH);
1769   SetTextFromObjField(GetComboBoxText(w,"*wid3"),NULL,
1770                       d->Obj,id,"gauge_width3");
1771   SetComboListFromObjField(GetComboBoxList(w,"*wid3"),NULL,
1772                       d->Obj,id,"gauge_width3");
1773   getobj(d->Obj,"gauge_R",id,0,NULL,&d->R);
1774   getobj(d->Obj,"gauge_G",id,0,NULL,&d->G);
1775   getobj(d->Obj,"gauge_B",id,0,NULL,&d->B);
1776   XtVaSetValues(XtNameToWidget(w,"*col"),XmNbackground,RGB(d->R,d->G,d->B),NULL);
1777 }
1778 
GaugeDialogColor(Widget w,XtPointer client_data,XtPointer call_data)1779 void GaugeDialogColor(Widget w,XtPointer client_data,XtPointer call_data)
1780 {
1781   struct GaugeDialog *d;
1782 
1783   d=(struct GaugeDialog *)client_data;
1784   GetColor(TopLevel,&d->R,&d->G,&d->B);
1785   XtVaSetValues(w,XmNbackground,RGB(d->R,d->G,d->B),NULL);
1786 }
1787 
GaugeDialogCopy(Widget w,XtPointer client_data,XtPointer call_data)1788 void GaugeDialogCopy(Widget w,XtPointer client_data,XtPointer call_data)
1789 {
1790   struct GaugeDialog *d;
1791   int sel;
1792 
1793   d=(struct GaugeDialog *)client_data;
1794   if ((sel=CopyClick(d->widget,d->Obj,d->Id,AxisCB))!=-1)
1795     GaugeDialogSetupItem(d->widget,d,sel);
1796 }
1797 
GaugeDialogSetup(Widget w,void * data,int makewidget)1798 void GaugeDialogSetup(Widget w,void *data,int makewidget)
1799 {
1800   Arg al[20];
1801   Cardinal ac;
1802   Widget rc,rc2,rc3,frame,button;
1803   struct GaugeDialog *d;
1804 
1805   d=(struct GaugeDialog *)data;
1806   if (makewidget) {
1807   ac=0;
1808   XtManageChild(button=XmCreatePushButton(w,"Copy",al,ac));
1809   XtAddCallback(button,XmNdisarmCallback,GaugeDialogCopy,d);
1810 
1811   ac=0;
1812   XtSetArg(al[ac],XmNorientation,XmVERTICAL); ac++;
1813   XtManageChild(rc=XmCreateRowColumn(w,"rc",al,ac));
1814 
1815   ac=0;
1816   XtManageChild(frame=XmCreateFrame(rc,"frame",al,ac));
1817   ac=0;
1818   XtSetArg(al[ac],XmNorientation,XmHORIZONTAL); ac++;
1819   XtManageChild(rc2=XmCreateRowColumn(frame,"gaugerc",al,ac));
1820   ac=0;
1821   XtManageChild(XmCreateLabel(rc2,"Gauge",al,ac));
1822   ac=0;
1823   XtSetArg(al[ac],XmNcomboBoxType,XmDROP_DOWN_LIST); ac++;
1824   XtManageChild(XmCreateComboBox(rc2,"gauge",al,ac));
1825   ac=0;
1826   XtManageChild(XmCreateLabel(rc2,"Min",al,ac));
1827   ac=0;
1828   XtManageChild(XmCreateTextField(rc2,"min",al,ac));
1829   ac=0;
1830   XtManageChild(XmCreateLabel(rc2,"Max",al,ac));
1831   ac=0;
1832   XtManageChild(XmCreateTextField(rc2,"max",al,ac));
1833 
1834   ac=0;
1835   XtManageChild(frame=XmCreateFrame(rc,"frame2",al,ac));
1836   ac=0;
1837   XtSetArg(al[ac],XmNorientation,XmVERTICAL); ac++;
1838   XtManageChild(rc2=XmCreateRowColumn(frame,"rc2",al,ac));
1839 
1840   ac=0;
1841   XtSetArg(al[ac],XmNorientation,XmHORIZONTAL); ac++;
1842   XtManageChild(rc3=XmCreateRowColumn(rc2,"stylerc",al,ac));
1843   ac=0;
1844   XtManageChild(XmCreateLabel(rc3,"Style",al,ac));
1845   ac=0;
1846   XtSetArg(al[ac],XmNcomboBoxType,XmDROP_DOWN_COMBO_BOX); ac++;
1847   XtManageChild(XmCreateComboBox(rc3,"style",al,ac));
1848   ac=0;
1849   XtManageChild(XmCreateLabel(rc3,"Color",al,ac));
1850   ac=0;
1851   XtManageChild(button=XmCreateDrawnButton(rc3,"col",al,ac));
1852   XtAddCallback(button,XmNdisarmCallback,GaugeDialogColor,d);
1853   ac=0;
1854   XtSetArg(al[ac],XmNorientation,XmHORIZONTAL); ac++;
1855   XtManageChild(rc3=XmCreateRowColumn(rc2,"len1rc",al,ac));
1856   ac=0;
1857   XtManageChild(XmCreateLabel(rc3,"Length1",al,ac));
1858   ac=0;
1859   XtManageChild(XmCreateTextField(rc3,"len1",al,ac));
1860   ac=0;
1861   XtManageChild(XmCreateLabel(rc3,"Width1",al,ac));
1862   ac=0;
1863   XtSetArg(al[ac],XmNcomboBoxType,XmDROP_DOWN_COMBO_BOX); ac++;
1864   XtManageChild(XmCreateComboBox(rc3,"wid1",al,ac));
1865   ac=0;
1866   XtSetArg(al[ac],XmNorientation,XmHORIZONTAL); ac++;
1867   XtManageChild(rc3=XmCreateRowColumn(rc2,"len2rc",al,ac));
1868   ac=0;
1869   XtManageChild(XmCreateLabel(rc3,"Length2",al,ac));
1870   ac=0;
1871   XtManageChild(XmCreateTextField(rc3,"len2",al,ac));
1872   ac=0;
1873   XtManageChild(XmCreateLabel(rc3,"Width2",al,ac));
1874   ac=0;
1875   XtSetArg(al[ac],XmNcomboBoxType,XmDROP_DOWN_COMBO_BOX); ac++;
1876   XtManageChild(XmCreateComboBox(rc3,"wid2",al,ac));
1877   ac=0;
1878   XtSetArg(al[ac],XmNorientation,XmHORIZONTAL); ac++;
1879   XtManageChild(rc3=XmCreateRowColumn(rc2,"len3rc",al,ac));
1880   ac=0;
1881   XtManageChild(XmCreateLabel(rc3,"Length3",al,ac));
1882   ac=0;
1883   XtManageChild(XmCreateTextField(rc3,"len3",al,ac));
1884   ac=0;
1885   XtManageChild(XmCreateLabel(rc3,"Width3",al,ac));
1886   ac=0;
1887   XtSetArg(al[ac],XmNcomboBoxType,XmDROP_DOWN_COMBO_BOX); ac++;
1888   XtManageChild(XmCreateComboBox(rc3,"wid3",al,ac));
1889   }
1890   GaugeDialogSetupItem(w,d,d->Id);
1891 }
1892 
1893 
GaugeDialogClose(Widget w,void * data)1894 void GaugeDialogClose(Widget w,void *data)
1895 {
1896   struct GaugeDialog *d;
1897   int ret;
1898 
1899   d=(struct GaugeDialog *)data;
1900   if (d->ret!=IDOK) return;
1901   ret=d->ret;
1902   d->ret=IDLOOP;
1903   if (SetObjFieldFromList(w,"*gauge",d->Obj,d->Id,"gauge")) return;
1904   if (SetObjFieldFromText(w,"*min",d->Obj,d->Id,"gauge_min")) return;
1905   if (SetObjFieldFromText(w,"*max",d->Obj,d->Id,"gauge_max")) return;
1906   if (SetObjFieldFromStyle(w,"*style",d->Obj,d->Id,"gauge_style")) return;
1907   if (SetObjFieldFromText(w,"*len1",d->Obj,d->Id,"gauge_length1")) return;
1908   if (SetObjFieldFromText(GetComboBoxText(w,"*wid1"),NULL,
1909                           d->Obj,d->Id,"gauge_width1")) return;
1910   if (SetObjFieldFromText(w,"*len2",d->Obj,d->Id,"gauge_length2")) return;
1911   if (SetObjFieldFromText(GetComboBoxText(w,"*wid2"),NULL,
1912                           d->Obj,d->Id,"gauge_width2")) return;
1913   if (SetObjFieldFromText(w,"*len3",d->Obj,d->Id,"gauge_length3")) return;
1914   if (SetObjFieldFromText(GetComboBoxText(w,"*wid3"),NULL,
1915                           d->Obj,d->Id,"gauge_width3")) return;
1916   if (putobj(d->Obj,"gauge_R",d->Id,&(d->R))==-1) return;
1917   if (putobj(d->Obj,"gauge_G",d->Id,&(d->G))==-1) return;
1918   if (putobj(d->Obj,"gauge_B",d->Id,&(d->B))==-1) return;
1919   d->ret=ret;
1920 }
1921 
GaugeDialog(struct GaugeDialog * data,struct objlist * obj,int id)1922 void GaugeDialog(struct GaugeDialog *data,struct objlist *obj,int id)
1923 {
1924   data->SetupWindow=GaugeDialogSetup;
1925   data->CloseWindow=GaugeDialogClose;
1926   data->Obj=obj;
1927   data->Id=id;
1928 }
1929 
AxisDialogSetupItem(Widget w,struct AxisDialog * d,int id)1930 void AxisDialogSetupItem(Widget w,struct AxisDialog *d,int id)
1931 {
1932   char *valstr;
1933   int i,j;
1934   double min,max,inc;
1935   int div,lastinst;
1936   XmString xs;
1937   char *name;
1938   struct narray *array;
1939   int num;
1940   double *data;
1941   char buf[30];
1942 
1943   XmListDeleteAllItems(GetComboBoxList(w,"*min"));
1944   XmListDeleteAllItems(GetComboBoxList(w,"*max"));
1945   XmListDeleteAllItems(GetComboBoxList(w,"*inc"));
1946   getobj(d->Obj,"scale_history",d->Id,0,NULL,&array);
1947   if (array!=NULL) {
1948     num=arraynum(array)/3;
1949     data=(double *)arraydata(array);
1950     for (j=0;j<num;j++) {
1951       sprintf(buf,"%.15g",data[0+j*3]);
1952       xs=XmStringCreateLocalized(buf);
1953       XmListAddItem(GetComboBoxList(w,"*min"),xs,0);
1954       XmStringFree(xs);
1955       sprintf(buf,"%.15g",data[1+j*3]);
1956       xs=XmStringCreateLocalized(buf);
1957       XmListAddItem(GetComboBoxList(w,"*max"),xs,0);
1958       XmStringFree(xs);
1959       sprintf(buf,"%.15g",data[2+j*3]);
1960       xs=XmStringCreateLocalized(buf);
1961       XmListAddItem(GetComboBoxList(w,"*inc"),xs,0);
1962       XmStringFree(xs);
1963     }
1964     SetComboBoxVisibleItemCount(w,"*min",j);
1965     SetComboBoxVisibleItemCount(w,"*max",j);
1966     SetComboBoxVisibleItemCount(w,"*inc",j);
1967   }
1968   getobj(d->Obj,"min",id,0,NULL,&min);
1969   getobj(d->Obj,"max",id,0,NULL,&max);
1970   getobj(d->Obj,"inc",id,0,NULL,&inc);
1971   if ((min==0) && (max==0) && (inc==0)) {
1972     XtVaSetValues(GetComboBoxText(w,"*min"),XmNvalue,"0",NULL);
1973     XtVaSetValues(GetComboBoxText(w,"*max"),XmNvalue,"0",NULL);
1974     XtVaSetValues(GetComboBoxText(w,"*inc"),XmNvalue,"0",NULL);
1975   } else {
1976     sprintf(buf,"%.15g",min);
1977     XtVaSetValues(GetComboBoxText(w,"*min"),XmNvalue,buf,NULL);
1978     sprintf(buf,"%.15g",max);
1979     XtVaSetValues(GetComboBoxText(w,"*max"),XmNvalue,buf,NULL);
1980     sprintf(buf,"%.15g",inc);
1981     XtVaSetValues(GetComboBoxText(w,"*inc"),XmNvalue,buf,NULL);
1982   }
1983   getobj(d->Obj,"div",id,0,NULL,&div);
1984   SetTextFromObjField(w,"*div",d->Obj,id,"div");
1985   SetListFromObjField(w,"*scale",d->Obj,id,"type");
1986   XmListDeleteAllItems(GetComboBoxList(w,"*ref"));
1987   lastinst=chkobjlastinst(d->Obj);
1988   for (j=0;j<=lastinst;j++) {
1989     getobj(d->Obj,"group",j,0,NULL,&name);
1990     if (name==NULL) name="";
1991     xs=XmStringCreateLocalized(name);
1992     XmListAddItem(GetComboBoxList(w,"*ref"),xs,0);
1993     XmStringFree(xs);
1994   }
1995   SetComboBoxVisibleItemCount(w,"*ref",j);
1996   sgetobjfield(d->Obj,id,"reference",NULL,&valstr,FALSE,FALSE,FALSE);
1997   for (i=0;(valstr[i]!='\0') && (valstr[i]!=':');i++);
1998   if (valstr[i]==':') i++;
1999   XtVaSetValues(GetComboBoxText(w,"*ref"),XmNvalue,valstr+i,NULL);
2000   memfree(valstr);
2001 }
2002 
AxisDialogGauge(Widget w,XtPointer client_data,XtPointer call_data)2003 void AxisDialogGauge(Widget w,XtPointer client_data,XtPointer call_data)
2004 {
2005   struct AxisDialog *d;
2006 
2007   d=(struct AxisDialog *)client_data;
2008   GaugeDialog(&DlgGauge,d->Obj,d->Id);
2009   DialogExecute(d->widget,&DlgGauge);
2010 }
2011 
2012 
AxisDialogBase(Widget w,XtPointer client_data,XtPointer call_data)2013 void AxisDialogBase(Widget w,XtPointer client_data,XtPointer call_data)
2014 {
2015   struct AxisDialog *d;
2016 
2017   d=(struct AxisDialog *)client_data;
2018   AxisBaseDialog(&DlgAxisBase,d->Obj,d->Id);
2019   DialogExecute(d->widget,&DlgAxisBase);
2020 }
2021 
AxisDialogPos(Widget w,XtPointer client_data,XtPointer call_data)2022 void AxisDialogPos(Widget w,XtPointer client_data,XtPointer call_data)
2023 {
2024   struct AxisDialog *d;
2025 
2026   d=(struct AxisDialog *)client_data;
2027   AxisPosDialog(&DlgAxisPos,d->Obj,d->Id);
2028   DialogExecute(d->widget,&DlgAxisPos);
2029 }
2030 
AxisDialogFont(Widget w,XtPointer client_data,XtPointer call_data)2031 void AxisDialogFont(Widget w,XtPointer client_data,XtPointer call_data)
2032 {
2033   struct AxisDialog *d;
2034 
2035   d=(struct AxisDialog *)client_data;
2036   AxisFontDialog(&DlgAxisFont,d->Obj,d->Id);
2037   DialogExecute(d->widget,&DlgAxisFont);
2038 }
2039 
AxisDialogNum(Widget w,XtPointer client_data,XtPointer call_data)2040 void AxisDialogNum(Widget w,XtPointer client_data,XtPointer call_data)
2041 {
2042   struct AxisDialog *d;
2043 
2044   d=(struct AxisDialog *)client_data;
2045   NumDialog(&DlgNum,d->Obj,d->Id);
2046   DialogExecute(d->widget,&DlgNum);
2047 }
2048 
AxisDialogClear(Widget w,XtPointer client_data,XtPointer call_data)2049 void AxisDialogClear(Widget w,XtPointer client_data,XtPointer call_data)
2050 {
2051   struct AxisDialog *d;
2052 
2053   d=(struct AxisDialog *)client_data;
2054   XtVaSetValues(GetComboBoxText(d->widget,"*min"),XmNvalue,"0",NULL);
2055   XtVaSetValues(GetComboBoxText(d->widget,"*max"),XmNvalue,"0",NULL);
2056   XtVaSetValues(GetComboBoxText(d->widget,"*inc"),XmNvalue,"0",NULL);
2057 }
2058 
AxisDialogFile(Widget w,XtPointer client_data,XtPointer call_data)2059 void AxisDialogFile(Widget w,XtPointer client_data,XtPointer call_data)
2060 {
2061   struct AxisDialog *d;
2062   int anum,room,type;
2063   char *buf,s[30];
2064   char *argv2[3];
2065   struct objlist *fobj;
2066   struct narray farray;
2067   int *selected,count,a,i,j,num,*array;
2068   struct narray *result;
2069 
2070   d=(struct AxisDialog *)client_data;
2071   if ((fobj=chkobject("file"))==NULL) return;
2072   if (chkobjlastinst(fobj)==-1) return;
2073   SelectDialog(&DlgSelect,fobj,FileCB,(struct narray *)&farray,NULL);
2074   if (DialogExecute(TopLevel,&DlgSelect)==IDOK) {
2075     num=arraynum(&farray);
2076     array=(int *)arraydata(&farray);
2077     anum=chkobjlastinst(d->Obj);
2078     if ((num>0) && (anum!=0)) {
2079       if ((buf=(char *)memalloc(6*num+6))!=NULL) {
2080         j=0;
2081         j+=sprintf(buf+j,"file:");
2082         for (i=0;i<num;i++)
2083           if (i==num-1) j+=sprintf(buf+j,"%d",array[i]);
2084           else j+=sprintf(buf+j,"%d,",array[i]);
2085         room=0;
2086         argv2[0]=(char *)buf;
2087         argv2[1]=(char *)&room;
2088         argv2[2]=NULL;
2089         XmListGetSelectedPos(GetComboBoxList(d->widget,"*scale"),
2090                              &selected,&count);
2091         if (count!=0) {
2092           a=selected[0]-1;
2093           XtFree((char *)selected);
2094           if ((getobj(d->Obj,"type",d->Id,0,NULL,&type)==-1)
2095           || (putobj(d->Obj,"type",d->Id,&a)==-1)) {
2096             arraydel(&farray);
2097             return;
2098           }
2099         }
2100         getobj(d->Obj,"get_auto_scale",d->Id,2,argv2,&result);
2101         memfree(buf);
2102         if (arraynum(result)==3) {
2103           sprintf(s,"%.15g",*(double *)arraynget(result,0));
2104           XtVaSetValues(GetComboBoxText(d->widget,"*min"),XmNvalue,s,NULL);
2105           sprintf(s,"%.15g",*(double *)arraynget(result,1));
2106           XtVaSetValues(GetComboBoxText(d->widget,"*max"),XmNvalue,s,NULL);
2107           sprintf(s,"%.15g",*(double *)arraynget(result,2));
2108           XtVaSetValues(GetComboBoxText(d->widget,"*inc"),XmNvalue,s,NULL);
2109         }
2110         putobj(d->Obj,"type",d->Id,&type);
2111       }
2112     }
2113   }
2114   arraydel(&farray);
2115 }
2116 
AxisDialogRef(Widget w,XtPointer client_data,XtPointer call_data)2117 void AxisDialogRef(Widget w,XtPointer client_data,XtPointer call_data)
2118 {
2119   struct AxisDialog *d;
2120   XmComboBoxCallbackStruct *dd;
2121   char buf[10];
2122   int a,oid;
2123 
2124   d=(struct AxisDialog *)client_data;
2125   dd=(XmComboBoxCallbackStruct *)call_data;
2126 #ifdef ZEROBASECOMBOBOX
2127   a=dd->item_position;
2128 #else
2129   a=dd->item_position-1;
2130 #endif
2131   if (a<0) return;
2132   getobj(d->Obj,"oid",a,0,NULL,&oid);
2133   sprintf(buf,"^%d",oid);
2134   XtVaSetValues(GetComboBoxText(d->widget,"*ref"),XmNvalue,buf,NULL);
2135 }
2136 
AxisDialogDelete(Widget w,XtPointer client_data,XtPointer call_data)2137 void AxisDialogDelete(Widget w,XtPointer client_data,XtPointer call_data)
2138 {
2139   struct AxisDialog *d;
2140 
2141   d=(struct AxisDialog *)client_data;
2142   d->ret=IDDELETE;
2143 }
2144 
AxisDialogCopy(Widget w,XtPointer client_data,XtPointer call_data)2145 void AxisDialogCopy(Widget w,XtPointer client_data,XtPointer call_data)
2146 {
2147   struct AxisDialog *d;
2148   int sel;
2149 
2150   d=(struct AxisDialog *)client_data;
2151   if ((sel=CopyClick(d->widget,d->Obj,d->Id,AxisCB))!=-1)
2152     AxisDialogSetupItem(d->widget,d,sel);
2153 }
2154 
AxisDialogSetup(Widget w,void * data,int makewidget)2155 void AxisDialogSetup(Widget w,void *data,int makewidget)
2156 {
2157   Arg al[20];
2158   Cardinal ac;
2159   Widget rc,rc2,rc3,rc4,button,frame,combo;
2160   struct AxisDialog *d;
2161   char *group;
2162   char title[25];
2163   XmString xs;
2164 
2165   d=(struct AxisDialog *)data;
2166   getobj(d->Obj,"group",d->Id,0,NULL,&group);
2167   if (group==NULL) group="";
2168   sprintf(title,"Axis %d %s",d->Id,group);
2169   xs=XmStringCreateLocalized(title);
2170   XtVaSetValues(w,XmNdialogTitle,xs,NULL);
2171   XmStringFree(xs);
2172 
2173   if (makewidget) {
2174   ac=0;
2175   XtManageChild(button=XmCreatePushButton(w,"Delete",al,ac));
2176   XtAddCallback(button,XmNdisarmCallback,AxisDialogDelete,d);
2177   ac=0;
2178   XtManageChild(button=XmCreatePushButton(w,"Copy",al,ac));
2179   XtAddCallback(button,XmNdisarmCallback,AxisDialogCopy,d);
2180 
2181   ac=0;
2182   XtSetArg(al[ac],XmNorientation,XmHORIZONTAL); ac++;
2183   XtManageChild(rc=XmCreateRowColumn(w,"rc",al,ac));
2184 
2185   ac=0;
2186   XtManageChild(frame=XmCreateFrame(rc,"frame",al,ac));
2187   ac=0;
2188   XtSetArg(al[ac],XmNorientation,XmHORIZONTAL); ac++;
2189   XtManageChild(rc2=XmCreateRowColumn(frame,"rc2",al,ac));
2190 
2191   ac=0;
2192   XtSetArg(al[ac],XmNorientation,XmVERTICAL); ac++;
2193   XtManageChild(rc3=XmCreateRowColumn(rc2,"rc3",al,ac));
2194 
2195   ac=0;
2196   XtSetArg(al[ac],XmNorientation,XmHORIZONTAL); ac++;
2197   XtManageChild(rc4=XmCreateRowColumn(rc3,"minrc",al,ac));
2198   ac=0;
2199   XtManageChild(XmCreateLabel(rc4,"Min",al,ac));
2200   ac=0;
2201   XtSetArg(al[ac],XmNcomboBoxType,XmDROP_DOWN_COMBO_BOX); ac++;
2202   XtManageChild(XmCreateComboBox(rc4,"min",al,ac));
2203   ac=0;
2204   XtSetArg(al[ac],XmNorientation,XmHORIZONTAL); ac++;
2205   XtManageChild(rc4=XmCreateRowColumn(rc3,"maxrc",al,ac));
2206   ac=0;
2207   XtManageChild(XmCreateLabel(rc4,"Max",al,ac));
2208   ac=0;
2209   XtSetArg(al[ac],XmNcomboBoxType,XmDROP_DOWN_COMBO_BOX); ac++;
2210   XtManageChild(XmCreateComboBox(rc4,"max",al,ac));
2211   ac=0;
2212   XtSetArg(al[ac],XmNorientation,XmHORIZONTAL); ac++;
2213   XtManageChild(rc4=XmCreateRowColumn(rc3,"incrc",al,ac));
2214   ac=0;
2215   XtManageChild(XmCreateLabel(rc4,"Inc",al,ac));
2216   ac=0;
2217   XtSetArg(al[ac],XmNcomboBoxType,XmDROP_DOWN_COMBO_BOX); ac++;
2218   XtManageChild(XmCreateComboBox(rc4,"inc",al,ac));
2219   ac=0;
2220   XtSetArg(al[ac],XmNorientation,XmHORIZONTAL); ac++;
2221   XtManageChild(rc4=XmCreateRowColumn(rc3,"scalerc",al,ac));
2222   ac=0;
2223   XtManageChild(XmCreateLabel(rc4,"Scale",al,ac));
2224   ac=0;
2225   XtSetArg(al[ac],XmNcomboBoxType,XmDROP_DOWN_LIST); ac++;
2226   XtManageChild(XmCreateComboBox(rc4,"scale",al,ac));
2227 
2228   ac=0;
2229   XtSetArg(al[ac],XmNorientation,XmVERTICAL); ac++;
2230   XtManageChild(rc3=XmCreateRowColumn(rc2,"rc4",al,ac));
2231   ac=0;
2232   XtManageChild(button=XmCreatePushButton(rc3,"Clear",al,ac));
2233   XtAddCallback(button,XmNdisarmCallback,AxisDialogClear,d);
2234   ac=0;
2235   XtManageChild(button=XmCreatePushButton(rc3,"File",al,ac));
2236   XtAddCallback(button,XmNdisarmCallback,AxisDialogFile,d);
2237   ac=0;
2238   XtSetArg(al[ac],XmNorientation,XmHORIZONTAL); ac++;
2239   XtManageChild(rc4=XmCreateRowColumn(rc3,"divrc",al,ac));
2240   ac=0;
2241   XtManageChild(XmCreateLabel(rc4,"Div",al,ac));
2242   ac=0;
2243   XtManageChild(XmCreateTextField(rc4,"div",al,ac));
2244   ac=0;
2245   XtSetArg(al[ac],XmNorientation,XmHORIZONTAL); ac++;
2246   XtManageChild(rc4=XmCreateRowColumn(rc3,"refrc",al,ac));
2247   ac=0;
2248   XtManageChild(XmCreateLabel(rc4,"Ref",al,ac));
2249   ac=0;
2250   XtSetArg(al[ac],XmNcomboBoxType,XmDROP_DOWN_COMBO_BOX); ac++;
2251   XtManageChild(combo=XmCreateComboBox(rc4,"ref",al,ac));
2252   XtAddCallback(combo,XmNselectionCallback,AxisDialogRef,d);
2253 
2254   ac=0;
2255   XtSetArg(al[ac],XmNorientation,XmVERTICAL); ac++;
2256   XtManageChild(rc2=XmCreateRowColumn(rc,"buttonrc",al,ac));
2257   ac=0;
2258   XtManageChild(button=XmCreatePushButton(rc2,"Baseline",al,ac));
2259   XtAddCallback(button,XmNdisarmCallback,AxisDialogBase,d);
2260   ac=0;
2261   XtManageChild(button=XmCreatePushButton(rc2,"Gauge",al,ac));
2262   XtAddCallback(button,XmNdisarmCallback,AxisDialogGauge,d);
2263   ac=0;
2264   XtManageChild(button=XmCreatePushButton(rc2,"Numbering",al,ac));
2265   XtAddCallback(button,XmNdisarmCallback,AxisDialogNum,d);
2266   ac=0;
2267   XtManageChild(button=XmCreatePushButton(rc2,"Font",al,ac));
2268   XtAddCallback(button,XmNdisarmCallback,AxisDialogFont,d);
2269   ac=0;
2270   XtManageChild(button=XmCreatePushButton(rc2,"Position",al,ac));
2271   XtAddCallback(button,XmNdisarmCallback,AxisDialogPos,d);
2272   }
2273   if (d->CanDel) XtManageChild(XtNameToWidget(w,"*Delete"));
2274   else XtUnmanageChild(XtNameToWidget(w,"*Delete"));
2275 
2276   AxisDialogSetupItem(w,d,d->Id);
2277 
2278 }
2279 
AxisDialogClose(Widget w,void * data)2280 void AxisDialogClose(Widget w,void *data)
2281 {
2282   struct AxisDialog *d;
2283   int ret;
2284   char *s,*buf;
2285   int len;
2286 
2287   d=(struct AxisDialog *)data;
2288   if (d->ret!=IDOK) return;
2289   ret=d->ret;
2290   d->ret=IDLOOP;
2291   exeobj(d->Obj,"scale_push",d->Id,0,NULL);
2292   if (SetObjFieldFromText(GetComboBoxText(w,"*min"),NULL,
2293                           d->Obj,d->Id,"min")) return;
2294   if (SetObjFieldFromText(GetComboBoxText(w,"*max"),NULL,
2295                           d->Obj,d->Id,"max")) return;
2296   if (SetObjFieldFromText(GetComboBoxText(w,"*inc"),NULL,
2297                           d->Obj,d->Id,"inc")) return;
2298   if (SetObjFieldFromText(w,"*div",d->Obj,d->Id,"div")) return;
2299   if (SetObjFieldFromList(w,"*scale",d->Obj,d->Id,"type")) return;
2300   XtVaGetValues(GetComboBoxText(w,"*ref"),XmNvalue,&s,NULL);
2301   if ((s==NULL) || (strlen(s)==0)) {
2302     if (sputobjfield(d->Obj,d->Id,"reference",NULL)!=0) return;
2303   } else {
2304     len=strlen(s);
2305     if ((buf=(char *)memalloc(len+6))!=NULL) {
2306       strcpy(buf,"axis:");
2307       if (s!=NULL) strcat(buf,s);
2308       if (sputobjfield(d->Obj,d->Id,"reference",buf)!=0) {
2309         memfree(buf);
2310         return;
2311       }
2312       memfree(buf);
2313     }
2314   }
2315   XtFree(s);
2316   d->ret=ret;
2317 }
2318 
AxisDialog(struct AxisDialog * data,struct objlist * obj,int id,int candel)2319 void AxisDialog(struct AxisDialog *data,struct objlist *obj,int id,int candel)
2320 {
2321   data->SetupWindow=AxisDialogSetup;
2322   data->CloseWindow=AxisDialogClose;
2323   data->Obj=obj;
2324   data->Id=id;
2325   data->CanDel=candel;
2326 }
2327 
CmAxisNewFrame()2328 void CmAxisNewFrame()
2329 {
2330   struct objlist *obj,*obj2;
2331   int idx,idy,idu,idr,idg,ret;
2332   int type,x,y,lenx,leny;
2333   struct narray group;
2334   char *argv[2];
2335 
2336   if (menulock || globallock) return;
2337   if ((obj=chkobject("axis"))==NULL) return;
2338   if ((obj2=getobject("axisgrid"))==NULL) return;
2339   idx=newobj(obj);
2340   idy=newobj(obj);
2341   idu=newobj(obj);
2342   idr=newobj(obj);
2343   idg=-1;
2344   arrayinit(&group,sizeof(int));
2345   type=1;
2346   x=3500;
2347   y=22000;
2348   lenx=14000;
2349   leny=14000;
2350   arrayadd(&group,&type);
2351   arrayadd(&group,&idx);
2352   arrayadd(&group,&idy);
2353   arrayadd(&group,&idu);
2354   arrayadd(&group,&idr);
2355   arrayadd(&group,&x);
2356   arrayadd(&group,&y);
2357   arrayadd(&group,&lenx);
2358   arrayadd(&group,&leny);
2359   argv[0]=(char *)&group;
2360   argv[1]=NULL;
2361   exeobj(obj,"default_grouping",idr,1,argv);
2362   arraydel(&group);
2363   SectionDialog(&DlgSection,x,y,lenx,leny,obj,idx,idy,idu,idr,obj2,&idg,FALSE);
2364   ret=DialogExecute(TopLevel,&DlgSection);
2365   if ((ret==IDDELETE) || (ret==IDCANCEL)) {
2366     if (idg!=-1) delobj(obj2,idg);
2367     delobj(obj,idr);
2368     delobj(obj,idu);
2369     delobj(obj,idy);
2370     delobj(obj,idx);
2371   } else  NgraphApp.Changed=TRUE;
2372   AxisWinUpdate(TRUE);
2373 }
2374 
CmAxisNewSection()2375 void CmAxisNewSection()
2376 {
2377   struct objlist *obj,*obj2;
2378   int idx,idy,idu,idr,idg,ret,oidx,oidy;
2379   int type,x,y,lenx,leny;
2380   struct narray group;
2381   char *argv[2];
2382   char *ref;
2383 
2384   if (menulock || globallock) return;
2385   if ((obj=getobject("axis"))==NULL) return;
2386   if ((obj2=getobject("axisgrid"))==NULL) return;
2387   idx=newobj(obj);
2388   idy=newobj(obj);
2389   idu=newobj(obj);
2390   idr=newobj(obj);
2391   idg=newobj(obj2);
2392   arrayinit(&group,sizeof(int));
2393   type=2;
2394   x=3500;
2395   y=22000;
2396   lenx=14000;
2397   leny=14000;
2398   arrayadd(&group,&type);
2399   arrayadd(&group,&idx);
2400   arrayadd(&group,&idy);
2401   arrayadd(&group,&idu);
2402   arrayadd(&group,&idr);
2403   arrayadd(&group,&x);
2404   arrayadd(&group,&y);
2405   arrayadd(&group,&lenx);
2406   arrayadd(&group,&leny);
2407   argv[0]=(char *)&group;
2408   argv[1]=NULL;
2409   exeobj(obj,"default_grouping",idr,1,argv);
2410   arraydel(&group);
2411   if (idg>=0) {
2412     getobj(obj,"oid",idx,0,NULL,&oidx);
2413     if ((ref=(char *)memalloc(15))!=NULL) {
2414       sprintf(ref,"axis:^%d",oidx);
2415       putobj(obj2,"axis_x",idg,ref);
2416     }
2417     getobj(obj,"oid",idy,0,NULL,&oidy);
2418     if ((ref=(char *)memalloc(15))!=NULL) {
2419       sprintf(ref,"axis:^%d",oidy);
2420       putobj(obj2,"axis_y",idg,ref);
2421     }
2422   }
2423   SectionDialog(&DlgSection,x,y,lenx,leny,obj,idx,idy,idu,idr,obj2,&idg,TRUE);
2424   ret=DialogExecute(TopLevel,&DlgSection);
2425   if ((ret==IDDELETE) || (ret==IDCANCEL)) {
2426     delobj(obj2,idg);
2427     delobj(obj,idr);
2428     delobj(obj,idu);
2429     delobj(obj,idy);
2430     delobj(obj,idx);
2431   } else NgraphApp.Changed=TRUE;
2432   AxisWinUpdate(TRUE);
2433 }
2434 
CmAxisNewCross()2435 void CmAxisNewCross()
2436 {
2437   struct objlist *obj;
2438   int idx,idy,ret;
2439   int type,x,y,lenx,leny;
2440   struct narray group;
2441   char *argv[2];
2442 
2443   if (menulock || globallock) return;
2444   if ((obj=chkobject("axis"))==NULL) return;
2445   idx=newobj(obj);
2446   idy=newobj(obj);
2447   arrayinit(&group,sizeof(int));
2448   type=3;
2449   x=3500;
2450   y=22000;
2451   lenx=14000;
2452   leny=14000;
2453   arrayadd(&group,&type);
2454   arrayadd(&group,&idx);
2455   arrayadd(&group,&idy);
2456   arrayadd(&group,&x);
2457   arrayadd(&group,&y);
2458   arrayadd(&group,&lenx);
2459   arrayadd(&group,&leny);
2460   argv[0]=(char *)&group;
2461   argv[1]=NULL;
2462   exeobj(obj,"default_grouping",idy,1,argv);
2463   arraydel(&group);
2464   CrossDialog(&DlgCross,x,y,lenx,leny,obj,idx,idy);
2465   ret=DialogExecute(TopLevel,&DlgCross);
2466   if ((ret==IDDELETE) || (ret==IDCANCEL)) {
2467     delobj(obj,idy);
2468     delobj(obj,idx);
2469   } else NgraphApp.Changed=TRUE;
2470   AxisWinUpdate(TRUE);
2471 }
2472 
CmAxisNewSingle()2473 void CmAxisNewSingle()
2474 {
2475   struct objlist *obj;
2476   int id,ret;
2477 
2478   if (menulock || globallock) return;
2479   if ((obj=chkobject("axis"))==NULL) return;
2480   if ((id=newobj(obj))>=0) {
2481     AxisDialog(&DlgAxis,obj,id,TRUE);
2482     ret=DialogExecute(TopLevel,&DlgAxis);
2483     if ((ret==IDDELETE) || (ret==IDCANCEL)) {
2484       delobj(obj,id);
2485     } else NgraphApp.Changed=TRUE;
2486     AxisWinUpdate(TRUE);
2487   }
2488 }
2489 
CmAxisAddMenu(Widget w,XtPointer client_data,XtPointer call_data)2490 void CmAxisAddMenu(Widget w,XtPointer client_data,XtPointer call_data)
2491 {
2492   switch ((int )client_data) {
2493   case 0:
2494     CmAxisNewFrame();
2495     break;
2496   case 1:
2497     CmAxisNewSection();
2498     break;
2499   case 2:
2500     CmAxisNewCross();
2501     break;
2502   case 3:
2503     CmAxisNewSingle();
2504     break;
2505   }
2506 }
2507 
CmAxisDel()2508 void CmAxisDel()
2509 {
2510   struct objlist *obj;
2511   int i;
2512 
2513   if (menulock || globallock) return;
2514   if ((obj=chkobject("axis"))==NULL) return;
2515   if (chkobjlastinst(obj)==-1) return;
2516   CopyDialog(&DlgCopy,obj,-1,AxisCB);
2517   if (DialogExecute(TopLevel,&DlgCopy)==IDOK) {
2518     i=DlgCopy.sel;
2519   } else {
2520     return;
2521   }
2522   AxisDel(i);
2523   NgraphApp.Changed=TRUE;
2524   AxisWinUpdate(TRUE);
2525   FileWinUpdate(TRUE);
2526 }
2527 
CmAxisUpdate()2528 void CmAxisUpdate()
2529 {
2530   struct objlist *obj;
2531   int i,ret;
2532 
2533   if (menulock || globallock) return;
2534   if ((obj=chkobject("axis"))==NULL) return;
2535   if (chkobjlastinst(obj)==-1) return;
2536   CopyDialog(&DlgCopy,obj,-1,AxisCB);
2537   if (DialogExecute(TopLevel,&DlgCopy)==IDOK) {
2538     i=DlgCopy.sel;
2539     if (i<0) return;
2540   } else return;
2541   AxisDialog(&DlgAxis,obj,i,TRUE);
2542   if ((ret=DialogExecute(TopLevel,&DlgAxis))==IDDELETE) {
2543     AxisDel(i);
2544   }
2545   if (ret!=IDCANCEL) NgraphApp.Changed=TRUE;
2546   AxisWinUpdate(TRUE);
2547   FileWinUpdate(TRUE);
2548 }
2549 
CmAxisZoom()2550 void CmAxisZoom()
2551 {
2552   struct narray farray;
2553   struct objlist *obj;
2554   int i;
2555   int *array,num,room;
2556   double zoom,min,max,mid,wd;
2557   char *argv[4];
2558 
2559   if (menulock || globallock) return;
2560   if ((obj=chkobject("axis"))==NULL) return;
2561   if (chkobjlastinst(obj)==-1) return;
2562   ZoomDialog(&DlgZoom);
2563   if ((DialogExecute(TopLevel,&DlgZoom)==IDOK) && (DlgZoom.zoom>0)) {
2564     zoom=DlgZoom.zoom/10000.0;
2565     SelectDialog(&DlgSelect,obj,AxisCB,(struct narray *)&farray,NULL);
2566     if (DialogExecute(TopLevel,&DlgSelect)==IDOK) {
2567       num=arraynum(&farray);
2568       array=(int *)arraydata(&farray);
2569       for (i=0;i<num;i++) {
2570         getobj(obj,"min",array[i],0,NULL,&min);
2571         getobj(obj,"max",array[i],0,NULL,&max);
2572         wd=(max-min)/2;
2573         if (wd!=0) {
2574           mid=(min+max)/2;
2575           min=mid-wd*zoom;
2576           max=mid+wd*zoom;
2577           room=1;
2578           argv[0]=(char *)&min;
2579           argv[1]=(char *)&max;
2580           argv[2]=(char *)&room;
2581           argv[3]=NULL;
2582           exeobj(obj,"scale",array[i],3,argv);
2583           NgraphApp.Changed=TRUE;
2584         }
2585       }
2586       AxisWinUpdate(TRUE);
2587     }
2588     arraydel(&farray);
2589   }
2590 }
2591 
CmAxisClear()2592 void CmAxisClear()
2593 {
2594   struct narray farray;
2595   struct objlist *obj;
2596   int i;
2597   int *array,num;
2598 
2599   if (menulock || globallock) return;
2600   if ((obj=chkobject("axis"))==NULL) return;
2601   if (chkobjlastinst(obj)==-1) return;
2602   SelectDialog(&DlgSelect,obj,AxisCB,(struct narray *)&farray,NULL);
2603   if (DialogExecute(TopLevel,&DlgSelect)==IDOK) {
2604     num=arraynum(&farray);
2605     array=(int *)arraydata(&farray);
2606     for (i=0;i<num;i++) {
2607       exeobj(obj,"scale_push",array[i],0,NULL);
2608       exeobj(obj,"clear",array[i],0,NULL);
2609       NgraphApp.Changed=TRUE;
2610     }
2611     AxisWinUpdate(TRUE);
2612   }
2613   arraydel(&farray);
2614 }
2615 
CmAxisMenu(Widget w,XtPointer client_data,XtPointer call_data)2616 void CmAxisMenu(Widget w,XtPointer client_data,XtPointer call_data)
2617 {
2618   switch ((int )client_data) {
2619   case 0:
2620     break;
2621   case 1:
2622     CmAxisUpdate();
2623     break;
2624   case 2:
2625     CmAxisDel();
2626     break;
2627   case 3:
2628     CmAxisZoom();
2629     break;
2630   case 4:
2631     CmAxisClear();
2632     break;
2633   }
2634 }
2635 
CmAxisGridNew()2636 void CmAxisGridNew()
2637 {
2638   struct objlist *obj;
2639   int id,ret;
2640 
2641   if (menulock || globallock) return;
2642   if ((obj=chkobject("axisgrid"))==NULL) return;
2643   if ((id=newobj(obj))>=0) {
2644     GridDialog(&DlgGrid,obj,id);
2645     ret=DialogExecute(TopLevel,&DlgGrid);
2646     if ((ret==IDDELETE) || (ret==IDCANCEL)) {
2647       delobj(obj,id);
2648     } else NgraphApp.Changed=TRUE;
2649   }
2650 }
2651 
CmAxisGridDel()2652 void CmAxisGridDel()
2653 {
2654   struct narray farray;
2655   struct objlist *obj;
2656   int i;
2657   int num,*array;
2658 
2659   if (menulock || globallock) return;
2660   if ((obj=chkobject("axisgrid"))==NULL) return;
2661   if (chkobjlastinst(obj)==-1) return;
2662   SelectDialog(&DlgSelect,obj,GridCB,(struct narray *)&farray,NULL);
2663   if (DialogExecute(TopLevel,&DlgSelect)==IDOK) {
2664     num=arraynum(&farray);
2665     array=(int *)arraydata(&farray);
2666     for (i=num-1;i>=0;i--) {
2667       delobj(obj,array[i]);
2668       NgraphApp.Changed=TRUE;
2669     }
2670   }
2671   arraydel(&farray);
2672 }
2673 
2674 
CmAxisGridUpdate()2675 void CmAxisGridUpdate()
2676 {
2677   struct narray farray;
2678   struct objlist *obj;
2679   int i,j,ret;
2680   int *array,num;
2681 
2682   if (menulock || globallock) return;
2683   if ((obj=chkobject("axisgrid"))==NULL) return;
2684   if (chkobjlastinst(obj)==-1) return;
2685   SelectDialog(&DlgSelect,obj,GridCB,(struct narray *)&farray,NULL);
2686   if (DialogExecute(TopLevel,&DlgSelect)==IDOK) {
2687     num=arraynum(&farray);
2688     array=(int *)arraydata(&farray);
2689     for (i=0;i<num;i++) {
2690       GridDialog(&DlgGrid,obj,array[i]);
2691       if ((ret=DialogExecute(TopLevel,&DlgGrid))==IDDELETE) {
2692         delobj(obj,array[i]);
2693         for (j=i+1;j<num;j++) array[j]--;
2694       }
2695       if (ret!=IDCANCEL) NgraphApp.Changed=TRUE;
2696     }
2697   }
2698   arraydel(&farray);
2699 }
2700 
2701 
CmGridMenu(Widget w,XtPointer client_data,XtPointer call_data)2702 void CmGridMenu(Widget w,XtPointer client_data,XtPointer call_data)
2703 {
2704   switch ((int )client_data) {
2705   case 0:
2706     CmAxisGridNew();
2707     break;
2708   case 1:
2709     CmAxisGridUpdate();
2710     break;
2711   case 2:
2712     CmAxisGridDel();
2713     break;
2714   }
2715 }
2716 
AxisWinAxisDelete()2717 void AxisWinAxisDelete()
2718 {
2719   int sel;
2720   struct AxisWin *d;
2721 
2722   d=&(NgraphApp.AxisWin);
2723   if (menulock || globallock) return;
2724   UnFocus();
2725   sel=d->select;
2726   if ((sel>=0) && (sel<=d->axisnum)) {
2727     AxisDel(sel);
2728     AxisWinUpdate(TRUE);
2729     FileWinUpdate(TRUE);
2730     NgraphApp.Changed=TRUE;
2731   }
2732 }
2733 
AxisWinAxisCopy()2734 void AxisWinAxisCopy()
2735 {
2736   int sel;
2737   int j,id,perm,type;
2738   char *field;
2739   struct AxisWin *d;
2740 
2741   d=&(NgraphApp.AxisWin);
2742   if (menulock || globallock) return;
2743   sel=d->select;
2744   if ((sel>=0) && (sel<=d->axisnum)) {
2745     if ((id=newobj(d->obj))>=0) {
2746       for (j=0;j<chkobjfieldnum(d->obj);j++) {
2747         field=chkobjfieldname(d->obj,j);
2748         perm=chkobjperm(d->obj,field);
2749         type=chkobjfieldtype(d->obj,field);
2750         if (((perm&NREAD)!=0) && ((perm&NWRITE)!=0) && (type<NVFUNC))
2751           copyobj(d->obj,field,id,sel);
2752       }
2753       d->axisnum++;
2754       NgraphApp.Changed=TRUE;
2755     }
2756     d->select=sel;
2757     AxisWinUpdate(FALSE);
2758   }
2759 }
2760 
AxisWinAxisTop()2761 void AxisWinAxisTop()
2762 {
2763   int sel;
2764   struct AxisWin *d;
2765 
2766   d=&(NgraphApp.AxisWin);
2767   if (menulock || globallock) return;
2768   UnFocus();
2769   sel=d->select;
2770   if ((sel>=0) && (sel<=d->axisnum)) {
2771     movetopobj(d->obj,sel);
2772     d->select=0;
2773     AxisMove(sel,0);
2774     AxisWinUpdate(FALSE);
2775     FileWinUpdate(FALSE);
2776     NgraphApp.Changed=TRUE;
2777   }
2778 }
2779 
AxisWinAxisLast()2780 void AxisWinAxisLast()
2781 {
2782   int sel;
2783   struct AxisWin *d;
2784 
2785   d=&(NgraphApp.AxisWin);
2786   if (menulock || globallock) return;
2787   UnFocus();
2788   sel=d->select;
2789   if ((sel>=0) && (sel<=d->axisnum)) {
2790     movelastobj(d->obj,sel);
2791     d->select=d->axisnum;
2792     AxisMove(sel,d->axisnum);
2793     AxisWinUpdate(FALSE);
2794     FileWinUpdate(FALSE);
2795     NgraphApp.Changed=TRUE;
2796   }
2797 }
2798 
AxisWinAxisUp()2799 void AxisWinAxisUp()
2800 {
2801   int sel;
2802   struct AxisWin *d;
2803 
2804   d=&(NgraphApp.AxisWin);
2805   if (menulock || globallock) return;
2806   UnFocus();
2807   sel=d->select;
2808   if ((sel>=1) && (sel<=d->axisnum)) {
2809     moveupobj(d->obj,sel);
2810     d->select=sel-1;
2811     AxisMove(sel,sel-1);
2812     AxisWinUpdate(FALSE);
2813     FileWinUpdate(FALSE);
2814     NgraphApp.Changed=TRUE;
2815   }
2816 }
2817 
AxisWinAxisDown()2818 void AxisWinAxisDown()
2819 {
2820   int sel;
2821   struct AxisWin *d;
2822 
2823   d=&(NgraphApp.AxisWin);
2824   if (menulock || globallock) return;
2825   UnFocus();
2826   sel=d->select;
2827   if ((sel>=0) && (sel<=d->axisnum-1)) {
2828     movedownobj(d->obj,sel);
2829     d->select=sel+1;
2830     AxisMove(sel,sel+1);
2831     AxisWinUpdate(FALSE);
2832     FileWinUpdate(FALSE);
2833     NgraphApp.Changed=TRUE;
2834   }
2835 }
2836 
AxisWinAxisUpdate()2837 void AxisWinAxisUpdate()
2838 {
2839   int sel,ret;
2840   int update;
2841   struct AxisWin *d;
2842 
2843   d=&(NgraphApp.AxisWin);
2844   if (menulock || globallock) return;
2845   UnFocus();
2846   sel=d->select;
2847   update=FALSE;
2848   if ((sel>=0) && (sel<=d->axisnum)) {
2849     AxisDialog(&DlgAxis,d->obj,sel,TRUE);
2850     if ((ret=DialogExecute(TopLevel,&DlgAxis))==IDDELETE) {
2851       AxisDel(sel);
2852       update=TRUE;
2853       d->select=-1;
2854     } else if (ret==IDOK) update=TRUE;
2855     if (ret!=IDCANCEL) NgraphApp.Changed=TRUE;
2856   }
2857   if (update) AxisWinUpdate(FALSE);
2858 }
2859 
AxisWinAxisSelect()2860 void AxisWinAxisSelect()
2861 {
2862   int sel;
2863   struct AxisWin *d;
2864 
2865   d=&(NgraphApp.AxisWin);
2866   if (menulock || globallock) return;
2867   sel=d->select;
2868   if ((sel>=0) && (sel<=d->axisnum)) Focus(d->obj,sel);
2869 }
2870 
AxisWinAxisHidden()2871 void AxisWinAxisHidden()
2872 {
2873   int sel;
2874   int hidden;
2875   struct AxisWin *d;
2876 
2877   d=&(NgraphApp.AxisWin);
2878   if (menulock || globallock) return;
2879   sel=d->select;
2880   if ((sel>=0) && (sel<=d->axisnum)) {
2881     getobj(d->obj,"hidden",sel,0,NULL,&hidden);
2882     hidden=hidden?FALSE:TRUE;
2883     putobj(d->obj,"hidden",sel,&hidden);
2884     AxisWinUpdate(FALSE);
2885     NgraphApp.Changed=TRUE;
2886   }
2887 }
2888 
AxisWinChangeAxisNum()2889 void AxisWinChangeAxisNum()
2890 {
2891   struct AxisWin *d;
2892 
2893   d=&(NgraphApp.AxisWin);
2894   if (d->text==NULL) return;
2895   XtVaSetValues(d->text,XmNheight,(d->axisnum+2)*FHeight,NULL);
2896 }
2897 
AxisWinUpdate(int clear)2898 void AxisWinUpdate(int clear)
2899 {
2900   struct AxisWin *d;
2901 
2902   d=&(NgraphApp.AxisWin);
2903   d->axisnum=chkobjlastinst(d->obj);
2904   AxisWinChangeAxisNum();
2905   if (d->text==NULL) return;
2906   XClearArea(XtDisplay(d->text),XtWindow(d->text),0,0,0,0,TRUE);
2907 }
2908 
AxisWinExpose(Widget wi,XtPointer client_data,XtPointer call_data)2909 void AxisWinExpose(Widget wi,XtPointer client_data,XtPointer call_data)
2910 {
2911   XmDrawingAreaCallbackStruct *dd;
2912   XExposeEvent *e;
2913   Display *disp;
2914   Window win;
2915   GC gc;
2916   int i;
2917   char buf[256];
2918   XRectangle rect;
2919   int h,w,x,y,len,cx;
2920   double min,max,inc;
2921   char *valstr;
2922   int hidden;
2923   char *name;
2924   struct AxisWin *d;
2925 
2926   d=&(NgraphApp.AxisWin);
2927   if (d->text==NULL) return;
2928   dd=(XmDrawingAreaCallbackStruct *)call_data;
2929   e=(XExposeEvent *)(dd->event);
2930   disp=e->display;
2931   win=e->window;
2932   gc=XCreateGC(disp,win,0,0);
2933   if (globallock) return;
2934   d->axisnum=chkobjlastinst(d->obj);
2935   h=FHeight;
2936   w=FWidth;
2937   XSetForeground(disp,gc,gray);
2938   XFillRectangle(disp,win,gc,0,0,72*w+2*w,h);
2939   x=FWidth;
2940   y=FAscent;
2941   XSetForeground(disp,gc,black);
2942   rect.y=y-FAscent;
2943   rect.height=h;
2944   rect.x=x;
2945   rect.width=6*w;
2946   len=sprintf(buf,"#");
2947   ExtTextOut(disp,win,gc,x,y,&rect,buf,len);
2948   x+=6*w;
2949   rect.x=x;
2950   rect.width=5*w;
2951   len=sprintf(buf,"name");
2952   ExtTextOut(disp,win,gc,x,y,&rect,buf,len);
2953   x+=5*w;
2954   rect.x=x;
2955   rect.width=10*w;
2956   len=sprintf(buf,"    min");
2957   ExtTextOut(disp,win,gc,x,y,&rect,buf,len);
2958   x+=10*w;
2959   rect.x=x;
2960   rect.width=10*w;
2961   len=sprintf(buf,"    max");
2962   ExtTextOut(disp,win,gc,x,y,&rect,buf,len);
2963   x+=10*w;
2964   rect.x=x;
2965   rect.width=10*w;
2966   len=sprintf(buf,"    inc");
2967   ExtTextOut(disp,win,gc,x,y,&rect,buf,len);
2968   x+=10*w;
2969   rect.x=x;
2970   rect.width=7*w;
2971   len=sprintf(buf," type  ");
2972   ExtTextOut(disp,win,gc,x,y,&rect,buf,len);
2973   x+=7*w;
2974   rect.x=x;
2975   rect.width=6*w;
2976   len=sprintf(buf,"     x");
2977   ExtTextOut(disp,win,gc,x,y,&rect,buf,len);
2978   x+=6*w;
2979   rect.x=x;
2980   rect.width=6*w;
2981   len=sprintf(buf,"     y");
2982   ExtTextOut(disp,win,gc,x,y,&rect,buf,len);
2983   x+=6*w;
2984   rect.x=x;
2985   rect.width=6*w;
2986   len=sprintf(buf,"   dir");
2987   ExtTextOut(disp,win,gc,x,y,&rect,buf,len);
2988   x+=6*w;
2989   rect.x=x;
2990   rect.width=x+6*w;
2991   len=sprintf(buf,"   len");
2992   ExtTextOut(disp,win,gc,x,y,&rect,buf,len);
2993   x+=6*w;
2994   rect.x=x+w;
2995   rect.width=x+8*w;
2996   len=sprintf(buf,"^#");
2997   ExtTextOut(disp,win,gc,x+w,y,&rect,buf,len);
2998 
2999   for (i=0;i<=d->axisnum;i++) {
3000       x=w;
3001       y=(i+1)*h+FAscent;
3002       rect.y=y-FAscent;
3003       rect.height=h;
3004 
3005       getobj(d->obj,"hidden",i,0,NULL,&hidden);
3006       if (hidden) XSetForeground(disp,gc,gray);
3007       else XSetForeground(disp,gc,black);
3008       if (i==d->select) {
3009         XSetForeground(disp,gc,black);
3010         XFillRectangle(disp,win,gc,0,rect.y,74*w+h+w,rect.height);
3011         XSetForeground(disp,gc,white);
3012       }
3013 
3014       getobj(d->obj,"id",i,0,NULL,&cx);
3015       rect.x=x;
3016       rect.width=6*w;
3017       len=sprintf(buf,"%d",cx);
3018       ExtTextOut(disp,win,gc,x,y,&rect,buf,len);
3019       x+=6*w;
3020 
3021       getobj(d->obj,"group",i,0,NULL,&name);
3022       rect.x=x;
3023       rect.width=5*w;
3024       if (name!=NULL) {
3025         ExtTextOut(disp,win,gc,x,y,&rect,name,strlen(name));
3026       } else {
3027         ExtTextOut(disp,win,gc,x,y,&rect,"....................",20);
3028       }
3029       x+=5*w;
3030 
3031       getobj(d->obj,"min",i,0,NULL,&min);
3032       getobj(d->obj,"max",i,0,NULL,&max);
3033       getobj(d->obj,"inc",i,0,NULL,&inc);
3034 
3035       rect.x=x;
3036       rect.width=10*w;
3037       if ((min==0) && (max==0)) len=sprintf(buf,"---------");
3038       else len=sprintf(buf,"%+.2e",min);
3039       ExtTextOut(disp,win,gc,x,y,&rect,buf,len);
3040       x+=10*w;
3041 
3042       rect.x=x;
3043       rect.width=10*w;
3044       if ((min==0) && (max==0)) len=sprintf(buf,"---------");
3045       else len=sprintf(buf,"%+.2e",max);
3046       ExtTextOut(disp,win,gc,x,y,&rect,buf,len);
3047       x+=10*w;
3048 
3049       rect.x=x;
3050       rect.width=10*w;
3051       if (inc==0) len=sprintf(buf,"---------");
3052       else len=sprintf(buf,"%+.2e",inc);
3053       ExtTextOut(disp,win,gc,x,y,&rect,buf,len);
3054       x+=10*w;
3055 
3056       sgetobjfield(d->obj,i,"type",NULL,&valstr,FALSE,FALSE,FALSE);
3057       rect.x=x+w;
3058       rect.width=7*w;
3059       ExtTextOut(disp,win,gc,x+w,y,&rect,valstr,strlen(valstr));
3060       memfree(valstr);
3061       x+=7*w;
3062 
3063       getobj(d->obj,"x",i,0,NULL,&cx);
3064       rect.x=x;
3065       rect.width=6*w;
3066       len=sprintf(buf,"%6d",cx);
3067       ExtTextOut(disp,win,gc,x,y,&rect,buf,len);
3068       x+=6*w;
3069 
3070       getobj(d->obj,"y",i,0,NULL,&cx);
3071       rect.x=x;
3072       rect.width=6*w;
3073       len=sprintf(buf,"%6d",cx);
3074       ExtTextOut(disp,win,gc,x,y,&rect,buf,len);
3075       x+=6*w;
3076 
3077       getobj(d->obj,"direction",i,0,NULL,&cx);
3078       rect.x=x;
3079       rect.width=6*w;
3080       len=sprintf(buf,"%6d",cx);
3081       ExtTextOut(disp,win,gc,x,y,&rect,buf,len);
3082       x+=6*w;
3083 
3084       getobj(d->obj,"oid",i,0,NULL,&cx);
3085       rect.x=x+w;
3086       rect.width=7*w;
3087       len=sprintf(buf,"^%d",cx);
3088       ExtTextOut(disp,win,gc,x+w,y,&rect,buf,len);
3089       x+=8*w;
3090     }
3091   XFreeGC(disp,gc);
3092 }
3093 
AxisWinEvLButtonDown(unsigned int state,TPoint point,struct AxisWin * d)3094 void AxisWinEvLButtonDown(unsigned int state,TPoint point,struct AxisWin *d)
3095 {
3096   int sel;
3097 
3098   if (menulock || globallock) return;
3099   sel=point.y/FHeight-1;
3100   if (sel!=d->select) {
3101     AxisWinUpdate(FALSE);
3102     d->select=sel;
3103   }
3104 }
3105 
AxisWinEvLButtonDblClk(unsigned int state,TPoint point,struct AxisWin * d)3106 void AxisWinEvLButtonDblClk(unsigned int state,TPoint point,struct AxisWin *d)
3107 {
3108   if (menulock || globallock) return;
3109   AxisWinAxisUpdate();
3110 }
3111 
AxisWinEvRButtonDown(unsigned int state,TPoint point,struct AxisWin * d,XButtonPressedEvent * event)3112 void AxisWinEvRButtonDown(unsigned int state,TPoint point,struct AxisWin *d,
3113                           XButtonPressedEvent *event)
3114 {
3115   int sel;
3116 
3117   if (menulock || globallock) return;
3118   sel=point.y/FHeight-1;
3119   if (sel!=d->select) {
3120     AxisWinUpdate(TRUE);
3121     d->select=sel;
3122   }
3123   sel=d->select;
3124   if ((sel>=0) && (sel<=d->axisnum)) {
3125     XtSetSensitive(XtNameToWidget(d->popup,"button_0"),True);
3126     XtSetSensitive(XtNameToWidget(d->popup,"button_1"),True);
3127     XtSetSensitive(XtNameToWidget(d->popup,"button_2"),True);
3128     XtSetSensitive(XtNameToWidget(d->popup,"button_3"),True);
3129     XtSetSensitive(XtNameToWidget(d->popup,"button_4"),True);
3130     XtSetSensitive(XtNameToWidget(d->popup,"button_5"),True);
3131     XtSetSensitive(XtNameToWidget(d->popup,"button_6"),True);
3132     XtSetSensitive(XtNameToWidget(d->popup,"button_7"),True);
3133     XtSetSensitive(XtNameToWidget(d->popup,"button_8"),True);
3134   } else {
3135     XtSetSensitive(XtNameToWidget(d->popup,"button_0"),False);
3136     XtSetSensitive(XtNameToWidget(d->popup,"button_1"),False);
3137     XtSetSensitive(XtNameToWidget(d->popup,"button_2"),False);
3138     XtSetSensitive(XtNameToWidget(d->popup,"button_3"),False);
3139     XtSetSensitive(XtNameToWidget(d->popup,"button_4"),False);
3140     XtSetSensitive(XtNameToWidget(d->popup,"button_5"),False);
3141     XtSetSensitive(XtNameToWidget(d->popup,"button_6"),False);
3142     XtSetSensitive(XtNameToWidget(d->popup,"button_7"),False);
3143     XtSetSensitive(XtNameToWidget(d->popup,"button_8"),False);
3144   }
3145   XmMenuPosition(d->popup,event);
3146   XtManageChild(d->popup);
3147 }
3148 
3149 Time AxisWinTime=0;
3150 TPoint AxisWinPoint;
3151 
AxisWinEvButtonDown(Widget w,XtPointer client_data,XEvent * event,Boolean * dispatch)3152 void AxisWinEvButtonDown(Widget w,XtPointer client_data,XEvent *event,
3153                          Boolean *dispatch)
3154 {
3155   struct AxisWin *d;
3156   XButtonEvent *e;
3157   TPoint point;
3158   int dbl;
3159 
3160   d=(struct AxisWin *)client_data;
3161   e=(XButtonEvent *)event;
3162   point.x=e->x;
3163   point.y=e->y;
3164   if (((e->time-AxisWinTime)<menulocal.mouseclick)
3165   && (AxisWinPoint.x==point.x) && (AxisWinPoint.y==point.y)) dbl=TRUE;
3166   else dbl=FALSE;
3167   AxisWinTime=e->time;
3168   AxisWinPoint.x=point.x;
3169   AxisWinPoint.y=point.y;
3170   if (e->button==Button1) {
3171     if (dbl) AxisWinEvLButtonDblClk(e->state,point,d);
3172     else AxisWinEvLButtonDown(e->state,point,d);
3173   } else if (e->button==Button2) {
3174     AxisWinEvLButtonDown(e->state,point,d);
3175     AxisWinEvLButtonDblClk(e->state,point,d);
3176   } else if (e->button==Button3) AxisWinEvRButtonDown(e->state,point,d,e);
3177 }
3178 
AxisWinPopupMenu(Widget w,XtPointer client_data,XtPointer call_data)3179 void AxisWinPopupMenu(Widget w,XtPointer client_data,XtPointer call_data)
3180 {
3181   switch ((int )client_data) {
3182   case 0:
3183     AxisWinAxisSelect();
3184     break;
3185   case 1:
3186     AxisWinAxisUpdate();
3187     break;
3188   case 2:
3189     AxisWinAxisDelete();
3190     break;
3191   case 3:
3192     AxisWinAxisTop();
3193     break;
3194   case 4:
3195     AxisWinAxisUp();
3196     break;
3197   case 5:
3198     AxisWinAxisDown();
3199     break;
3200   case 6:
3201     AxisWinAxisLast();
3202     break;
3203   case 7:
3204     AxisWinAxisCopy();
3205     break;
3206   case 8:
3207     AxisWinAxisHidden();
3208     break;
3209   }
3210 }
3211 
AxisWinEvKeyDown(Widget w,XtPointer client_data,XEvent * event,Boolean * dispatch)3212 void AxisWinEvKeyDown(Widget w,XtPointer client_data,XEvent *event,
3213                      Boolean *dispatch)
3214 {
3215   struct AxisWin *d;
3216   XKeyEvent *e;
3217   KeySym sym;
3218   int sel;
3219 
3220   if (menulock || globallock) return;
3221   d=(struct AxisWin *)client_data;
3222   e=(XKeyEvent *)event;
3223   sym=XKeycodeToKeysym(e->display,e->keycode,0);
3224   sel=d->select;
3225   switch (sym) {
3226   case XK_Down:
3227     if (e->state & ShiftMask) AxisWinAxisDown();
3228     else {
3229       if ((sel==-1) && (d->axisnum>=0)) sel=0;
3230       else if (sel<d->axisnum) sel++;
3231       if (sel!=d->select) {
3232         d->select=sel;
3233         AxisWinUpdate(TRUE);
3234       }
3235     }
3236     break;
3237   case XK_Up:
3238     if (e->state & ShiftMask) AxisWinAxisUp();
3239     else {
3240       if ((sel==-1) && (d->axisnum>=0)) sel=d->axisnum;
3241       else if (sel>0) sel--;
3242       if (sel!=d->select) {
3243         d->select=sel;
3244         AxisWinUpdate(TRUE);
3245       }
3246     }
3247     break;
3248   case XK_Delete:
3249     AxisWinAxisDelete();
3250     break;
3251   case XK_Insert:
3252     AxisWinAxisCopy();
3253     break;
3254   case XK_Home:
3255     if (e->state & ShiftMask) AxisWinAxisTop();
3256     break;
3257   case XK_End:
3258     if (e->state & ShiftMask) AxisWinAxisLast();
3259     break;
3260   case XK_Return:
3261     AxisWinAxisUpdate();
3262     break;
3263   case XK_space:
3264     AxisWinAxisSelect();
3265     break;
3266   case XK_BackSpace:
3267     AxisWinAxisHidden();
3268     break;
3269   }
3270 }
3271 
AxisWindowUnmap(Widget w,XtPointer client_data,XtPointer call_data)3272 void AxisWindowUnmap(Widget w,XtPointer client_data,XtPointer call_data)
3273 {
3274   struct AxisWin *d;
3275   Position x,y,x0,y0;
3276   Dimension w0,h0;
3277 
3278   d=&(NgraphApp.AxisWin);
3279   if (d->Win!=NULL) {
3280     XtVaGetValues(d->Win,XmNx,&x,XmNy,&y,
3281                          XmNwidth,&w0,XmNheight,&h0,NULL);
3282     menulocal.axiswidth=w0;
3283     menulocal.axisheight=h0;
3284     XtTranslateCoords(TopLevel,0,0,&x0,&y0);
3285     menulocal.axisx=x-x0;
3286     menulocal.axisy=y-y0;
3287     XtDestroyWidget(d->Win);
3288     d->Win=NULL;
3289     d->text=NULL;
3290     XmToggleButtonSetState(XtNameToWidget(TopLevel,"*windowmenu.button_1"),
3291                            False,False);
3292   }
3293 }
3294 
CmAxisWinScaleUndo(Widget w,XtPointer client_data,XtPointer call_data)3295 void CmAxisWinScaleUndo(Widget w,XtPointer client_data,XtPointer call_data)
3296 {
3297   struct AxisWin *d;
3298   char *argv[1];
3299   struct objlist *obj;
3300   struct narray farray;
3301   int i,num,*array;
3302 
3303   if (menulock || globallock) return;
3304   d=&(NgraphApp.AxisWin);
3305   if ((obj=chkobject("axis"))==NULL) return;
3306   if (chkobjlastinst(obj)==-1) return;
3307   SelectDialog(&DlgSelect,obj,AxisCB,(struct narray *)&farray,NULL);
3308   if (DialogExecute(TopLevel,&DlgSelect)==IDOK) {
3309     num=arraynum(&farray);
3310     array=(int *)arraydata(&farray);
3311     for (i=num-1;i>=0;i--) {
3312       argv[0]=NULL;
3313       exeobj(obj,"scale_pop",array[i],0,argv);
3314       NgraphApp.Changed=TRUE;
3315     }
3316     AxisWinUpdate(TRUE);
3317   }
3318   arraydel(&farray);
3319 }
3320 
CmAxisWindow(Widget w,XtPointer client_data,XtPointer call_data)3321 void CmAxisWindow(Widget w,XtPointer client_data,XtPointer call_data)
3322 {
3323   Arg al[20];
3324   Cardinal ac;
3325   Widget dlg,scw,clip;
3326   int width,height;
3327   Position x,y;
3328   struct AxisWin *d;
3329 
3330   d=&(NgraphApp.AxisWin);
3331   if (d->Win!=NULL) {
3332     XtUnmanageChild(d->Win);
3333   } else {
3334     if (menulocal.axiswidth==CW_USEDEFAULT) width=FWidth*72+2*FWidth;
3335     else width=menulocal.axiswidth;
3336     if (menulocal.axisheight==CW_USEDEFAULT) height=FHeight*10;
3337     else height=menulocal.axisheight;
3338     ac=0;
3339     XtSetArg(al[ac],XmNborderWidth,1);ac++;
3340     XtSetArg(al[ac],XmNdialogStyle,XmDIALOG_MODELESS); ac++;
3341     XtSetArg(al[ac],XmNautoUnmanage,FALSE); ac++;
3342     XtSetArg(al[ac],XmNwidth,width); ac++;
3343     XtSetArg(al[ac],XmNheight,height); ac++;
3344     if ((menulocal.axisx!=CW_USEDEFAULT)
3345     && (menulocal.axisy!=CW_USEDEFAULT)) {
3346       XtTranslateCoords(TopLevel,menulocal.axisx,menulocal.axisy,&x,&y);
3347       x-=menulocal.framex;
3348       y-=menulocal.framey;
3349       if (x<0) x=0;
3350       if (y<0) y=0;
3351       XtSetArg(al[ac],XmNdefaultPosition,False); ac++;
3352       XtSetArg(al[ac],XmNx,x); ac++;
3353       XtSetArg(al[ac],XmNy,y); ac++;
3354     } else {
3355       XtSetArg(al[ac],XmNdefaultPosition,True); ac++;
3356     }
3357     XtManageChild(dlg=XmCreateFormDialog(TopLevel,"axiswindow",al,ac));
3358     d->Win=dlg;
3359     XtAddCallback(dlg,XmNunmapCallback,AxisWindowUnmap,NULL);
3360     ac=0;
3361     XtSetArg(al[ac],XmNtopAttachment,XmATTACH_FORM); ac++;
3362     XtSetArg(al[ac],XmNbottomAttachment,XmATTACH_FORM); ac++;
3363     XtSetArg(al[ac],XmNleftAttachment,XmATTACH_FORM); ac++;
3364     XtSetArg(al[ac],XmNrightAttachment,XmATTACH_FORM); ac++;
3365     XtSetArg(al[ac],XmNalignment,XmALIGNMENT_BEGINNING); ac++;
3366     XtSetArg(al[ac],XmNscrollingPolicy,XmAUTOMATIC); ac++;
3367     XtSetArg(al[ac],XmNscrollBarDisplayPolicy,XmSTATIC); ac++;
3368     XtSetArg(al[ac],XmNwidth,width); ac++;
3369     XtSetArg(al[ac],XmNheight,height); ac++;
3370     XtSetArg(al[ac],XmNborderWidth,0);ac++;
3371     XtManageChild(scw=XmCreateScrolledWindow(dlg,NULL,al,ac));
3372     ac=0;
3373     XtSetArg(al[ac],XmNwidth,FWidth*72+2*FWidth); ac++;
3374     XtSetArg(al[ac],XmNheight,height); ac++;
3375     XtSetArg(al[ac],XmNbackground,WhitePixel(XtDisplay(TopLevel),0)); ac++;
3376     XtManageChild(d->text=XmCreateDrawingArea(scw,NULL,al,ac));
3377     XtVaGetValues(scw,XmNclipWindow,&clip,NULL);
3378     XtVaSetValues(clip,XmNbackground,WhitePixel(XtDisplay(TopLevel),0),NULL);
3379     XtAddCallback(d->text,XmNexposeCallback,AxisWinExpose,NULL);
3380     XtAddEventHandler(d->text,ButtonPressMask,False,AxisWinEvButtonDown,d);
3381     d->obj=chkobject("axis");
3382     d->axisnum=chkobjlastinst(d->obj);
3383     AxisWinChangeAxisNum();
3384     d->select=-1;
3385     d->popup=XmVaCreateSimplePopupMenu(d->text,"axispopup",AxisWinPopupMenu,
3386     XmVaPUSHBUTTON,NULL,NULL,NULL,NULL,
3387     XmVaPUSHBUTTON,NULL,NULL,NULL,NULL,
3388     XmVaPUSHBUTTON,NULL,NULL,NULL,NULL,
3389     XmVaPUSHBUTTON,NULL,NULL,NULL,NULL,
3390     XmVaPUSHBUTTON,NULL,NULL,NULL,NULL,
3391     XmVaPUSHBUTTON,NULL,NULL,NULL,NULL,
3392     XmVaPUSHBUTTON,NULL,NULL,NULL,NULL,
3393     XmVaPUSHBUTTON,NULL,NULL,NULL,NULL,
3394     XmVaPUSHBUTTON,NULL,NULL,NULL,NULL,
3395     NULL);
3396     XtAddEventHandler(d->text,KeyPressMask,False,AxisWinEvKeyDown,d);
3397     XmToggleButtonSetState(XtNameToWidget(TopLevel,"*windowmenu.button_1"),
3398                            True,False);
3399   }
3400 }
3401