~ubuntu-branches/ubuntu/hoary/scilab/hoary

« back to all changes in this revision

Viewing changes to routines/menusX/gxmen_getfile.c

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2005-01-09 22:58:21 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050109225821-473xr8vhgugxxx5j
Tags: 3.0-12
changed configure.in to build scilab's own malloc.o, closes: #255869

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*------------------------------------------------------------------------
 
2
 *    Scilab Gtk menus 
 
3
 *    Copyright (C) 2001 Enpc/Jean-Philippe Chancelier
 
4
 *    jpc@cermics.enpc.fr 
 
5
 --------------------------------------------------------------------------*/
 
6
 
 
7
#include <stdio.h>
 
8
#include <stdlib.h>
 
9
#include <string.h>
 
10
#include <math.h>
 
11
#include <sys/stat.h>
 
12
#include <time.h>
 
13
#include <unistd.h>
 
14
#include <gtk/gtk.h>
 
15
 
 
16
#include "men_scilab.h"
 
17
 
 
18
extern void C2F(cvstr)();
 
19
 
 
20
/*--------------------------------------------------------------
 
21
 * Gtk version for scilab file selection 
 
22
 * GtkFileSelection
 
23
 *--------------------------------------------------------------*/
 
24
 
 
25
typedef enum { OK, CANCEL , DESTROY, RESET } state; 
 
26
 
 
27
static void file_selection_ok (GtkWidget  *w,  state *rep)
 
28
{
 
29
  *rep = OK;
 
30
  gtk_main_quit();
 
31
}
 
32
 
 
33
static void file_selection_destroy (GtkWidget  *w,  state *rep)
 
34
{
 
35
  *rep = DESTROY;
 
36
  gtk_main_quit();
 
37
}
 
38
 
 
39
static void file_selection_cancel (GtkWidget *w,  state *rep)
 
40
{
 
41
  *rep = CANCEL;
 
42
  gtk_main_quit();
 
43
}
 
44
 
 
45
/* XXXX reste a rajouter un bouton home et un bouton SCI 
 
46
 * Il faut aussi expanser les dirname ? SCI HOME etc....
 
47
 */
 
48
 
 
49
int GetFileWindow(char *filemask,char **file,char *dirname,
 
50
                  int flag,int *ierr,char *title)
 
51
{
 
52
 return  sci_get_file_window(filemask,file,dirname,flag,0,ierr,title);
 
53
}
 
54
    
 
55
 
 
56
int  sci_get_file_window(char *filemask,char **file,char *dirname,
 
57
                         int flag,int action,int *ierr,char *title)
 
58
{
 
59
  static int last_choice = 0;
 
60
  GList *cbitems = NULL;
 
61
  GtkWidget *combo;
 
62
  static int n_actions = 4 ;
 
63
  static char *actions[]={ "getf","exec","load","chdir",NULL };
 
64
  guint signals[3];
 
65
  static state rep;
 
66
  GtkWidget *window;
 
67
  rep =RESET ;
 
68
 
 
69
  start_sci_gtk(); /* in case gtk was not initialized */
 
70
 
 
71
  window = gtk_file_selection_new (title);
 
72
 
 
73
  if ( strcmp(dirname,".") == 0) 
 
74
    gtk_file_selection_set_filename (GTK_FILE_SELECTION (window),"./");
 
75
  else 
 
76
    gtk_file_selection_set_filename (GTK_FILE_SELECTION (window),dirname);
 
77
  gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_MOUSE);
 
78
 
 
79
  if ( action == 1 ) 
 
80
    {
 
81
      int j;
 
82
      for (j = 0; j < n_actions  ; ++j) 
 
83
        cbitems = g_list_append(cbitems, actions[j]);
 
84
      combo =  gtk_combo_new ();
 
85
      gtk_combo_set_popdown_strings (GTK_COMBO (combo), cbitems);
 
86
      gtk_entry_set_text (GTK_ENTRY (GTK_COMBO(combo)->entry),
 
87
                          actions[last_choice]);
 
88
      gtk_entry_set_editable(GTK_ENTRY (GTK_COMBO(combo)->entry),FALSE);
 
89
      
 
90
      gtk_box_pack_start (GTK_BOX (GTK_FILE_SELECTION (window)->action_area), 
 
91
                          combo, FALSE, FALSE, 0);
 
92
      gtk_widget_show (combo);
 
93
    }
 
94
 
 
95
  signals[0]=gtk_signal_connect (GTK_OBJECT (window), "destroy",
 
96
                      GTK_SIGNAL_FUNC(file_selection_destroy),
 
97
                      &rep);
 
98
 
 
99
  signals[1]=gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (window)->ok_button),
 
100
                      "clicked", GTK_SIGNAL_FUNC(file_selection_ok),
 
101
                      &rep);
 
102
  
 
103
  signals[2]=gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (window)->cancel_button),
 
104
                      "clicked", GTK_SIGNAL_FUNC(file_selection_cancel),
 
105
                      &rep);
 
106
  gtk_widget_show (window);
 
107
  while (1) 
 
108
    {
 
109
      gtk_main();
 
110
      /* want to quit the gtk_main only when this getfile is achieved 
 
111
       */
 
112
      if ( rep != RESET ) break;
 
113
    }
 
114
  if ( rep == OK ) 
 
115
    {
 
116
      int action_length=0;
 
117
      char *loc = gtk_file_selection_get_filename(GTK_FILE_SELECTION(window));
 
118
      if ( action == 1 ) 
 
119
        {
 
120
          int j;
 
121
          gchar *entry_text;
 
122
          entry_text = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(combo)->entry));
 
123
          for (j = 0; j < n_actions ; ++j) 
 
124
            { 
 
125
              if ( strcmp(entry_text, actions[j]) == 0) 
 
126
                {
 
127
                  last_choice = j ;
 
128
                  action_length = strlen(actions[j])+3;
 
129
                  break;
 
130
                }
 
131
            }
 
132
        }
 
133
      /* Attention la taille doit correspondre � "%s('%s');" */
 
134
      if (( *file = (char *) MALLOC((strlen(loc)+6+action_length)*sizeof(char))) == NULL) 
 
135
        {
 
136
          Scistring("Malloc : running out of memory");
 
137
          *ierr = 1;
 
138
        }
 
139
      else 
 
140
        { 
 
141
          if ( action == 1) 
 
142
            sprintf(*file,"%s('%s');",actions[last_choice],loc);
 
143
          else 
 
144
            strcpy(*file,loc);
 
145
          *ierr=0;
 
146
        }
 
147
 
 
148
    }
 
149
  /* since here we are no more in a gtk_main we must disconnect signals 
 
150
   * before destroying widget window 
 
151
   */
 
152
  if ( rep != DESTROY ) 
 
153
    {
 
154
      gtk_signal_disconnect(GTK_OBJECT(window),signals[0]);
 
155
      gtk_signal_disconnect(GTK_OBJECT (GTK_FILE_SELECTION (window)->ok_button),signals[1]);
 
156
      gtk_signal_disconnect(GTK_OBJECT (GTK_FILE_SELECTION (window)->cancel_button),signals[2]);
 
157
      gtk_widget_destroy(window);
 
158
    }
 
159
  return (rep == OK) ? TRUE : FALSE ; 
 
160
}