1 // -*- compile-command: "g++ -I.. -I. -g -c Tableur.cc " -*-
2 #ifndef _TABLEUR_H
3 #define _TABLEUR_H
4 
5 #ifndef IN_GIAC
6 #include <giac/first.h>
7 #else
8 #include "first.h"
9 #endif
10 /*
11  *  Copyright (C) 2002,2014 B. Parisse, Institut Fourier, 38402 St Martin d'Heres
12  *
13  *  This program is free software; you can redistribute it and/or modify
14  *  it under the terms of the GNU General Public License as published by
15  *  the Free Software Foundation; either version 3 of the License, or
16  *  (at your option) any later version.
17  *
18  *  This program is distributed in the hope that it will be useful,
19  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
20  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  *  GNU General Public License for more details.
22  *
23  *  You should have received a copy of the GNU General Public License
24  *  along with this program. If not, see <http://www.gnu.org/licenses/>.
25  */
26 
27 #ifndef IN_GIAC
28 #include <giac/gen.h>
29 #else
30 #include "gen.h"
31 #endif
32 #ifdef HAVE_LIBFLTK
33 #include "Flv_Table.H"
34 #include "Flve_Input.H"
35 #include <FL/Fl_Menu_Button.H>
36 #include <FL/Fl_Double_Window.H>
37 #include <FL/fl_draw.H>
38 #include <FL/fl_message.H>
39 #endif
40 #include "Input.h"
41 #include "Graph.h"
42 #include "Graph3d.h"
43 
44 #ifndef NO_NAMESPACE_XCAS
45 namespace xcas {
46 #endif // ndef NO_NAMESPACE_XCAS
47 #ifdef HAVE_LIBFLTK
48   extern Fl_Menu_Item Tableur_menu[];
49   class Flv_Table_Gen;
50   bool iscell_range(const giac::gen & g,const giac::matrice & m,giac::matrice & mselect,Flv_Table_Gen * ptr);
51   // Returns 0 if not a cell range, 1 if vc is made of successives integers, n if of n independant columns, set absolu to true if IDNT are used for cols
52   int iscell_range(const giac::gen & g,const giac::matrice & m,giac::matrice & mselect,Flv_Table_Gen * sptr,int & r1,int & r2,std::vector<int> & vc,bool & absolu);
53 
54   bool tablefunc_dialog(Fl_Widget * spread_ptr,std::string & arg,bool plot,int type,const std::string & title);
55   bool tableseq_dialog(Fl_Widget * spread_ptr,std::string & arg,bool plot,const std::string & title,std::string & u0param);
56 
57   // Should be inside a Tableur Group
58   class Flv_Table_Gen : public Flv_Table{
59   public:
60     static int def_rows,def_cols;
61     giac::matrice m;
62     giac::vecteur m_history;
63     int max_history,cur_history;
64     giac::matrice selected,selected_1;
65     giac::gen name,init; // sheet evaluation saves the matrix in name
66     bool is_spreadsheet,matrix_fill_cells;
67     bool move_right;
68     bool changed_;
69     int sort_col,matrix_symmetry,spreadsheet_recompute;
70     int push_row,push_col;
71     int prev_row,prev_col;
72     giac::context * contextptr;
73     bool editing,computing;
74     int edit_row,edit_col;
75     Xcas_Text_Editor * input;
76     Multiline_Input_tab* _goto;
77     Graph2d * graph,*graph2d;
78     Graph3d * graph3d;
79     Fl_Menu_Button * mb;
80     Fl_Window * win2,*win3;
81     std::string status_string;
82     std::string * filename,prefix_filename;
83     unsigned max_printsize;
84     int header_event,last_event;
85     // if printing cell requires more than max_printsize, cell is not displayed
86     virtual int handle(int event);
87     void finish_flv_table_gen();
88     void update_name();
89     void config();
Flv_Table(X,Y,W,H,l)90   Flv_Table_Gen(int X,int Y,int W,int H,const char *l=0):Flv_Table(X,Y,W,H,l),matrix_fill_cells(true),matrix_symmetry(0),spreadsheet_recompute(true),max_printsize(1024){ contextptr=0; computing=editing=false; graph=0;graph2d=0; graph3d=0; _goto=0;input=0; name=0; finish_flv_table_gen();};
91     Flv_Table_Gen( int X, int Y, int W, int H,const giac::gen & g,const char *l=0 );
92     Flv_Table_Gen( int X, int Y, int W, int H,const giac::matrice & mym,const char *l=0);
93     ~Flv_Table_Gen() ;
94     virtual void draw_cell(int Offset,int &X,int &Y,int &W,int &H,int R,int C );
95     void enter_move();
96     //	Required for editing
97     //virtual void save_editor( Fl_Widget *e, int R, int C );
98     //virtual void load_editor( Fl_Widget *e, int R, int C );
99     //virtual void position_editor( Fl_Widget *e, int x, int y, int w, int h, Flv_Style &s );
100     void spread_erase(int nrows,int ncols);
101     void spread_insert(int nrows,int ncols);
102     void copy(int clipboard=0);
103     void blank();
104     void blank(int row_min,int r,int col_min,int c);
105     void erase_row_col(int i); // 2 ask, 1 col, 0 row
106     void copy_right();
107     void copy_down();
108     void copy_first_in_selection();
109     void paste(const giac::matrice & m,bool reeval=true);
110     void addrowatend();
111     void addcolatend();
112     void set_matrix(const giac::matrice & m,bool interruptible=false,bool reeval=true);
113     void set_matrix(const giac::gen & g,bool interruptible=false,bool reeval=true);
114     void resizesheet(int nr,int nc);
115     void spread_eval_interrupt();
116     void update_spread_graph();
117     int set_graphic_dialog(const std::string & title,const std::string & aide,giac::gen & in, giac::gen & out,bool show_class,bool & absolu,bool & transpose,double & degree);
118     void set_graphic(const giac::gen & function,const std::string & aide);
119     void update_status() ;
120     void update_goto() ;
121     void update_input() ;
122     void backup();
123     void restore(int i);
124     void changed();
125   };
126 
127   std::string tableur_insert(Flv_Table_Gen * tg);
128 
129   giac::gen Xcas_fltk_Row(const giac::gen & g,const giac::context * contextptr);
130   giac::gen Xcas_fltk_Col(const giac::gen & g,const giac::context * contextptr);
131   giac::gen Xcas_fltk_current_sheet(const giac::gen & g,const giac::context * contextptr);
132 
133   class Tableur_Group : public Fl_Tile {
134   public:
135     int disposition; // 0, 1: graphe invisible, 2: portait, 3: landscape
136     double dtable,dgraph,dparam;
137     Flv_Table_Gen * table;
138     Fl_Menu_Bar * menubar;
139     Fl_Group * reevalsave;
140     Fl_Button * fname;
141     Fl_Box * borderbox;
142     Tableur_Group(int X,int Y,int W,int H,int L,int disp=2);
143     virtual void resize2(double dt=0,double dg=0,double dp=0);
144     virtual int handle(int event);
145     void save_dparam();
146   };
147 
148   // Insure that all elements of m that are vectors have length <= 3
149   void spread_ck(giac::matrice & m);
150 
151   struct xcas_matrix {
152     giac::matrice m;
153     bool changed,is_spreadsheet;
154     int rows,cols,row,row_end,col,col_end;
xcas_matrixxcas_matrix155     xcas_matrix(const giac::matrice & mym,bool b,bool is_sp,int nr,int nc,int rs,int re,int cs,int ce): m(makefreematrice(mym)),changed(b),is_spreadsheet(is_sp),rows(nr),cols(nc),row(rs),row_end(re),col(cs),col_end(ce) {}
xcas_matrixxcas_matrix156     xcas_matrix(): changed(false),is_spreadsheet(true),rows(50),cols(10),row(0),row_end(0),col(0),col_end(0) { m=makefreematrice(giac::vecteur(50,giac::vecteur(10,giac::zero))); makespreadsheetmatrice(m,giac::context0); }
157   };
158 
159   struct editor_string {
160     std::string s;
161     bool changed;
162     int pos1,pos2;
editor_stringeditor_string163     editor_string(const std::string & mys,bool b,int i,int j):s(mys),changed(b),pos1(i),pos2(j) {}
editor_stringeditor_string164     editor_string():s(""),changed(false),pos1(0),pos2(0) {}
165   };
166 #endif
167 #ifndef NO_NAMESPACE_XCAS
168 } // namespace xcas
169 #endif // ndef NO_NAMESPACE_XCAS
170 
171 #endif // _TABLEUR_H
172