1 /********************************************************************
2 This file is part of the abs 0.907 distribution. abs is a spreadsheet
3 with graphical user interface.
4
5 Copyright (C) 1998-2001 Andr� Bertin (Andre.Bertin@ping.be)
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version if in the same spirit as version 2.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
21 Concact: abs@pi.be
22 http://home.pi.be/bertin/abs.shtml
23
24 *********************************************************************/
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51 #include "plotdialog.h"
52 #include "application.h"
53 #include "main.h"
54 #include "callback.h"
55 #include "button.h"
56 #include "graph.h"
57 #include "param.h"
58 #include "mydialog.h"
59 #include "grap.xpm"
60
61 static char *plot_type[] =
62 {
63 "XY ",
64 "Pie ",
65 "Bar ",
66 " ",
67 " ",
68 };
69 static char *plotpane[] =
70 {
71 "type",
72 "range",
73 "labels",
74 "grid",
75 "axis",
76 };
77
78 static char *serie[] =
79 {
80 "X",
81 "Y1",
82 "Y2",
83 "Y3",
84 "Y4",
85 "Y5",
86 "Y6",
87 "Y7",
88 " ",
89 };
90
91 static int selectedtype = -1;
92 static int previousrange = 1;
93
94 extern Widget gettop ();
95
96 ThumbDialog *td2;
97 Widget plottype;
98 Widget typelist;
99 Widget range;
100 Widget ranges;
101 Widget wdeleterange;
102 Widget seriename;
103 Widget titre1;
104 Widget Xaxis;
105 Widget Yaxis;
106 Widget btn;
107 Widget btn2;
108 Widget btn3;
109 Widget btn4;
110 Widget btn5;
111 Widget hgrid;
112 Widget vgrid;
113 Widget ymax, ymin, yunit, xmax, xmin, xunit;
114 Widget ymaxv, yminv, yunitv, xmaxv, xminv, xunitv;
115
116
117 void
X11m_plottype()118 X11m_plottype ()
119 {
120 selectedtype = -1;
121 activepane (td2, 0);
122 display_prompt (td2, gettop ());
123 }
124
125 void
X11m_plotdata()126 X11m_plotdata ()
127 {
128 selectedtype = -1;
129 activepane (td2, 1);
130 display_prompt (td2, gettop ());
131 }
132
133 void
X11m_plotoption()134 X11m_plotoption ()
135 {
136 char *buf;
137 char name[32];
138 char buf1[32];
139 int serie;
140 Arg arglist[1];
141 selectedtype = -1;
142
143 if (ActiveGraph == NULL)
144 return;
145
146 buf = (char *) gettitre1 ();
147 if (buf != NULL)
148 {
149 XtSetArg (arglist[0], XtNstring, buf);
150 XtSetValues (titre1, arglist, 1);
151 }
152 else
153 {
154 XtSetArg (arglist[0], XtNstring, "");
155 XtSetValues (titre1, arglist, 1);
156 }
157
158 buf = (char *) getXaxis ();
159 if (buf != NULL)
160 {
161 XtSetArg (arglist[0], XtNstring, buf);
162 XtSetValues (Xaxis, arglist, 1);
163 }
164 else
165 {
166 XtSetArg (arglist[0], XtNstring, "");
167 XtSetValues (Xaxis, arglist, 1);
168 }
169
170 buf = (char *) getYaxis ();
171 if (buf != NULL)
172 {
173 XtSetArg (arglist[0], XtNstring, buf);
174 XtSetValues (Yaxis, arglist, 1);
175 }
176 else
177 {
178 XtSetArg (arglist[0], XtNstring, "");
179 XtSetValues (Yaxis, arglist, 1);
180 }
181
182
183
184
185 serie = 1;
186 XawListHighlight (ranges, serie - 1);
187 getrange (serie, buf1, name);
188 if (buf1 != NULL)
189 {
190 XtSetArg (arglist[0], XtNstring, &buf1);
191 XtSetValues (range, arglist, 1);
192 }
193
194 if (name != NULL)
195 {
196 XtSetArg (arglist[0], XtNstring, &name);
197 XtSetValues (seriename, arglist, 1);
198 }
199
200 if (ActiveGraph != NULL)
201 {
202 setcheck (vgrid, ActiveGraph->Axes[xlCategory].HasMajorGridLines);
203 setcheck (hgrid, ActiveGraph->Axes[xlValue].HasMajorGridLines);
204
205 setcheck (xmin, ActiveGraph->Axes[xlCategory].MinimumScaleIsAuto);
206 SetEntryVal (xminv, ActiveGraph->Axes[xlCategory].MinimumScale);
207
208 setcheck (xmax, ActiveGraph->Axes[xlCategory].MaximumScaleIsAuto);
209 SetEntryVal (xmaxv, ActiveGraph->Axes[xlCategory].MaximumScale);
210
211 setcheck (xunit, ActiveGraph->Axes[xlCategory].MajorUnitIsAuto);
212 SetEntryVal (xunitv, ActiveGraph->Axes[xlCategory].MajorUnit);
213
214 setcheck (ymin, ActiveGraph->Axes[xlValue].MinimumScaleIsAuto);
215 SetEntryVal (yminv, ActiveGraph->Axes[xlValue].MinimumScale);
216
217 setcheck (ymax, ActiveGraph->Axes[xlValue].MaximumScaleIsAuto);
218 SetEntryVal (ymaxv, ActiveGraph->Axes[xlValue].MaximumScale);
219
220 setcheck (yunit, ActiveGraph->Axes[xlValue].MajorUnitIsAuto);
221 SetEntryVal (yunitv, ActiveGraph->Axes[xlValue].MajorUnit);
222
223 }
224
225 previousrange = 1;
226
227 display_prompt (td2, gettop ());
228 }
229
230 void
initplotdial()231 initplotdial ()
232 {
233 int type = 0;
234
235 if (ActiveGraph != NULL)
236 {
237 type = ActiveGraph->type;
238
239 XawListHighlight (typelist, type);
240
241 }
242
243
244 }
245
246
247 void
formatplot()248 formatplot ()
249 {
250 char *str;
251 Arg arglist[1];
252 Boolean on;
253 int *touched_pane = (int *) get_touched_pane (td2);
254
255
256 if (touched_pane[0])
257 {
258 if (selectedtype >= 0)
259 setgraphtype (selectedtype);
260 }
261 if (touched_pane[1])
262 {
263 char *str1;
264 char *str2;
265 XtSetArg (arglist[0], XtNstring, &str1);
266 XtGetValues (range, arglist, 1);
267 XtSetArg (arglist[0], XtNstring, &str2);
268 XtGetValues (seriename, arglist, 1);
269 setrange (previousrange, str1, str2);
270 }
271 if (touched_pane[2])
272 {
273 XtSetArg (arglist[0], XtNstring, &str);
274 XtGetValues (titre1, arglist, 1);
275 settitre1 (str);
276 XtSetArg (arglist[0], XtNstring, &str);
277 XtGetValues (Xaxis, arglist, 1);
278 setXaxis (str);
279 XtGetValues (Yaxis, arglist, 1);
280 setYaxis (str);
281 }
282 if (touched_pane[3])
283 {
284 XtSetArg (arglist[0], XtNstate, &on);
285 XtGetValues (vgrid, arglist, 1);
286 setgridv (on);
287 XtSetArg (arglist[0], XtNstate, &on);
288 XtGetValues (hgrid, arglist, 1);
289 setgridh (on);
290 }
291
292 if (touched_pane[4])
293 if (ActiveGraph != NULL)
294 {
295 ActiveGraph->Axes[xlCategory].MinimumScaleIsAuto = getcheck (xmin);
296 ActiveGraph->Axes[xlCategory].MinimumScale = GetEntryVal (xminv);
297
298 ActiveGraph->Axes[xlCategory].MaximumScaleIsAuto = getcheck (xmax);
299 ActiveGraph->Axes[xlCategory].MaximumScale = GetEntryVal (xmaxv);
300
301 ActiveGraph->Axes[xlCategory].MajorUnitIsAuto = getcheck (xunit);
302 ActiveGraph->Axes[xlCategory].MajorUnit = GetEntryVal (xunitv);
303
304 ActiveGraph->Axes[xlValue].MinimumScaleIsAuto = getcheck (ymin);
305 ActiveGraph->Axes[xlValue].MinimumScale = GetEntryVal (yminv);
306
307 ActiveGraph->Axes[xlValue].MaximumScaleIsAuto = getcheck (ymax);
308 ActiveGraph->Axes[xlValue].MaximumScale = GetEntryVal (ymaxv);
309
310 ActiveGraph->Axes[xlValue].MajorUnitIsAuto = getcheck (yunit);
311 ActiveGraph->Axes[xlValue].MajorUnit = GetEntryVal (yunitv);
312
313 }
314
315 plot ();
316
317 }
318
319 void
graprange(w,pointer,call_data)320 graprange (w, pointer, call_data)
321 Widget w;
322 XtPointer pointer;
323 XtPointer call_data;
324 {
325 ThumbDialog *td = (ThumbDialog *) pointer;
326 XtUnmanageChild (td->promptShell);
327
328 cb_grap (range, td->promptShell);
329 }
330
331 void
grapseriename(w,pointer,call_data)332 grapseriename (w, pointer, call_data)
333 Widget w;
334 XtPointer pointer;
335 XtPointer call_data;
336 {
337 ThumbDialog *td = (ThumbDialog *) pointer;
338 XtUnmanageChild (td->promptShell);
339
340 cb_grap (seriename, td->promptShell);
341
342 }
343 void
graptitre1(w,pointer,call_data)344 graptitre1 (w, pointer, call_data)
345 Widget w;
346 XtPointer pointer;
347 XtPointer call_data;
348 {
349 ThumbDialog *td = (ThumbDialog *) pointer;
350 XtUnmanageChild (td->promptShell);
351
352 cb_grap (titre1, td->promptShell);
353
354
355 }
356 void
grapXaxis(w,pointer,call_data)357 grapXaxis (w, pointer, call_data)
358 Widget w;
359 XtPointer pointer;
360 XtPointer call_data;
361 {
362 ThumbDialog *td = (ThumbDialog *) pointer;
363 XtUnmanageChild (td->promptShell);
364
365 cb_grap (Xaxis, td->promptShell);
366 }
367
368 void
grapYaxis(w,pointer,call_data)369 grapYaxis (w, pointer, call_data)
370 Widget w;
371 XtPointer pointer;
372 XtPointer call_data;
373 {
374 ThumbDialog *td = (ThumbDialog *) pointer;
375 XtUnmanageChild (td->promptShell);
376
377 cb_grap (Yaxis, td->promptShell);
378 }
379
380
381
382
383 void
updaterange(w,closure,call_data)384 updaterange (w, closure, call_data)
385 Widget w;
386 XtPointer closure, call_data;
387 {
388 Arg arglist[1];
389 int serie;
390 char buf[32];
391 char name[32];
392
393 char *str1;
394 char *str2;
395 XawListReturnStruct *item;
396
397 XtSetArg (arglist[0], XtNstring, &str1);
398 XtGetValues (range, arglist, 1);
399 XtSetArg (arglist[0], XtNstring, &str2);
400 XtGetValues (seriename, arglist, 1);
401 setrange (previousrange, str1, str2);
402
403
404 item = (XawListReturnStruct *) call_data;
405 serie = item->list_index + 1;
406 previousrange = serie;
407 getrange (serie, buf, name);
408 XtSetArg (arglist[0], XtNstring, &buf);
409 XtSetValues (range, arglist, 1);
410 XtSetArg (arglist[0], XtNstring, &name);
411 XtSetValues (seriename, arglist, 1);
412 }
413
414 void
DeleteRangeAction(w,closure,call_data)415 DeleteRangeAction (w, closure, call_data)
416 Widget w;
417 XtPointer closure, call_data;
418 {
419 int serie;
420 char buf[32];
421 char name[32];
422 Arg arglist[1];
423 if (previousrange <= 0)
424 return;
425 deleterange (previousrange);
426 serie = previousrange;
427 getrange (serie, buf, name);
428 XtSetArg (arglist[0], XtNstring, &buf);
429 XtSetValues (range, arglist, 1);
430 XtSetArg (arglist[0], XtNstring, &name);
431 XtSetValues (seriename, arglist, 1);
432
433 }
434
435
436 void
set_plottype(w,closure,call_data)437 set_plottype (w, closure, call_data)
438 Widget w;
439 XtPointer closure, call_data;
440 {
441 XawListReturnStruct *item = (XawListReturnStruct *) call_data;
442 selectedtype = item->list_index;
443 }
444
445
446 int
make_plot_dial()447 make_plot_dial ()
448 {
449 Widget viewport, viewport2;
450 Widget base;
451
452 td2 = CreateThumbDialog (gettop (), XtNumber (plotpane), plotpane, formatplot, initplotdial);
453
454 base = (Widget) get_base (td2);
455
456 w_n = 0;
457 w_bord (0);
458 w_dim (100, 120);
459 w_rel (NULL, 20, 55);
460 XtSetArg (w_args[w_n], XtNuseRight, True);
461 w_n++;
462 XtSetArg (w_args[w_n], XtNallowVert, True);
463 w_n++;
464 XtSetArg (w_args[w_n], XtNforceBars, True);
465 w_n++;
466 viewport = XtCreateManagedWidget ("viewport",
467 viewportWidgetClass, base, w_args, w_n);
468
469 addshadow (viewport, 6);
470 addpanechild (td2, 0, viewport);
471
472 w_n = 0;
473 w_bord (0);
474 XtSetArg (w_args[w_n], XtNdefaultColumns, 1);
475 w_n++;
476 XtSetArg (w_args[w_n], XtNforceColumns, True);
477 w_n++;
478 w_bONw ();
479 typelist = XtCreateManagedWidget ("typelist", listWidgetClass,
480 viewport, w_args, w_n);
481 XtAddCallback (typelist, XtNcallback, set_plottype, NULL);
482 XawListChange (typelist, plot_type, 3, 0, True);
483
484
485 w_n = 0;
486 w_bord (0);
487 w_dim (100, 120);
488 w_rel (NULL, 20, 55);
489 XtSetArg (w_args[w_n], XtNuseRight, True);
490 w_n++;
491 XtSetArg (w_args[w_n], XtNallowVert, True);
492 w_n++;
493 XtSetArg (w_args[w_n], XtNforceBars, True);
494 w_n++;
495 viewport2 = XtCreateManagedWidget ("viewport",
496 viewportWidgetClass, base, w_args, w_n);
497 addshadow (viewport2, 6);
498
499 addpanechild (td2, 1, viewport2);
500
501 w_n = 0;
502 w_bord (0);
503 XtSetArg (w_args[w_n], XtNdefaultColumns, 1);
504 w_n++;
505 XtSetArg (w_args[w_n], XtNforceColumns, True);
506 w_n++;
507
508 w_bONw ();
509 ranges = XtCreateManagedWidget ("list", listWidgetClass,
510 viewport2, w_args, w_n);
511 XtAddCallback (ranges, XtNcallback, updaterange, NULL);
512 XawListChange (ranges, serie, 8, 0, True);
513
514 addpanechild (td2, 1, CreateLabel (base, "Range", 160, 35, 80, 20));
515 range = CreateEntry (base, "test", 160, 60, 100, 20, "");
516 w_n = 0;
517 w_bONw ();
518 w_set (range);
519 XtAddEventHandler (range,
520 ExposureMask,
521 FALSE,
522 shadow3,
523 (XtPointer) range);
524
525 addpanechild (td2, 1, range);
526
527
528 w_n = 0;
529 w_rel (NULL, 270, 60);
530 btn = (Widget) make_button_pixmap (base, "grap", grap_xpm, graprange, (XtPointer) td2);
531 XtSetValues (btn, w_args, w_n);
532 addpanechild (td2, 1, btn);
533
534 w_n = 0;
535 w_dim (85, 20);
536 w_rel (NULL, 160, 160);
537 wdeleterange = XtCreateManagedWidget
538 ("Delete", commandWidgetClass, base, w_args, w_n);
539 XtAddCallback (wdeleterange, XtNcallback, DeleteRangeAction, NULL);
540 addpanechild (td2, 1, wdeleterange);
541
542
543
544
545 addpanechild (td2, 1, CreateLabel (base, "Name", 160, 90, 80, 20));
546 seriename = CreateEntry (base, "text", 160, 115, 100, 20, "");
547 w_n = 0;
548 w_bONw ();
549 w_set (seriename);
550 XtAddEventHandler (seriename,
551 ExposureMask,
552 FALSE,
553 shadow3,
554 (XtPointer) seriename);
555
556 addpanechild (td2, 1, seriename);
557
558 w_n = 0;
559 w_rel (NULL, 270, 115);
560 btn2 = (Widget) make_button_pixmap (base, "grap", grap_xpm, grapseriename, (XtPointer) td2);
561 XtSetValues (btn2, w_args, w_n);
562 addpanechild (td2, 1, btn2);
563
564
565
566
567
568
569
570 addpanechild (td2, 2, CreateLabel (base, "Titre 1", 20, 35, 80, 20));
571 titre1 = CreateEntry (base, "text", 110, 35, 180, 20, "");
572 w_n = 0;
573 w_bONw ();
574 w_set (titre1);
575 XtAddEventHandler (titre1,
576 ExposureMask,
577 FALSE,
578 shadow3,
579 (XtPointer) titre1);
580
581 addpanechild (td2, 2, titre1);
582 w_n = 0;
583 w_rel (NULL, 300, 35);
584 btn3 = (Widget) make_button_pixmap (base, "grap", grap_xpm, graptitre1, (XtPointer) td2);
585 XtSetValues (btn3, w_args, w_n);
586 addpanechild (td2, 2, btn3);
587
588
589 addpanechild (td2, 2, CreateLabel (base, "X Axis", 20, 65, 80, 20));
590 Xaxis = CreateEntry (base, "text", 110, 65, 180, 20, "");
591 w_n = 0;
592 w_bONw ();
593 w_set (Xaxis);
594 XtAddEventHandler (Xaxis,
595 ExposureMask,
596 FALSE,
597 shadow3,
598 (XtPointer) Xaxis);
599 addpanechild (td2, 2, Xaxis);
600
601 w_n = 0;
602 w_rel (NULL, 300, 65);
603 btn4 = (Widget) make_button_pixmap (base, "grap", grap_xpm, grapXaxis, (XtPointer) td2);
604 XtSetValues (btn4, w_args, w_n);
605 addpanechild (td2, 2, btn4);
606
607
608 addpanechild (td2, 2, CreateLabel (base, "Y Axis", 20, 95, 80, 20));
609 Yaxis = CreateEntry (base, "text", 110, 95, 180, 20, "");
610 w_n = 0;
611 w_bONw ();
612 w_set (Yaxis);
613 XtAddEventHandler (Yaxis,
614 ExposureMask,
615 FALSE,
616 shadow3,
617 (XtPointer) Yaxis);
618 addpanechild (td2, 2, Yaxis);
619
620
621 w_n = 0;
622 w_rel (NULL, 300, 95);
623 btn5 = (Widget) make_button_pixmap (base, "grap", grap_xpm, grapYaxis, (XtPointer) td2);
624 XtSetValues (btn5, w_args, w_n);
625 addpanechild (td2, 2, btn5);
626
627
628 addpanechild (td2, 3, CreateLabel (base, "Vertical grid", 20, 35, 80, 20));
629
630 w_n = 0;
631 w_rel (NULL, 130, 35);
632 vgrid = (Widget) make_check (base, "vgrid", NULL, (XtPointer) td2);
633 XtSetValues (vgrid, w_args, w_n);
634 addpanechild (td2, 3, vgrid);
635
636 addpanechild (td2, 3, CreateLabel (base, "Horizontal grid", 20, 65, 80, 20));
637
638 w_n = 0;
639 w_rel (NULL, 130, 65);
640 hgrid = (Widget) make_check (base, "hgrid", NULL, (XtPointer) td2);
641 XtSetValues (hgrid, w_args, w_n);
642 addpanechild (td2, 3, hgrid);
643
644 activepane (td2, 0);
645
646
647 addpanechild (td2, 4, CreateLabel (base, "Automatic", 10, 35, 100, 22));
648 addpanechild (td2, 4, CreateLabel (base, "X Minimum", 30, 60, 100, 22));
649 addpanechild (td2, 4, CreateLabel (base, "X Maximum", 30, 85, 100, 22));
650 addpanechild (td2, 4, CreateLabel (base, "X Unit", 30, 110, 100, 22));
651 addpanechild (td2, 4, CreateLabel (base, "Y Minimum", 30, 135, 100, 22));
652 addpanechild (td2, 4, CreateLabel (base, "Y Maximum", 30, 160, 100, 22));
653 addpanechild (td2, 4, CreateLabel (base, "Y Unit", 30, 185, 100, 22));
654
655 w_n = 0;
656 w_rel (NULL, 10, 60);
657 xmin = (Widget) make_check (base, "xmin", NULL, (XtPointer) td2);
658 XtSetValues (xmin, w_args, w_n);
659 addpanechild (td2, 4, xmin);
660
661 w_n = 0;
662 w_rel (NULL, 10, 85);
663 xmax = (Widget) make_check (base, "xmax", NULL, (XtPointer) td2);
664 XtSetValues (xmax, w_args, w_n);
665 addpanechild (td2, 4, xmax);
666
667 w_n = 0;
668 w_rel (NULL, 10, 110);
669 xunit = (Widget) make_check (base, "xunit", NULL, (XtPointer) td2);
670 XtSetValues (xunit, w_args, w_n);
671 addpanechild (td2, 4, xunit);
672
673 w_n = 0;
674 w_rel (NULL, 10, 135);
675 ymin = (Widget) make_check (base, "ymin", NULL, (XtPointer) td2);
676 XtSetValues (ymin, w_args, w_n);
677 addpanechild (td2, 4, ymin);
678
679 w_n = 0;
680 w_rel (NULL, 10, 160);
681 ymax = (Widget) make_check (base, "ymax", NULL, (XtPointer) td2);
682 XtSetValues (ymax, w_args, w_n);
683 addpanechild (td2, 4, ymax);
684
685 w_n = 0;
686 w_rel (NULL, 10, 185);
687 yunit = (Widget) make_check (base, "yunit", NULL, (XtPointer) td2);
688 XtSetValues (yunit, w_args, w_n);
689 addpanechild (td2, 4, yunit);
690
691 xminv = CreateEntry (base, "xminv", 160, 60, 150, 22, "");
692 XtAddEventHandler (xminv, ExposureMask, FALSE, shadow3, (XtPointer) xminv);
693 addpanechild (td2, 4, xminv);
694
695 xmaxv = CreateEntry (base, "xmaxv", 160, 85, 150, 22, "");
696 XtAddEventHandler (xmaxv, ExposureMask, FALSE, shadow3, (XtPointer) xmaxv);
697 addpanechild (td2, 4, xmaxv);
698
699 xunitv = CreateEntry (base, "xunitv", 160, 110, 150, 22, "");
700 XtAddEventHandler (xunitv, ExposureMask, FALSE, shadow3, (XtPointer) xunitv);
701 addpanechild (td2, 4, xunitv);
702 yminv = CreateEntry (base, "yminv", 160, 135, 150, 22, "");
703 XtAddEventHandler (yminv, ExposureMask, FALSE, shadow3, (XtPointer) yminv);
704 addpanechild (td2, 4, yminv);
705 ymaxv = CreateEntry (base, "ymaxv", 160, 160, 150, 22, "");
706 XtAddEventHandler (ymaxv, ExposureMask, FALSE, shadow3, (XtPointer) ymaxv);
707 addpanechild (td2, 4, ymaxv);
708 yunitv = CreateEntry (base, "yunitv", 160, 185, 150, 22, "");
709 XtAddEventHandler (yunitv, ExposureMask, FALSE, shadow3, (XtPointer) yunitv);
710 addpanechild (td2, 4, yunitv);
711
712 activepane (td2, 0);
713
714 return 0;
715 }
716