1
/*------------------------------------------------------------------------
2
* Copyright (C) 2001-2003 Enpc/Jean-Philippe Chancelier
4
* main menu and graphic window menus
5
*--------------------------------------------------------------*/
15
#include "../graphics/Math.h"
16
#include "../graphics/bcg.h"
17
#include "../graphics/Graphics.h"
18
#include "../sun/Sun.h"
19
#include "../sun/men_Sutils.h"
20
/* #include "../menusX/men_scilab.h"*/
21
#include "All-extern.h"
24
#define PI0 (integer *) 0
25
#define PD0 (double *) 0
27
void menu_entry_show(menu_entry *m); /* only used for debug */
28
extern void create_scilab_about(void);
29
extern int prtdlg __PARAMS((integer *flag, char *printer, integer *colored, integer *orientation, char *file, integer *ok));
30
extern int sci_get_file_window __PARAMS((char *, char **, char *, int,int, int *,char *));
32
extern char GetDriver();
33
static void *sci_window_initial_menu() ;
34
static void sci_menu_to_item_factory(GtkItemFactory *ifactory,menu_entry *m);
35
static void sci_menu_delete(menu_entry **m, char *name) ;
36
static int sci_menu_add(menu_entry **m,int winid,char *name,char** entries,int ne,
37
int action_type,char *fname);
38
static menu_entry * sci_menu_set_status(menu_entry *m,int winid,char *name,
39
int subid,int status);
40
static int call_predefined_callbacks(char *name, int winid);
42
static void sci_factory_add_menu_entry(GtkItemFactory *ifactory,menu_entry *m);
43
static void sci_factory_add_last_menu_entry(GtkItemFactory *ifactory,menu_entry *m);
44
/*--------------------------------------------------------------
45
* main menu. i.e the menu of the main scilab window
46
* this menu is attached to a zterm through a plug widget
47
*--------------------------------------------------------------*/
49
static menu_entry *main_menu_entries = NULL;
50
static GtkItemFactory *main_item_factory= NULL;
53
* used when the menu is plugged
56
void create_plugged_main_menu()
58
static GtkWidget *menubar = NULL;
60
static GtkWidget *Plug;
61
static GtkItemFactory *item_factory;
62
GtkAccelGroup *accel_group = NULL ;
63
char * plug_info = getenv("SCIWIN");
65
if ( plug_info == NULL) return ;
67
main_item_factory= item_factory = gtk_item_factory_new (GTK_TYPE_MENU_BAR, "<main>",
71
Plug = gtk_plug_new(atoi(getenv("SCIWIN")));
72
main_menu_entries = sci_window_initial_menu();
73
if ( main_menu_entries == NULL) return;
77
/* This function generates the menu items from scilab description */
78
/* Attention il faut aussi gerer les menu en set unest XXXXX */
80
sci_menu_to_item_factory(item_factory, main_menu_entries);
82
/* Attach the new accelerator group to the window. */
83
/* gtk_window_add_accel_group (GTK_WINDOW (window), accel_group); */
85
/* Finally, return the actual menu bar created by the item factory. */
87
if ( menubar != NULL) gtk_widget_destroy(menubar);
88
menubar = gtk_item_factory_get_widget (item_factory, "<main>");
89
gtk_container_add(GTK_CONTAINER(Plug),menubar);
90
if ( accel_group != NULL )
91
gtk_window_add_accel_group (GTK_WINDOW (Plug), accel_group);
92
gtk_widget_show_all(Plug);
99
* used when zterm is plugged
102
GtkWidget *create_main_menu( GtkWidget *window)
104
static int first = 0;
105
static GtkWidget *menubar = NULL;
106
static GtkItemFactory *item_factory;
107
GtkAccelGroup *accel_group = NULL ;
109
/* Make an accelerator group (shortcut keys) */
110
if ( window != NULL) accel_group = gtk_accel_group_new ();
112
main_item_factory= item_factory = gtk_item_factory_new (GTK_TYPE_MENU_BAR, "<main>",
115
main_menu_entries = sci_window_initial_menu();
116
if ( main_menu_entries == NULL) return NULL;
120
/* This function generates the menu items from scilab description */
121
/* Attention il faut aussi gerer les menu en set unset XXXXX */
123
sci_menu_to_item_factory(item_factory, main_menu_entries);
125
/* Finally, return the actual menu bar created by the item factory. */
126
if ( menubar != NULL) gtk_widget_destroy(menubar);
127
menubar = gtk_item_factory_get_widget (item_factory, "<main>");
128
if ( window != NULL ) gtk_window_add_accel_group (GTK_WINDOW (window), accel_group);
135
/*--------------------------------------------------------------
136
* Graphic window menu in main menu
137
*--------------------------------------------------------------*/
139
static integer lab_count = 0;
140
static char gwin_name[100];
143
void MenuFixCurrentWin(int ivalue)
146
char *graphic_entries[] = { "Create or Select||$gwselect",
151
if ( ivalue == lab_count ) return ;
152
if ( main_item_factory == NULL ) return;
153
sprintf( gwin_name, "Graphic Window %d", (int) lab_count );
154
C2F(delbtn)(&w, gwin_name);
155
sprintf( gwin_name, "Graphic Window %d", (int) ivalue );
157
sci_menu_add(&main_menu_entries,-1,gwin_name,
158
graphic_entries,5,0,"$graphic_window");
159
sci_factory_add_last_menu_entry(main_item_factory,main_menu_entries);
163
/*--------------------------------------------------------------
164
* Graphic window menu
165
*--------------------------------------------------------------*/
167
void create_graphic_window_menu(struct BCG *dd)
169
GtkAccelGroup *accel_group= gtk_accel_group_new ();
171
/* Attach the new accelerator group to the window. */
172
gtk_window_add_accel_group (GTK_WINDOW (dd->window), accel_group);
174
dd->item_factory = gtk_item_factory_new (GTK_TYPE_MENU_BAR, "<main>",
177
/* This function generates the menu items from scilab description */
178
/* Attention il faut aussi gerer les menu en set unest XXXXX */
180
sci_menu_to_item_factory(dd->item_factory,dd->menu_entries);
182
/* Finally, return the actual menu bar created by the item factory. */
184
dd->menubar = gtk_item_factory_get_widget (dd->item_factory, "<main>");
185
gtk_box_pack_start (GTK_BOX (dd->vbox),dd->menubar, FALSE, TRUE, 0);
186
gtk_widget_show (dd->menubar);
190
/**********************************************************
191
* General routines for dynamic menu item creation and deletion
192
***********************************************************/
194
/*---------------------------------------------------
195
* Delete the button named button_name in the menu of window
197
*---------------------------------------------------*/
199
int C2F(delbtn)(int *win_num,char *button_name)
201
GtkItemFactory *item_factory;
203
char *p,*but= button_name;
206
while ( *but != '\0' ) {
207
if ( *but == '/') break ;
208
else if ( *but == '_') but++ ;
209
else { *(p++)= *(but++);}
212
if ( *win_num == -1 )
214
item_factory = main_item_factory;
215
sci_menu_delete(&main_menu_entries,button_name);
219
BCG *dd = GetWindowXgcNumber(*win_num);
220
if ( dd == NULL || dd->item_factory == NULL) return 0;
221
item_factory = dd->item_factory;
222
sci_menu_delete(&dd->menu_entries,button_name);
224
gtk_item_factory_delete_item (item_factory,btn);
228
/*----------------------------------------------------------------
229
* Add dynamically buttons and menus in The Scilab Graphic Window
230
* or in the Scilab main window
231
* Scilab interface for the AddMenu function
232
* Add a menu in window number win_num or in Main window
234
* win_num : graphic window number or -1 for main scilab window
235
* button_name : label of button
236
* entries : labels of submenus if any (in scilab code)
237
* ptrentries : table of pointers on each entries
238
* ne : number of submenus
240
* typ==0 : interpreted (execution of scilab instruction
241
* typ!=0 : hard coded a routine is called
242
* fname; : name of the action function
243
*----------------------------------------------------------------*/
245
int C2F(addmen)(win_num,button_name,entries,ptrentries,ne,typ,fname,ierr)
246
integer *win_num,*entries,*ptrentries,*ne,*ierr,*typ;
247
char *button_name,*fname;
249
char ** menu_entries;
252
ScilabMStr2CM(entries,ne,ptrentries,&menu_entries,ierr);
253
if ( *ierr == 1) return(0);
255
AddMenu(win_num,button_name,menu_entries,ne,typ,fname,ierr);
260
/*---------------------------------------------------
261
* Add a menu in window number wun_num or in Main window
262
* win_num : graphic window number or -1 for main scilab window
263
* button_name : label of button
264
* entries : labels of submenus if any
265
* ne : number of submenus
267
* typ==0 : interpreted (execution of scilab instruction
268
* typ!=0 : hard coded a routine is called
269
* fname; : name of the action function
270
*---------------------------------------------------*/
272
void AddMenu(win_num, button_name, entries, ne, typ, fname, ierr)
281
if ( *win_num == -1 )
283
/* Scilab main menu */
284
if ( main_item_factory == NULL ) return;
285
if ( sci_menu_add(&main_menu_entries,*win_num,button_name,entries,*ne,
291
sci_factory_add_last_menu_entry(main_item_factory,main_menu_entries);
295
BCG *dd = GetWindowXgcNumber(*win_num);
296
if ( dd == NULL || dd->item_factory == NULL ) return;
297
if ( sci_menu_add(&dd->menu_entries,*win_num,button_name,entries,
298
*ne,*typ,fname) == 1 )
303
sci_factory_add_last_menu_entry(dd->item_factory,dd->menu_entries);
307
/*--------------------------------------------------
308
* Activate or deactivate a menu
309
*---------------------------------------------------*/
311
void SetUnsetMenu(win_num, button_name, ne,flag)
317
menu_entry *e,*entries;
318
GtkItemFactory *item_factory;
319
if ( *win_num == -1 )
321
item_factory = main_item_factory;
322
entries =main_menu_entries;
326
BCG *dd = GetWindowXgcNumber(*win_num);
327
if ( dd == NULL || dd->item_factory == NULL) return ;
328
item_factory = dd->item_factory;
329
entries = dd->menu_entries;
332
e = sci_menu_set_status(entries,*win_num,button_name,*ne,flag);
340
char *loc = e->name, *pbuf;
341
strcpy(buf,"<main>/");
342
pbuf = buf + strlen(buf);
343
while ( *loc != '\0' )
345
if ( *loc != '_' ) { *pbuf = *loc ; pbuf++; loc++;}
353
char *loc = e->menu->name, *pbuf;
354
strcpy(buf,"<main>/");
355
pbuf = buf + strlen(buf);
356
while ( *loc != '\0' )
358
if ( *loc != '_' ) { *pbuf = *loc ; pbuf++; loc++;}
363
while ( *loc != '\0' )
365
if ( *loc != '_' ) { *pbuf = *loc ; pbuf++; loc++;}
370
w = gtk_item_factory_get_widget (item_factory,buf);
371
/* rend le menu non sensitif */
375
gtk_widget_set_sensitive (w, TRUE);
377
gtk_widget_set_sensitive (w, FALSE);
382
/** activate a menu (scilab interface) **/
384
int C2F(setmen)(win_num,button_name,entries,ptrentries,ne,ierr)
385
integer *win_num,*entries,*ptrentries,*ne,*ierr;
388
SetUnsetMenu(win_num,button_name,ne,TRUE);
392
int C2F(unsmen)(win_num,button_name,entries,ptrentries,ne,ierr)
393
integer *win_num,*entries,*ptrentries,*ne,*ierr;
396
SetUnsetMenu(win_num,button_name,ne,FALSE);
400
/*--------------------------------------------------------
401
* A Set of functions to make addmenu/delmenu/set-unsetmenu
402
* work with itemfactory menus of gtk
403
* It seams that toplevel menu buttons cannot
404
* be deleted in itemfactory.
405
* thus we recreate a new menubar when menus are deleted
406
*--------------------------------------------------------*/
408
static void submenu_entry_set_menu(menu_entry *subs,menu_entry *father);
410
/* checks that name and name1 are the same taking care of _ */
412
static int is_menu_name(char *name,char *name1)
419
if ( *name1 == '_' ) name1++;
421
else if ( *name != *name1 ) {
428
if ( *name1 != 0) return 1;
432
void menu_entry_show(menu_entry *m)
434
if ( m== NULL) return ;
435
fprintf(stdout,"name = %s ",m->name);
436
fprintf(stdout,"status %d nsub=%d win=%d action=%d fname=%s\n",
437
m->status,m->nsub,m->winid,m->action_type,m->fname);
438
if ( m->accel != NULL)
439
fprintf(stdout,"accel %s \n",m->accel);
440
if ( m->subs != NULL)
442
fprintf(stdout,"{\n");
443
menu_entry_show(m->subs);
444
fprintf(stdout,"}\n");
446
menu_entry_show(m->next);
449
menu_entry *new_menu_entry(char *name,char *accel,int status,int nsub,
450
menu_entry *subs,int winid,
451
int action_type,char *fname)
454
if ((loc = MALLOC(sizeof(menu_entry)))== NULL)
456
if ((loc->name = MALLOC((strlen(name)+1)*sizeof(char)))==NULL)
458
strcpy(loc->name,name);
462
if ((loc->accel = MALLOC((strlen(accel)+1)*sizeof(accel)))==NULL)
464
strcpy(loc->accel,accel);
466
else loc->accel = NULL;
470
if ((loc->fname = MALLOC((strlen(fname)+1)*sizeof(fname)))==NULL)
472
strcpy(loc->fname,fname);
474
else loc->fname= NULL;
476
loc->status = status;
480
loc->action_type = action_type;
483
submenu_entry_set_menu(loc->subs,loc);
487
static void submenu_entry_set_menu(menu_entry *subs,menu_entry *father)
489
if ( subs == NULL) return ;
490
subs->menu = father ;
491
submenu_entry_set_menu(subs->next,father);
494
void menu_entry_delete(menu_entry *me)
496
if ( me == NULL) return ;
501
menu_entry_delete(me->subs);
502
menu_entry_delete(me->next);
506
void submenu_add(menu_entry *me,menu_entry *more)
508
menu_entry *loc = me->subs;
509
if (loc == NULL) me->subs = more;
510
while ( loc->next != NULL) loc = loc->next ;
515
/****************************************************
516
* Add a menu in a menu_item list
517
* win_num : graphic window number or -1 for main scilab window
518
* name : label of menu button
519
* if entries is empty then name can be
520
* "name|accelerator|specific_action"
521
* entries : labels of submenus if any. each entry is a string
522
* "entry_name" or "entry_name|accelerator|specific_action"
524
* ne : number of submenus
525
* action_type : Action mode
526
* action_type==0 : interpreted (execution of scilab instruction
527
* action_type!=0 : hard coded a routine is called
528
* fname; : name of the action function
529
****************************************************/
532
static menu_entry *gtksci_new_menu_entry(char *entry_name,int winid,int pos,int action_type,char *fname)
535
char *entry=NULL,*accel=NULL,*action=NULL;
536
entry=strdup(entry_name);
537
accel = strchr(entry,'|');
540
*accel = '\0'; accel +=1;
541
action = strchr(accel,'|');
542
if ( action != NULL )
544
*action = '\0'; action+=1;
547
if (action == NULL) action = fname ;
548
menu = new_menu_entry(entry,accel,1,pos+1,NULL,winid,action_type,action);
551
/* XXXXX clean and return */
552
if(entry != NULL) free(entry);
560
static int sci_menu_add(menu_entry **m,int winid,char *name,char** entries,int ne,
561
int action_type,char *fname)
565
/* here we must find the menu_entry associated to win_num */
566
menu_entry *me1=NULL,*me2,*top,*subs=NULL;
567
/* first build the sub_menus */
568
for (i=0 ; i < ne ;i++)
570
me2 = gtksci_new_menu_entry(entries[i],winid,i,action_type,fname);
575
if ( i != 0) me1->next = me2;
581
top = gtksci_new_menu_entry(name,winid,0,action_type,fname);
585
/* now the menu entry */
586
top = new_menu_entry(name,NULL,1,1,subs,winid,action_type,fname);
590
/* XXXXX clean and return */
591
if(entry != NULL) free(entry);
594
if ( *m == NULL) *m = top ;
597
menu_entry *loc= *m ;
598
while (loc->next != NULL) loc=loc->next;
601
if(entry != NULL) free(entry);
605
/****************************************************
606
*Delete the menu name in menu_entry list
607
****************************************************/
609
static void sci_menu_delete(menu_entry **m, char *name)
611
menu_entry *loc,*nloc;
612
if ( *m == NULL ) return ;
613
/* we want to delete a toplevel menu */
615
if ( is_menu_name((*m)->name,name) ==0)
617
/* we delete the first entry of m */
620
menu_entry_delete(loc);
624
while ( nloc != NULL)
626
if ( is_menu_name(nloc->name,name)==0)
628
loc->next = nloc->next ;
630
menu_entry_delete(nloc);
638
/****************************************************
639
* Set the status of a menu
640
****************************************************/
643
static menu_entry * sci_menu_set_status(menu_entry *m,int winid,char *name,
644
int subid,int status)
646
menu_entry *loc = m ;
649
if ( is_menu_name(loc->name,name)==0)
653
loc->status = status ;
659
/* walk to find submenu number subid */
661
for ( count = 0 ; count < subid -1 ; count++)
662
loc = (loc == NULL) ? NULL : loc->next ;
663
if ( loc == NULL) return NULL ;
664
loc->status = status;
673
/*------------------------------------------------------
675
*------------------------------------------------------*/
677
static void sci_menu_default_callback (gpointer callback_data,
678
guint callback_action,
681
static char buf[256];
682
menu_entry *m = (menu_entry *) callback_data;
684
fprintf(stdout,"menu activated \"%s\"",
685
gtk_item_factory_path_from_widget (widget));
687
if ( m== NULL) return ;
689
fprintf(stdout,"name = %s ",m->name);
690
fprintf(stdout,"status %d nsub=%d win=%d action=%d fname=%s\n",
691
m->status,m->nsub,m->winid,m->action_type,m->fname);
694
if ( call_predefined_callbacks(m->fname, m->winid)==1) return ;
696
if (m->action_type == 0)
698
/* Interpreted mode : we store the action on a queue */
700
sprintf(buf,"execstr(%s(%d))",m->fname,m->nsub);
702
sprintf(buf,"execstr(%s_%d(%d))",m->fname,m->winid,m->nsub);
705
else if (m->action_type == 2)
707
/* Interpreted mode : we store the action on a queue */
709
sprintf(buf,"%s(%d)",m->fname,m->nsub);
711
sprintf(buf,"%s(%d,%d)",m->fname,m->nsub,m->winid);
716
/* hard coded mode */
718
C2F(setfbutn)(m->fname,&rep);
720
F2C(fbutn)((m->fname),&(m->winid),&(m->nsub));
725
/*------------------------------------------------------
726
* fill an item factory with a menu_entry description
727
*------------------------------------------------------*/
729
static void sci_menu_to_item_factory(GtkItemFactory *ifactory,menu_entry *m)
733
sci_factory_add_menu_entry(ifactory,m);
738
/*-------------------------------------------------------------------
739
* build items associated to the last menu_entry contained in m
740
* and add them in the factory ifactory
741
*-------------------------------------------------------------------*/
743
static void sci_factory_add_last_menu_entry(GtkItemFactory *ifactory,menu_entry *m)
745
if ( m == NULL ) return ;
746
while ( m->next != NULL) m = m->next ;
747
sci_factory_add_menu_entry(ifactory,m);
751
/*-------------------------------------------------------------------
752
* build items associated to the first menu_entry contained in m
753
* and add them in the factory ifactory
754
*-------------------------------------------------------------------*/
756
static void sci_factory_add_menu_entry(GtkItemFactory *ifactory,menu_entry *m)
759
static GtkItemFactoryEntry entry = { NULL,NULL, sci_menu_default_callback,0,NULL};
760
if ( m == NULL ) return ;
761
sprintf(buf_path,"/%s",m->name);
762
entry.path = buf_path;
763
entry.accelerator = m->accel;
764
if ( m->subs == NULL)
766
entry.item_type = "<Item>";
767
gtk_item_factory_create_item(ifactory,&entry,(void *)m,1);
772
if ( is_menu_name(m->name,"Help")==0)
773
entry.item_type = "<LastBranch>";
775
entry.item_type = "<Branch>";
776
entry.callback = NULL;
777
gtk_item_factory_create_item(ifactory,&entry,(void *)m,1);
779
entry.item_type = "<Item>";
782
sprintf(buf_path,"/%s/%s",m->name,loc->name);
783
entry.path = buf_path;
784
entry.accelerator = loc->accel;
785
entry.callback = sci_menu_default_callback;
786
gtk_item_factory_create_item(ifactory,&entry,(void*)loc,1);
795
void * graphic_initial_menu(int winid) {
796
menu_entry *m = NULL;
797
char *file_entries[] = { "_Clear||$clear",
799
"_Print|<control>P|$print",
800
"_Export|<control>E|$export",
801
"S_ave|<control>S|$save",
802
"L_oad|<control>L|$load",
804
sci_menu_add(&m,winid,"_File",file_entries,7,0,"$file");
805
sci_menu_add(&m,winid,"_Zoom",NULL,0,0,"$zoom");
806
sci_menu_add(&m,winid,"_UnZoom",NULL,0,0,"$unzoom");
807
sci_menu_add(&m,winid,"3D _Rot.",NULL,0,0,"$rot3d");
811
static void * sci_window_initial_menu()
813
menu_entry *m = NULL;
815
char *file_entries[] = { "File _Operations||$fileops",
817
"_Quit|<control>Q|$quit" } ;
818
char *control_entries[] = { "Resume||$resume",
822
char *graphic_entries[] = { "Create or Select||$gwselect",
828
char *help_entries[] = { "Scilab Help||$help",
830
sci_menu_add(&m,winid,"_File",file_entries,3,0,"$file");
831
sci_menu_add(&m,winid,"_Control",control_entries,4,0,"$zoom");
832
sci_menu_add(&m,winid,"_Demos",NULL,0,0,"$demos");
833
sci_menu_add(&m,winid,"Graphic Window 0",graphic_entries,5,0,"$graphic_window");
834
sci_menu_add(&m,winid,"Help",help_entries,2,0,"$help");
838
/**************************************************************
839
* predefined actions for menus
840
**************************************************************/
842
/*-----------------------------------------------------------------
843
* To clear the graphic window and clear the recorded graphics
844
* w and client_data are unused
845
*-----------------------------------------------------------------*/
847
static void scig_menu_erase(int winid)
852
/*----------------------------------------------
853
* To select the graphic window
854
-----------------------------------------------*/
856
static void scig_menu_select(int winid)
861
/*----------------------------------------------
862
* To delete the graphic window
863
-----------------------------------------------*/
865
/* add handlers for delete action */
867
void scig_deletegwin_handler_none (win)int win; {};
869
void scig_deletegwin_handler_sci (int win)
872
static char buf[256];
875
SciGc = GetWindowXgcNumber(win);
876
if (strlen(SciGc->EventHandler)!=0) {
877
sprintf(buf,"%s(%d,0,0,-1000)",SciGc->EventHandler,win);
881
static Scig_deletegwin_handler scig_deletegwin_handler = scig_deletegwin_handler_sci;
882
/*static Scig_deletegwin_handler scig_deletegwin_handler = scig_deletegwin_handler_none;*/
884
Scig_deletegwin_handler set_scig_deletegwin_handler(f)
885
Scig_deletegwin_handler f;
887
Scig_deletegwin_handler old = scig_deletegwin_handler;
888
scig_deletegwin_handler = f;
892
void reset_scig_deletegwin_handler()
894
scig_deletegwin_handler = scig_deletegwin_handler_sci;
899
extern void delete_sgwin_entities(int winid,int v_flag);
902
static void scig_menu_delete(int winid)
906
if (version_flag() == 0) {DeleteObjs(winid); v_flag = 0;}
907
scig_deletegwin_handler(winid);
909
delete_sgwin_entities(winid,v_flag);
912
/* for Fortran call */
914
int C2F(deletewin)(int *winid)
916
scig_menu_delete(*winid);
920
/*-----------------------------------------------------------------*
921
* Replot in Postscript style and send to printer
922
*-----------------------------------------------------------------*/
924
static char bufname[256];
925
static char printer[128];
926
static char file[256];
928
static void scig_menu_print(int winid)
931
integer colored,orientation,flag=1,ok;
932
prtdlg(&flag,printer,&colored,&orientation,file,&ok);
935
if ( ( p1 = getenv("TMPDIR")) == (char *) 0 )
937
sciprint("Cannot find environment variable TMPDIR\r\n");
940
sprintf(bufname,"%s/scilab-%d",p1,(int)winid);
941
scig_tops(winid,colored,bufname,"Pos");
942
sprintf(bufname,"$SCI/bin/scilab -%s %s/scilab-%d %s",
943
(orientation == 1) ? "print_l" : "print_p",
944
p1,(int)winid,printer);
949
/* for use inside menus */
951
void scig_print(int winid)
953
scig_menu_print( winid);
956
/*-----------------------------------------------------------------
957
* Replot in Postscript or Xfig style and save
958
*-----------------------------------------------------------------*/
960
static void scig_menu_saveps(int winid)
962
integer colored,orientation,flag=2,ok;
963
prtdlg(&flag,printer,&colored,&orientation,file,&ok);
966
if (strncmp(printer,"Postscript",10)==0 )
969
scig_tops(winid,colored,file,"Pos");
971
else if (strcmp(printer,"Xfig")==0)
974
scig_tops(winid,colored,file,"Fig");
976
else if (strcmp(printer,"Gif")==0)
979
scig_tops(winid,colored,file,"GIF");
981
else if (strcmp(printer,"PPM")==0)
984
scig_tops(winid,colored,file,"PPM");
986
if ( strcmp(printer,"Postscript No Preamble") != 0)
988
sprintf(bufname,"$SCI/bin/scilab -%s %s %s",
989
( orientation == 1) ? "save_l" : "save_p",file,printer);
995
/* for use inside menus */
997
void scig_export(int winid)
999
scig_menu_saveps(winid) ;
1002
/*-----------------------------------------------------------------*
1004
*-----------------------------------------------------------------*/
1006
static void scig_menu_save(int winid)
1010
static char *init ="*.scg";
1011
rep=sci_get_file_window(init,&filename,".",0,0,&ierr,"Save Graphic File");
1012
if ( ierr == 0 && rep == TRUE )
1014
C2F(xsaveplots)(&winid,filename,0L);
1018
/*-----------------------------------------------------------------*
1020
*-----------------------------------------------------------------*/
1022
static void scig_menu_load(int winid)
1026
static char *init ="*.scg";
1027
rep=sci_get_file_window(init,&filename,".",0,0,&ierr,"Load Graphic File");
1028
if ( ierr == 0 && rep == TRUE )
1030
scig_loadsg(winid, filename);
1034
/*-----------------------------------------------------------------*
1036
*-----------------------------------------------------------------*/
1038
static void sci_menu_fileops()
1040
static char * file = NULL ;
1042
rep = sci_get_file_window(NULL,&file,".",0,1,&ierr,"File operations");
1043
if ( ierr == 0 && rep == TRUE )
1045
StoreCommand1(file,1); /* we want the command to appear in the window */
1051
/*-----------------------------------------------------------------**
1053
*-----------------------------------------------------------------*/
1055
static void scig_menu_zoom(int winid)
1058
SetUnsetMenu(&winid,"Zoom",&ne,False);
1059
SetUnsetMenu(&winid,"3D Rot.",&ne,False);
1060
SetUnsetMenu(&winid,"UnZoom",&ne,False);
1061
SetUnsetMenu(&winid,"File",&ne,False);
1062
if ( scig_2dzoom(winid)==1) return; /* the window has been closed */
1063
SetUnsetMenu(&winid,"Zoom",&ne,True);
1064
SetUnsetMenu(&winid,"3D Rot.",&ne,True);
1065
SetUnsetMenu(&winid,"UnZoom",&ne,True);
1066
SetUnsetMenu(&winid,"File",&ne,True);
1070
/*-----------------------------------------------------------------
1072
*-----------------------------------------------------------------*/
1074
static void scig_menu_unzoom(int winid)
1077
SetUnsetMenu(&winid,"UnZoom",&ne,False);
1079
SetUnsetMenu(&winid,"UnZoom",&ne,True);
1083
/*-----------------------------------------------------------------
1084
* 3D Rotation callback
1085
*-----------------------------------------------------------------*/
1087
static void scig_menu_rot3d(int winid)
1090
SetUnsetMenu(&winid,"3D Rot.",&ne,False);
1091
SetUnsetMenu(&winid,"UnZoom",&ne,False);
1092
SetUnsetMenu(&winid,"Zoom",&ne,False);
1093
SetUnsetMenu(&winid,"File",&ne,False);
1094
if (scig_3drot(winid)==1) return; /* the window has been closed */
1095
SetUnsetMenu(&winid,"3D Rot.",&ne,True);
1096
SetUnsetMenu(&winid,"UnZoom",&ne,True);
1097
SetUnsetMenu(&winid,"Zoom",&ne,True);
1098
SetUnsetMenu(&winid,"File",&ne,True);
1102
/*-----------------------------------------------------------------
1104
*-----------------------------------------------------------------*/
1106
static void sci_menu_kill()
1108
sci_clear_and_exit(1);
1111
/*-----------------------------------------------------------------
1113
*-----------------------------------------------------------------*/
1115
static void sci_menu_stop ()
1119
/* if (get_is_reading()) write_scilab(""); */
1122
/*-----------------------------------------------------------------
1124
*-----------------------------------------------------------------*/
1126
extern int Sci_Help(char *name);
1128
static void sci_menu_help()
1130
StoreCommand("help();");
1133
/*-----------------------------------------------------------------
1135
*-----------------------------------------------------------------*/
1137
static void sci_menu_demos()
1139
StoreCommand( get_sci_data_strings(2));
1143
/*-----------------------------------------------------------------
1144
* Callbacks for the Graphic Window main menu
1145
*-----------------------------------------------------------------*/
1147
static void sci_menu_gwplus()
1149
MenuFixCurrentWin(lab_count+1);
1152
static void sci_menu_gwminus()
1154
MenuFixCurrentWin(lab_count-1);
1157
static void sci_menu_gwcreate_or_select()
1159
scig_sel(lab_count);
1162
static void sci_menu_gwraise()
1164
scig_raise(lab_count);
1167
static void sci_menu_gwdelete()
1169
scig_menu_delete(lab_count);
1172
/*-----------------------------------------------------------------
1173
* Execute predefined callbacks
1174
*-----------------------------------------------------------------*/
1176
static int call_predefined_callbacks(char *name, int winid)
1178
if (strcmp(name,"$clear")== 0) scig_menu_erase(winid) ;
1179
else if (strcmp(name,"$select")== 0) scig_menu_select(winid) ;
1180
else if (strcmp(name,"$print")== 0) scig_menu_print(winid);
1181
else if (strcmp(name,"$export")== 0) scig_export(winid);
1182
else if (strcmp(name,"$save")== 0) scig_menu_save(winid);
1183
else if (strcmp(name,"$load")== 0) scig_menu_load(winid);
1184
else if (strcmp(name,"$close")== 0) scig_menu_delete(winid);
1185
else if (strcmp(name,"$zoom")== 0) scig_menu_zoom(winid);
1186
else if (strcmp(name,"$unzoom")== 0) scig_menu_unzoom(winid);
1187
else if (strcmp(name,"$rot3d")== 0) scig_menu_rot3d(winid);
1188
else if (strcmp(name,"$help")== 0) sci_menu_help();
1189
else if (strcmp(name,"$stop")== 0) sci_menu_stop();
1190
else if (strcmp(name,"$kill")== 0) sci_menu_kill();
1191
else if (strcmp(name,"$demos")== 0) sci_menu_demos();
1192
else if (strcmp(name,"$fileops")== 0) sci_menu_fileops();
1193
else if (strcmp(name,"$gwselect")== 0) sci_menu_gwcreate_or_select();
1194
else if (strcmp(name,"$gwraise")== 0) sci_menu_gwraise();
1195
else if (strcmp(name,"$gwdelete")== 0) sci_menu_gwdelete();
1196
else if (strcmp(name,"$gwplus")== 0) sci_menu_gwplus();
1197
else if (strcmp(name,"$gwminus")== 0) sci_menu_gwminus();
1198
else if (strcmp(name,"$about")== 0) create_scilab_about ();
1199
else if (strcmp(name,"$resume")== 0) StoreCommand1("resume",1);
1200
else if (strcmp(name,"$abort")== 0) StoreCommand1("abort",1);
1201
else if (strcmp(name,"$restart")== 0) StoreCommand1("exec SCI/scilab.star;",1);
1202
else if (strcmp(name,"$quit")== 0) StoreCommand1("quit;",1);