File: xmen_getfile.c

package info (click to toggle)
scilab 2.4-1
  • links: PTS
  • area: non-free
  • in suites: potato, slink
  • size: 55,196 kB
  • ctags: 38,019
  • sloc: ansic: 231,970; fortran: 148,976; tcl: 7,099; makefile: 4,585; sh: 2,978; csh: 154; cpp: 101; asm: 39; sed: 5
file content (144 lines) | stat: -rw-r--r-- 3,919 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/* Copyright INRIA */
/********************************************************
 * choice.c The XWindow part 
 * All the generic stuff for dealing with choice widgets.
 * (from xgc) 
 ***********************************************************/

#include "men_scilab.h"

extern int set_cmap _PARAMS((Window w)); 
extern void DisplayInit _PARAMS((char *string,Display **dpy,Widget *toplevel));
extern int ok_prep  _PARAMS((char *filemask,char *dirname,char *title,int flag,int *err));
extern int ok_end  _PARAMS((void));
extern int w_init  _PARAMS((  Widget w));
extern int set_temp_wf_cursor _PARAMS((Cursor cursor));
extern void Rescan    _PARAMS( (Widget widget, XEvent*	event,
				String* params,    Cardinal* num_params));
extern int reset_wf_cursor  _PARAMS((void));
extern int create_file_panel  _PARAMS((  Widget w, char * description));
extern int getMenuBut0  _PARAMS((  Widget *w));

extern void C2F(cvstr)();

extern XtAppContext app_con; 

extern Widget file_popup;
extern Boolean	file_msg_is_popped;
extern Widget	file_msg_popup;
extern Cursor   cur_wf_cursor,arrow_wf_cursor,wait_wf_cursor;

static int ok_Flag_sci; 
static char *xgetf_str ;
static int error=0;

/*************************************************     
 * Really Ugly I'm ashamed 
 * The main function to activate the file menu 
 **********************************************************/

int GetFileWindow(filemask,file,dirname,flag,ierr,title)
     char *filemask,*dirname,**file,*title;
     int flag,*ierr;
{
  int err=0;
  static Display *dpy = (Display *) NULL;
  static  Widget toplevel,toplevel1;
  error= 0;
  getMenuBut0(&toplevel);
  DisplayInit("",&dpy,&toplevel1);
  if ( toplevel == (Widget) 0) 
    {
      /* we are in scilab -nw */
      toplevel = toplevel1;
    }
  popup_file_panel1(toplevel,title);
  ok_prep(filemask,dirname,title,flag,&err);
  if ( err != 1 )   XtSpecialLoop();
  ok_end();
  XtSetSensitive(toplevel,True);
  *file = xgetf_str;
  *ierr = error;
  if ( ok_Flag_sci == -1 ) 
    return(FALSE);
  else
    return(TRUE);
}

/*************************************************     
 * X11 Event loop 
 **********************************************************/

void XtSpecialLoop()
{
  XEvent event;
  ok_Flag_sci= 0;
  for (;;) {
    XtAppNextEvent(app_con,&event);
    XtDispatchEvent(&event);
    if (ok_Flag_sci != 0) break;
  }
}

/*************************************************     
 * The cancel command callback 
 **********************************************************/

void cancel_getfile() 
{ 
  ok_Flag_sci = -1;
}

/*************************************************     
 * Activated when file is choosed 
 * write result in a static var (str) 
 **********************************************************/

int write_getfile(dir,file)
     char dir[],file[];
{
  xgetf_str = (char *) MALLOC( (strlen(dir)+strlen(file)+2)*(sizeof(char)));
  if (xgetf_str != 0)
    { 
      int ind ;
      sprintf(xgetf_str,"%s/%s",dir,file);
      ind = strlen(xgetf_str) - 1 ;
      if (xgetf_str[ind] == '\n') xgetf_str[ind] = '\0' ;
    }
  else 
    {
      Scistring("Malloc : No more place");
      error = 1;
    }
  ok_Flag_sci= 1;
  return(0);
}

/*************************************************     
 * Activate the file menu 
 **********************************************************/

int popup_file_panel1(w,description)
    Widget	    w;
     char *description;
{
    extern Atom     wm_delete_window;
    w_init(w);
    set_temp_wf_cursor(wait_wf_cursor);
    XtSetSensitive(w, False);
    if (!file_popup)
	create_file_panel(w,description);
    else
      Rescan((Widget) 0, (XEvent*) 0, (String*) 0, (Cardinal*) 0);

    XtPopup(file_popup, XtGrabNonexclusive);
    (void) XSetWMProtocols(XtDisplay(file_popup), XtWindow(file_popup),
			   &wm_delete_window, 1);
    if (file_msg_is_popped)
	XtAddGrab(file_msg_popup, False, False);
    reset_wf_cursor();
    return(0);
}