diff --git a/src/include/msksheet.cpp b/src/include/msksheet.cpp index e51a13eca..e45f1543c 100755 --- a/src/include/msksheet.cpp +++ b/src/include/msksheet.cpp @@ -190,8 +190,10 @@ class TSpreadsheet : public TControl enum { MAX_COL=96 }; static int ROW_NUMBER_WIDTH; - // @cmember:(INTERNAL) Array di TToken_strings contenenti le righe - TString_array _str; + // @cmember:(INTERNAL) Array di TToken_strings contenenti le righe + TString_array _str; + // @cmember:(INTERNAL) Array di TToken_strings contenenti le righe originali + TString_array _original_str; // @cmember:(INTERNAL) Array di TToken_strings contenenti le righe copiate TString_array _copied_rows; // @cmember:(INTERNAL) Array delle colonne disattivate (solo visualizzazione) @@ -328,19 +330,27 @@ public: // @cmember Ritorna l' abilitazione della colonna
bool column_enabled(int col) const { return !column_disabled(col); } - // @cmember Ritorna il contenuto della riga
-esima - TToken_string& row(int n) { return _str.row(n); } + // @cmember Ritorna il contenuto della riga
-esima + TToken_string& row(int n) { return _str.row(n); } + // @cmember Ritorna il contenuto della riga original
-esima
+ TToken_string& original_row(int n) { return _original_str.row(n); }
// @cmember Aggiunge una riga allo spreadsheet passata come puntatore
int add(const TToken_string& s) { return _str.add(s); }
// @cmember Aggiunge una riga allo spreadsheet (vedi
bool destroy(int rec = -1, bool update_sheet = true);
- // @cmember Ritorna l'array di tutte le stringhe delle righe
- TString_array& rows_array() { return _str; }
-
+ // @cmember Ritorna l'array di tutte le stringhe delle righe
+ TString_array& rows_array() { return _str; }
+ // @cmember Ritorna l'array di tutte le stringhe delle righe originali
+ TString_array& original_rows_array() { return _original_str; }
+ // @cmember Salva l'array di tutte le stringhe nell'array delle righe originali
+ void update_original_rows(int r = -1);
+ // @cmember Azzera l'array delle righe originali
+ void zero_original_rows() { original_rows_array().destroy(); }
+
// @cmember Trova una colonna abilitata a partire da colonna
int find_enabled_column(int rec, int colonna, int direction) const;
// @cmember Trova un record abilitato a partire da rec
@@ -842,6 +852,19 @@ void TSpreadsheet::update_rec(int rec)
_needs_update = -1;
}
+void TSpreadsheet::update_original_rows(int r)
+{
+ if (r < 0)
+ _original_str = _str;
+ else
+ {
+ TToken_string & original_row = _original_str.row(r);
+ TToken_string & row = _str.row(r);
+
+ original_row = row;
+ }
+}
+
// Cerca una colonna abilitata a partire da colonna
// La prima cella utilizzabile ha indice 1
// rec e' un numero di record assoluto
@@ -954,8 +977,10 @@ int TSpreadsheet::insert(
if (ok)
{
TToken_string* toktok = new TToken_string(80, owner().separator());
- r = _str.insert(toktok, rec);
-
+ TToken_string* original_toktok = new TToken_string(80, owner().separator());
+
+ r = _str.insert(toktok, rec);
+ _original_str.insert(original_toktok, rec);
_properties.insert(NULL, r, true); // Crea lo spazio necessario per le proprieta'
// Notifica che l'inserimento e' terminato
@@ -1004,14 +1029,16 @@ bool TSpreadsheet::destroy(
if (rec < 0)
{
- _str.destroy();
+ _str.destroy();
+ _original_str.destroy();
_properties.destroy();
set_dirty(_row_dirty = false);
}
else
{
_properties.destroy(rec, true); // Destroy line info
- ok = _str.destroy(rec, true); // Destroy line
+ _original_str.destroy(rec, true); // Destroy line
+ ok = _str.destroy(rec, true); // Destroy line
}
if (ok && mask().is_running() && update_sheet)
@@ -2614,11 +2641,17 @@ void TSpreadsheet::str2mask(int riga)
bool TSpreadsheet::notify(int rec, KEY k)
{
const bool ok = _notify ? _notify(owner(), rec, k) : true;
- if (k == K_ENTER)
+
+ if (k == K_SPACE && ok)
+ update_original_rows(rec);
+ if (k == K_ENTER)
{
const bool cell_dirty = _cell_dirty; // preservato lo stato di cell_dirty
+
set_dirty(ok ? 1 : 3);
_cell_dirty = cell_dirty;
+ if (ok)
+ update_original_rows(rec);
}
return ok;
}
@@ -3055,7 +3088,26 @@ void TSheet_field::create(WINDOW parent)
// Certified 100%
TString_array& TSheet_field::rows_array() const
{
- return ((TSpreadsheet*)_ctl)->rows_array();
+ return ((TSpreadsheet*)_ctl)->rows_array();
+}
+
+
+// Certified 100%
+TString_array& TSheet_field::original_rows_array() const
+{
+ return ((TSpreadsheet*)_ctl)->original_rows_array();
+}
+
+// Certified 100%
+void TSheet_field::update_original_rows(int row) const
+{
+ ((TSpreadsheet*)_ctl)->update_original_rows(row);
+}
+
+// Certified 100%
+void TSheet_field::zero_original_rows() const
+{
+ ((TSpreadsheet*)_ctl)->zero_original_rows();
}
const char* TSheet_field::cell(int r, int c) const
@@ -3069,6 +3121,35 @@ const char* TSheet_field::cell(int r, int c) const
return v ? v : " ";
}
+int TSheet_field::set_row_cell_currency(TToken_string& row, short id, const real& n)
+{
+ const TMask& m = sheet_mask();
+ const TCurrency_field& cf = (const TCurrency_field&)m.field(id);
+ TOperable_field* vf = cf.driver(0);
+
+ if (vf != nullptr && !vf->empty()) // E' un importo in valuta?
+ {
+ const TString& codval = vf->get();
+
+ if (is_true_value(codval)) // La valuta e' diversa dall'euro?
+ {
+ if (n.is_zero())
+ set_row_cell(row, id, "");
+ else
+ {
+ const TCurrency cur(n, codval);
+ set_row_cell(row, id, cur.get_num().string());
+ }
+ return true;
+ }
+ }
+ if (n.is_zero())
+ set_row_cell(row, id, "");
+ else
+ set_row_cell(row, id, n.string(-1, 2));
+ return false;
+}
+
int TSheet_field::set_row_cell(short id, const char * value, int nrow)
{
if (nrow < 0)
@@ -3146,6 +3227,17 @@ int TSheet_field::set_row_cell(short id, const bool value, int nrow)
return nrow;
}
+int TSheet_field::set_row_cell_currency(short id, const real& value, int nrow)
+{
+ if (nrow < 0)
+ nrow = first_empty();
+ set_row_cell_currency(row(nrow), id, value);
+#ifdef DBG
+ const TToken_string & r = row(nrow);
+#endif
+ return nrow;
+}
+
// Certified 100%
// Ritorna l'indice della prima riga vuota dello sheet
int TSheet_field::first_empty() const
@@ -3159,28 +3251,45 @@ int TSheet_field::first_empty() const
return n;
}
-
// @doc EXTERNAL
// @mfunc Ritorna nuova riga dello spreadshhet
//
// @rdesc Ritorna la stringa letta
TToken_string& TSheet_field::row(
- int n) // @parm Numero della riga da leggere/creare
+ int n) // @parm Numero della riga da leggere/creare
- // @comm Se il parametro e maggiore del numero massimo di righe presenti
- // o minore di 0 viene aggiunta una riga vuota in fondo allo spreadsheet
- // (viene chiamata la e maggiore del numero massimo di righe presenti
+ // o minore di 0 viene aggiunta una riga vuota in fondo allo spreadsheet
+ // (viene chiamata la e maggiore del numero massimo di righe presenti
+ // o minore di 0 viene aggiunta una riga vuota in fondo allo spreadsheet
+ // (viene chiamata la -esimo della riga
const char* cell(int r, int c) const;
@@ -158,6 +166,7 @@ public:
virtual void set_row_cell(TToken_string & row, short id, const real& value) { row.add(value, cid2index(id)); }
virtual void set_row_cell(TToken_string & row, short id, const TDate& value) { row.add(value, cid2index(id)); }
virtual void set_row_cell(TToken_string & row, short id, const bool value) { row.add(value ? "X" : "", cid2index(id)); }
+ virtual int set_row_cell_currency(TToken_string& row, short id, const real& n);
virtual int set_row_cell(short id, const char * value, int nrow = -1);
virtual int set_row_cell(short id, char value, int nrow = -1);
@@ -166,6 +175,15 @@ public:
virtual int set_row_cell(short id, const real& value, int nrow = -1);
virtual int set_row_cell(short id, const TDate& value, int nrow = -1);
virtual int set_row_cell(short id, const bool value, int nrow = -1);
+ virtual int set_row_cell_currency(short id, const real& n, int nrow = -1);
+
+ virtual const char * get_str_row_cell(TToken_string & row, short id) { return row.get(cid2index(id)); }
+ virtual char get_char_row_cell(TToken_string & row, short id) { return row.get_char(cid2index(id)); }
+ virtual long get_long_row_cell(TToken_string & row, short id) { return row.get_long(cid2index(id)); }
+ virtual int get_int_row_cell(TToken_string & row, short id) { return row.get_int(cid2index(id)); }
+ virtual real get_real_row_cell(TToken_string & row, short id) { return real(row.get(cid2index(id))); }
+ virtual TDate get_date_row_cell(TToken_string & row, short id) { return TDate(row.get(cid2index(id))); }
+ virtual bool get_bool_row_cell(TToken_string & row, short id) { const TString s = get_str_row_cell(row, id); return s == "X"; }
virtual const char * get_str_row_cell(int nrow, short id) { return row(nrow).get(cid2index(id)); }
virtual char get_char_row_cell(int nrow, short id) { return row(nrow).get_char(cid2index(id)); }
@@ -216,6 +234,8 @@ public:
virtual KEY run_editmask(int n);
// @cmember Setta il membro della classe in un numero di colonna logica
int cid2index(short cid) const;