3
char cur_filename[FSIZE];
6
* FIG : Facility for Interactive Generation of figures
7
* Copyright (c) 1991 by Brian V. Smith
9
* "Permission to use, copy, modify, distribute, and sell this software and its
10
* documentation for any purpose is hereby granted without fee, provided that
11
* the above copyright notice appear in all copies and that both the copyright
12
* notice and this permission notice appear in supporting documentation.
13
* No representations are made about the suitability of this software for
14
* any purpose. It is provided "as is" without express or implied warranty."
19
#include "wf_resources.h"
22
#include "wf_w_drawprim.h" /* for char_height */
24
#include "wf_w_util.h"
25
#include "wf_w_setup.h"
29
#include "../machine.h"
30
#include "All-extern.h"
31
#include "../menusX/men_scilab.h"
33
extern Boolean file_msg_is_popped;
34
extern Widget file_msg_popup;
35
Boolean warnexist=True;
37
static void file_panel_dismiss __PARAMS((void));
38
static void file_panel_cancel __PARAMS((Widget w, XButtonEvent *ev));
40
/* don't allow newlines in text until we handle multiple line texts */
41
String text_translations =
42
"<Key>Return: no-op(RingBell)\n\
43
Ctrl<Key>J: no-op(RingBell)\n\
44
Ctrl<Key>M: no-op(RingBell)\n\
45
Ctrl<Key>X: EmptyTextKey()\n\
46
Ctrl<Key>U: multiply(4)\n\
47
<Key>F18: PastePanelKey()\n";
49
DeclareStaticArgs(12);
51
static Widget cfile_lab, cfile_text;
52
static Widget cancel,ok, exec,load,getf,getfc,linkf;
54
static Position xposn, yposn;
55
static String file_name_translations =
56
"<Key>Return: exec()\n";
58
static void file_panel_cancel();
59
void do_ok(),do_exec(), do_load(),do_getf(),do_getfc(),do_linkf();
60
static XtActionsRec file_name_actions[] =
62
{"exec", (XtActionProc) do_exec},
63
{"ok", (XtActionProc) do_ok},
65
static String file_translations =
66
"<Message>WM_PROTOCOLS: DismissFile()\n";
67
static XtActionsRec file_actions[] =
69
{"DismissFile", (XtActionProc) file_panel_cancel},
70
{"cancel", (XtActionProc) file_panel_cancel},
71
{"ok", (XtActionProc) do_ok},
72
{"exec", (XtActionProc) do_exec},
73
{"load", (XtActionProc) do_load},
74
{"linkf", (XtActionProc) do_linkf},
75
{"getf", (XtActionProc) do_getf},
76
{"getfc", (XtActionProc) do_getfc}
79
/* Global so w_dir.c can access us */
81
Widget file_panel, /* so w_dir can access the scrollbars */
82
file_popup, /* the popup itself */
83
file_selfile, /* selected file widget */
84
file_mask, /* mask widget */
85
file_dir, /* current directory widget */
86
file_flist, /* file list widget */
87
file_dlist, /* dir list widget */
88
labelW; /* popup label */
93
FirstArg(XtNstring, "\0");
94
SetValues(file_selfile); /* clear Filename string */
95
XtPopdown(file_popup);
96
XtSetSensitive(file_w, True);
100
#define STRW1 ";exec(\"%s/%s\");\n"
107
char strsend1[sizeof(STRW1)+FSIZE];
108
sprintf(strsend1,STRW1,dir,file);
109
write_scilab(strsend1);
121
FirstArg(XtNstring, &dval);
123
FirstArg(XtNstring, &fval);
124
GetValues(file_selfile);
125
/* check the ascii widget for a filename */
128
/* "Filename" widget empty, use current filename */
130
if (emptyname_msg(fval, "EXEC"))
133
if (change_directory(dval) == 0) {
134
if (exec_file(dval,fval) == 0) {
135
FirstArg(XtNlabel, fval);
136
SetValues(cfile_text); /* set the current filename */
137
if (fval != cur_filename)
138
update_cur_filename(fval); /* and update cur_filename */
139
file_panel_dismiss();
143
(void) exec_file("",cur_filename);
148
/***********************************
149
* Used with the primitive C2F(xgetfile)
150
***********************************/
152
void ok_file(dir,file)
156
write_getfile(dir,file);
161
/* Accelerators to their default values */
162
XtOverrideTranslations(file_selfile,
163
XtParseTranslationTable(file_name_translations));
164
XtOverrideTranslations(file_flist,
165
XtParseTranslationTable(file_name_translations));
166
XtSetSensitive(ok,False);
167
XtSetSensitive(exec, True);
168
XtSetSensitive(load, True);
169
XtSetSensitive(getf, True);
170
/** XtSetSensitive(getfc, True); **/
171
XtSetSensitive(linkf, True);
174
static String file_name_translations1 =
175
"<Key>Return: ok()\n";
177
void ok_prep(filemask,dirname,title,flag,err)
183
char newdir[PATH_MAX];
185
/* FirstArg(XtNtitle, title);
186
SetValues(file_popup); */
187
FirstArg(XtNlabel, title);
191
/* Change Accelerators to ok */
192
XtOverrideTranslations(file_selfile,
193
XtParseTranslationTable(file_name_translations1));
194
XtOverrideTranslations(file_flist,
195
XtParseTranslationTable(file_name_translations1));
196
FirstArg(XtNstring, filemask);
197
SetValues(file_mask);
198
/** callingRescan because of file_mask change **/
199
Rescan((Widget) 0, (XEvent*) 0, (String*) 0, (Cardinal*) 0);
200
if ( flag == 1 && ((int) strlen(dirname)) >= 1 )
202
/* We also want to change dir */
203
char longdir[PATH_MAX];
206
parseuserpath(dirname,longdir);
207
strcpy(newdir, longdir);
209
else if ( strncmp(dirname,"SCI",3) == 0)
211
parsescipath(dirname,longdir);
212
strcpy(newdir, longdir);
216
strcpy(newdir,dirname);
220
XtSetSensitive(ok,True);
221
XtSetSensitive(exec, False);
222
XtSetSensitive(load, False);
223
XtSetSensitive(getf, False);
224
/** XtSetSensitive(getfc, False); **/
225
XtSetSensitive(linkf, False);
228
/* make the full path from SCI/partialpath */
230
void parsescipath(path,longpath)
231
char *path,*longpath;
233
strcpy(longpath,getenv("SCI"));
234
if (strlen(path)==3) /* nothing after the SCI, we have the full path */
236
strcat(longpath,&path[3]); /* append the rest of the path */
248
FirstArg(XtNstring, &dval);
250
FirstArg(XtNstring, &fval);
251
GetValues(file_selfile);
252
/* check the ascii widget for a filename */
255
/* "Filename" widget empty, use current filename */
257
if (emptyname_msg(fval, "OK"))
260
if (change_directory(dval) == 0)
263
/** if (ok_file(dval,fval) == 0) { **/
264
FirstArg(XtNlabel, fval);
265
SetValues(cfile_text); /* set the current filename */
266
if (fval != cur_filename)
267
update_cur_filename(fval); /* and update cur_filename */
268
file_panel_dismiss();
272
(void) ok_file("",cur_filename);
277
#define STRW3 ";getf(\"%s/%s\",\"c\");\n"
284
char strsend1[sizeof(STRW3)+FSIZE];
285
sprintf(strsend1,STRW3,dir,file);
286
write_scilab(strsend1);
297
FirstArg(XtNstring, &fval);
298
GetValues(file_selfile); /* check the ascii widget for a filename */
299
if (emptyname(fval)) {
300
fval = cur_filename; /* "Filename" widget empty, use current filename */
301
warnexist = False; /* don't warn if this file exists */
302
/* copy the name from the file_name widget to the current filename */
305
warnexist = True; /* warn if this file exists */
308
if (emptyname_msg(fval, "Getfc"))
311
/* get the directory from the ascii widget */
312
FirstArg(XtNstring, &dval);
315
if (change_directory(dval) == 0) {
316
XtSetSensitive(getfc, False);
317
if (getfc_file(dval,fval) == 0) {
318
FirstArg(XtNlabel, fval);
319
SetValues(cfile_text);
320
if (strcmp(fval,cur_filename) != 0) {
321
update_cur_filename(fval); /* update cur_filename */
323
file_panel_dismiss();
325
XtSetSensitive(getfc, True);
328
/* not using popup filename not changed so ok to write existing file */
329
(void) getfc_file("",cur_filename);
336
#define STRL ";link(\"%s/%s\",\"%s\");\n"
344
char strsend1[sizeof(STRL)+FSIZE];
345
file1=malloc((unsigned) (strlen(file)+1) *sizeof(char));
346
if (file1 != (char*) 0)
349
file1[strlen(file)-2]='\0';
350
sprintf(strsend1,STRL,dir,file,file1);
354
{ sprintf(strsend1,STRL,dir,file,file);}
355
write_scilab(strsend1);
366
FirstArg(XtNstring, &fval);
367
GetValues(file_selfile); /* check the ascii widget for a filename */
368
if (emptyname(fval)) {
369
fval = cur_filename; /* "Filename" widget empty, use current filename */
370
warnexist = False; /* don't warn if this file exists */
371
/* copy the name from the file_name widget to the current filename */
374
warnexist = True; /* warn if this file exists */
377
if (emptyname_msg(fval, "Link"))
380
/* get the directory from the ascii widget */
381
FirstArg(XtNstring, &dval);
384
if (change_directory(dval) == 0) {
385
XtSetSensitive(linkf, False);
386
if (linkf_file(dval,fval) == 0) {
387
FirstArg(XtNlabel, fval);
388
SetValues(cfile_text);
389
if (strcmp(fval,cur_filename) != 0) {
390
update_cur_filename(fval); /* update cur_filename */
392
file_panel_dismiss();
394
XtSetSensitive(linkf, True);
397
/* not using popup filename not changed so ok to write existing file */
398
(void) linkf_file("",cur_filename);
404
#define STRW5 ";getf(\"%s/%s\");\n"
411
char strsend1[sizeof(STRW5)+FSIZE];
412
sprintf(strsend1,STRW5,dir,file);
413
write_scilab(strsend1);
424
FirstArg(XtNstring, &fval);
425
GetValues(file_selfile); /* check the ascii widget for a filename */
426
if (emptyname(fval)) {
427
fval = cur_filename; /* "Filename" widget empty, use current filename */
428
warnexist = False; /* don't warn if this file exists */
429
/* copy the name from the file_name widget to the current filename */
432
warnexist = True; /* warn if this file exists */
435
if (emptyname_msg(fval, "Getf"))
438
/* get the directory from the ascii widget */
439
FirstArg(XtNstring, &dval);
442
if (change_directory(dval) == 0) {
443
XtSetSensitive(getf, False);
444
if (getf_file(dval,fval) == 0) {
445
FirstArg(XtNlabel, fval);
446
SetValues(cfile_text);
447
if (strcmp(fval,cur_filename) != 0) {
448
update_cur_filename(fval); /* update cur_filename */
450
file_panel_dismiss();
452
XtSetSensitive(getf, True);
455
/* not using popup filename not changed so ok to write existing file */
456
(void) getf_file("",cur_filename);
462
#define STRW6 ";load(\"%s/%s\");\n"
469
char strsend1[sizeof(STRW6)+FSIZE];
470
sprintf(strsend1,STRW6,dir,file);
471
write_scilab(strsend1);
482
FirstArg(XtNstring, &fval);
483
GetValues(file_selfile); /* check the ascii widget for a filename */
484
if (emptyname(fval)) {
485
fval = cur_filename; /* "Filename" widget empty, use current filename */
486
warnexist = False; /* don't warn if this file exists */
487
/* copy the name from the file_name widget to the current filename */
490
warnexist = True; /* warn if this file exists */
493
if (emptyname_msg(fval, "Load"))
496
/* get the directory from the ascii widget */
497
FirstArg(XtNstring, &dval);
500
if (change_directory(dval) == 0) {
501
XtSetSensitive(load, False);
502
if (load_file(dval,fval) == 0) {
503
FirstArg(XtNlabel, fval);
504
SetValues(cfile_text);
505
if (strcmp(fval,cur_filename) != 0) {
506
update_cur_filename(fval); /* update cur_filename */
508
file_panel_dismiss();
510
XtSetSensitive(load, True);
513
/* not using popup filename not changed so ok to write existing file */
514
(void) load_file("",cur_filename);
521
file_panel_cancel(w, ev)
525
cancel_getfile();/* for getfile.c */
526
file_panel_dismiss();
531
void popup_file_panel(w,description)
535
extern Atom wm_delete_window;
538
set_temp_wf_cursor(wait_wf_cursor);
539
XtSetSensitive(w, False);
542
create_file_panel(w,description);
544
Rescan((Widget) 0, (XEvent*) 0, (String*) 0, (Cardinal*) 0);
545
FirstArg(XtNlabel, description);
548
XtPopup(file_popup, XtGrabNonexclusive);
549
(void) XSetWMProtocols(XtDisplay(file_popup), XtWindow(file_popup),
550
&wm_delete_window, 1);
551
if (file_msg_is_popped)
552
XtAddGrab(file_msg_popup, False, False);
556
void create_file_panel(w,description)
561
Widget file, beside, below;
562
Widget hpaned,dialogpanned,viewportW/*,labelW*/;
563
XFontStruct *temp_font;
564
static int actions_added=0;
566
XtTranslateCoords(w, (Position) 0, (Position) 0, &xposn, &yposn);
568
FirstArg(XtNx, xposn);
569
NextArg(XtNy, yposn + 50);
570
NextArg(XtNtitle, " File menu");
571
file_popup = XtCreatePopupShell("xsci_file_menu",
572
transientShellWidgetClass,
573
w_toplevel, Args, ArgCount);
574
XtOverrideTranslations(file_popup,
575
XtParseTranslationTable(file_translations));
577
hpaned = XtCreateManagedWidget("hpaned",panedWidgetClass,file_popup,
578
(Arg *) NULL,(Cardinal)ZERO);
580
dialogpanned = XtCreateManagedWidget("paned",panedWidgetClass,hpaned,
581
(Arg *) NULL,(Cardinal)ZERO);
583
viewportW = XtCreateManagedWidget("labelviewport",viewportWidgetClass,
584
dialogpanned,(Arg *) NULL,(Cardinal)ZERO);
585
FirstArg(XtNlabel, description);
586
labelW=XtCreateManagedWidget("label",labelWidgetClass,viewportW,Args, ArgCount);
589
file_panel = XtCreateManagedWidget("file_panel", formWidgetClass,
590
dialogpanned, (Arg *) NULL, (Cardinal) 0);
592
FirstArg(XtNlabel, " Current Filename:");
593
NextArg(XtNvertDistance, 15);
594
NextArg(XtNjustify, XtJustifyLeft);
595
NextArg(XtNborderWidth, 0);
596
cfile_lab = XtCreateManagedWidget("cur_file_label", labelWidgetClass,
597
file_panel, Args, ArgCount);
599
FirstArg(XtNlabel, cur_filename);
600
NextArg(XtNfromHoriz, cfile_lab);
601
NextArg(XtNvertDistance, 15);
602
NextArg(XtNjustify, XtJustifyLeft);
603
NextArg(XtNborderWidth, 0);
604
NextArg(XtNwidth, 250);
605
cfile_text = XtCreateManagedWidget("cur_file_name", labelWidgetClass,
606
file_panel, Args, ArgCount);
608
FirstArg(XtNlabel, " Filename:");
609
NextArg(XtNvertDistance, 15);
610
NextArg(XtNfromVert, cfile_lab);
611
NextArg(XtNborderWidth, 0);
612
file = XtCreateManagedWidget("file_label", labelWidgetClass,
613
file_panel, Args, ArgCount);
614
FirstArg(XtNfont, &temp_font);
617
FirstArg(XtNwidth, 350);
618
NextArg(XtNheight, ch=char_height(temp_font) * 2 + 4);
619
NextArg(XtNeditType, "edit");
620
NextArg(XtNstring, cur_filename);
621
NextArg(XtNinsertPosition, strlen(cur_filename));
622
NextArg(XtNfromHoriz, file);
623
NextArg(XtNborderWidth, INTERNAL_BW);
624
NextArg(XtNvertDistance, 15);
625
NextArg(XtNfromVert, cfile_lab);
626
NextArg(XtNscrollHorizontal, XawtextScrollWhenNeeded);
627
file_selfile = XtCreateManagedWidget("file_name", asciiTextWidgetClass,
628
file_panel, Args, ArgCount);
629
XtOverrideTranslations(file_selfile,
630
XtParseTranslationTable(text_translations));
632
if (!actions_added) {
633
XtAppAddActions(app_con, file_actions, XtNumber(file_actions));
635
/* add action to exec file */
636
XtAppAddActions(app_con, file_name_actions, XtNumber(file_name_actions));
639
/* make <return> in the filename window exec the file */
640
XtOverrideTranslations(file_selfile,
641
XtParseTranslationTable(file_name_translations));
643
create_dirinfo(file_panel, file_selfile, &beside, &below,
644
&file_mask, &file_dir, &file_flist, &file_dlist);
645
/* make <return> in the file list window exec the file */
646
XtOverrideTranslations(file_flist,
647
XtParseTranslationTable(file_name_translations));
648
FirstArg(XtNlabel, "Cancel");
649
NextArg(XtNvertDistance, 15);
650
NextArg(XtNhorizDistance, 25);
651
NextArg(XtNheight, 25);
652
NextArg(XtNfromHoriz, beside);
653
NextArg(XtNfromVert, below);
654
NextArg(XtNborderWidth, INTERNAL_BW);
655
cancel = XtCreateManagedWidget("cancel", commandWidgetClass,
656
file_panel, Args, ArgCount);
657
XtAddEventHandler(cancel, ButtonReleaseMask, (Boolean) 0,
658
(XtEventHandler)file_panel_cancel, (XtPointer) NULL);
659
FOpAddInfoHandler(cancel,"Cancel file operation");
661
FirstArg(XtNlabel, "Ok");
662
NextArg(XtNsensitive, False);
663
NextArg(XtNfromHoriz, cancel);
664
NextArg(XtNfromVert, below);
665
NextArg(XtNvertDistance, 15);
666
NextArg(XtNhorizDistance, 25);
667
NextArg(XtNheight, 25);
668
NextArg(XtNborderWidth, INTERNAL_BW);
669
ok = XtCreateManagedWidget("Ok", commandWidgetClass,
670
file_panel, Args, ArgCount);
671
XtAddEventHandler(ok, ButtonReleaseMask, (Boolean) 0,
672
(XtEventHandler)do_ok, (XtPointer) NULL);
673
FOpAddInfoHandler(ok,"send file name to Scilab");
675
FirstArg(XtNlabel, "Load");
676
NextArg(XtNfromHoriz, ok);
677
NextArg(XtNfromVert, below);
678
NextArg(XtNvertDistance, 15);
679
NextArg(XtNhorizDistance, 25);
680
NextArg(XtNheight, 25);
681
NextArg(XtNborderWidth, INTERNAL_BW);
682
load = XtCreateManagedWidget("load", commandWidgetClass,
683
file_panel, Args, ArgCount);
684
XtAddEventHandler(load, ButtonReleaseMask, (Boolean) 0,
685
(XtEventHandler)do_load, (XtPointer) NULL);
686
FOpAddInfoHandler(load,"Load a scilab file (created by save)");
688
FirstArg(XtNlabel, "Getf");
689
NextArg(XtNfromHoriz, load);
690
NextArg(XtNfromVert, below);
691
NextArg(XtNvertDistance, 15);
692
NextArg(XtNhorizDistance, 25);
693
NextArg(XtNheight, 25);
694
NextArg(XtNborderWidth, INTERNAL_BW);
695
getf = XtCreateManagedWidget("getf", commandWidgetClass,
696
file_panel, Args, ArgCount);
697
XtAddEventHandler(getf, ButtonReleaseMask, (Boolean) 0,
698
(XtEventHandler)do_getf, (XtPointer) NULL);
699
FOpAddInfoHandler(getf,"Load scilab functions");
702
FirstArg(XtNlabel, "Getfc");
703
NextArg(XtNfromHoriz, getf);
704
NextArg(XtNfromVert, below);
705
NextArg(XtNvertDistance, 15);
706
NextArg(XtNhorizDistance, 25);
707
NextArg(XtNheight, 25);
708
NextArg(XtNborderWidth, INTERNAL_BW);
709
getfc = XtCreateManagedWidget("getfc", commandWidgetClass,
710
file_panel, Args, ArgCount);
711
XtAddEventHandler(getfc, ButtonReleaseMask, (Boolean) 0,
712
(XtEventHandler)do_getfc, (XtPointer) NULL);
713
FOpAddInfoHandler(getfc,"Load and compile scilab functions");
715
FirstArg(XtNlabel, "Link");
716
NextArg(XtNfromHoriz, getf);
717
NextArg(XtNfromVert, below);
718
NextArg(XtNvertDistance, 15);
719
NextArg(XtNhorizDistance, 25);
720
NextArg(XtNheight, 25);
721
NextArg(XtNborderWidth, INTERNAL_BW);
722
linkf = XtCreateManagedWidget("link", commandWidgetClass,
723
file_panel, Args, ArgCount);
724
XtAddEventHandler(linkf, ButtonReleaseMask, (Boolean) 0,
725
(XtEventHandler)do_linkf, (XtPointer) NULL);
726
FOpAddInfoHandler(linkf,"Dynamic link of object file");
727
FirstArg(XtNlabel, "Exec");
728
NextArg(XtNborderWidth, INTERNAL_BW);
729
NextArg(XtNfromHoriz, linkf);
730
NextArg(XtNfromVert, below);
731
NextArg(XtNvertDistance, 15);
732
NextArg(XtNhorizDistance, 25);
733
NextArg(XtNheight, 25);
734
exec = XtCreateManagedWidget("exec", commandWidgetClass,
735
file_panel, Args, ArgCount);
736
XtAddEventHandler(exec, ButtonReleaseMask, (Boolean) 0,
737
(XtEventHandler)do_exec, (XtPointer) NULL);
738
FOpAddInfoHandler(exec,"Execute the content of file (scilab code)");
739
init_msg(file_panel,exec,ch," ");
740
XtInstallAccelerators(file_panel, cancel);
741
XtInstallAccelerators(file_panel, exec);