Migliorata gestione errori sulle celle.

git-svn-id: svn://10.65.10.50/trunk@26 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
guy 1994-08-17 14:07:00 +00:00
parent fe15049eab
commit b6fc4a65e3

View File

@ -18,13 +18,9 @@ const short FIRST_FIELD = 101;
class TSpreadsheet : public TWindow class TSpreadsheet : public TWindow
{ {
enum enum { ITF_CID = 0, LIST_CID = 1 };
{
ITF_CID = 0, LIST_CID = 1
};
TArray _str; // Array di TToken_strings TArray _str; // Array di TToken_strings
TBit_array _column_disabled; TBit_array _column_disabled;
TArray _disabled; // Array di TBit_array TArray _disabled; // Array di TBit_array
@ -61,10 +57,7 @@ class TSpreadsheet:public TWindow
void update(int row); void update(int row);
TToken_string& row(int n); TToken_string& row(int n);
TArray & rows_array () const TArray& rows_array() const { return (TArray&)_str; }
{
return (TArray &) _str;
}
int add(TToken_string&); int add(TToken_string&);
int insert(int rec); int insert(int rec);
bool destroy(int rec = -1); bool destroy(int rec = -1);
@ -73,35 +66,13 @@ class TSpreadsheet:public TWindow
void enable_cell(int row, int column, bool on = TRUE); void enable_cell(int row, int column, bool on = TRUE);
bool cell_disabled(int row, int column) const; bool cell_disabled(int row, int column) const;
TMask & mask () TMask& mask() { return _mask; }
{ int items() const { return _str.items(); }
return _mask; int columns() const { return _columns; }
} bool dirty() const { return _dirty; }
void set_notify(SPREADSHEET_NOTIFY n) { _notify = n; }
int items () const void set_dirty(bool spork = TRUE) { _dirty = spork; }
{
return _str.items ();
}
int columns () const
{
return _columns;
}
bool dirty () const
{
return _dirty;
}
void set_notify (SPREADSHEET_NOTIFY n)
{
_notify = n;
}
void set_dirty (bool spork = TRUE)
{
_dirty = spork;
}
TSpreadsheet(short x, short y, short dx, short dy, const char* maskname, int maskno, TSpreadsheet(short x, short y, short dx, short dy, const char* maskname, int maskno,
const char* head, WINDOW parent); const char* head, WINDOW parent);
@ -154,9 +125,7 @@ TSpreadsheet ::TSpreadsheet (short x, short y, short dx, short dy,
{ {
w = atoi(at+1); w = atoi(at+1);
*at = '\0'; *at = '\0';
} } else w = strlen(h);
else
w = strlen (h);
width[i] = w+1; width[i] = w+1;
@ -214,14 +183,12 @@ TSpreadsheet ::TSpreadsheet (short x, short y, short dx, short dy,
{ {
const int cid = FIRST_FIELD+i; // Column & Field ID const int cid = FIRST_FIELD+i; // Column & Field ID
const TMask_field* f = field(cid); // Field on mask const TMask_field* f = field(cid); // Field on mask
const int w = width[i] + (f->has_query ()? 2 : 0); // Column const int w = width[i] + (f->has_query() ? 2 : 0); // Column width
// width
long flags = XI_ATR_EDITMENU | XI_ATR_AUTOSCROLL; long flags = XI_ATR_EDITMENU | XI_ATR_AUTOSCROLL;
if (f->class_id() == CLASS_REAL_FIELD) flags |= XI_ATR_RJUST; if (f->class_id() == CLASS_REAL_FIELD) flags |= XI_ATR_RJUST;
if (f->active()) flags |= XI_ATR_ENABLED; if (f->active()) flags |= XI_ATR_ENABLED;
else else _column_disabled.set(i);
_column_disabled.set (i);
coldef = xi_add_column_def(listdef, cid, coldef = xi_add_column_def(listdef, cid,
flags, cid, w, width[i], (char*)h); flags, cid, w, width[i], (char*)h);
@ -248,6 +215,7 @@ TSpreadsheet ::TSpreadsheet (short x, short y, short dx, short dy,
_list = xi_get_obj(itf, LIST_CID); _list = xi_get_obj(itf, LIST_CID);
} }
// Converts a row number in the correspondig record number // Converts a row number in the correspondig record number
int TSpreadsheet::row2rec(int row) int TSpreadsheet::row2rec(int row)
{ {
@ -265,6 +233,7 @@ int TSpreadsheet ::row2rec (int row)
return (int)rec[row]; return (int)rec[row];
} }
// Converts a row number in the correspondig record number // Converts a row number in the correspondig record number
int TSpreadsheet::rec2row(int record) int TSpreadsheet::rec2row(int record)
{ {
@ -317,6 +286,7 @@ void TSpreadsheet ::set_focus_cell (int riga, int colonna)
xi_set_focus(&cell); xi_set_focus(&cell);
} }
int TSpreadsheet::insert(int rec) int TSpreadsheet::insert(int rec)
{ {
const bool ok = notify(rec, K_INS); const bool ok = notify(rec, K_INS);
@ -332,6 +302,7 @@ int TSpreadsheet ::insert (int rec)
return r; return r;
} }
bool TSpreadsheet::destroy(int rec) bool TSpreadsheet::destroy(int rec)
{ {
bool ok = TRUE; bool ok = TRUE;
@ -353,6 +324,7 @@ bool TSpreadsheet ::destroy (int rec)
return ok; return ok;
} }
void TSpreadsheet::update(int row) void TSpreadsheet::update(int row)
{ {
if (row < 0) if (row < 0)
@ -365,6 +337,7 @@ void TSpreadsheet ::update (int row)
update_rec(row); update_rec(row);
} }
void TSpreadsheet::xiev_handler(XI_OBJ *itf, XI_EVENT *xiev) void TSpreadsheet::xiev_handler(XI_OBJ *itf, XI_EVENT *xiev)
{ {
TSpreadsheet* es = (TSpreadsheet*)xi_get_app_data(itf); TSpreadsheet* es = (TSpreadsheet*)xi_get_app_data(itf);
@ -372,6 +345,7 @@ void TSpreadsheet ::xiev_handler (XI_OBJ * itf, XI_EVENT * xiev)
es->list_handler(xiev); es->list_handler(xiev);
} }
// Certified 75% // Certified 75%
void TSpreadsheet::list_handler(XI_EVENT *xiev) void TSpreadsheet::list_handler(XI_EVENT *xiev)
{ {
@ -437,9 +411,7 @@ case XIE_CELL_REQUEST:
if (cell_disabled(rec, col)) if (cell_disabled(rec, col))
xiev->v.cell_request.back_color = MASK_BACK_COLOR; xiev->v.cell_request.back_color = MASK_BACK_COLOR;
} }
} } else src = format("%d", rec+1);
else
src = format ("%d", rec + 1);
const int len = xiev->v.cell_request.len; const int len = xiev->v.cell_request.len;
char* dst = xiev->v.cell_request.s; char* dst = xiev->v.cell_request.s;
@ -473,8 +445,7 @@ case XIE_BUTTON:
check_enabled = TRUE; // Enable checks check_enabled = TRUE; // Enable checks
xi_set_focus(xiev->v.xi_obj); // Restore focus to cell xi_set_focus(xiev->v.xi_obj); // Restore focus to cell
} }
} } else
else
if (xiev->v.xi_obj->type == XIT_LIST) if (xiev->v.xi_obj->type == XIT_LIST)
insert(-1); insert(-1);
break; break;
@ -540,14 +511,23 @@ case XIE_ON_CELL:
else else
{ {
xiev->refused = TRUE; // Refuse focus on disabled cells xiev->refused = TRUE; // Refuse focus on disabled cells
const int r = xiev->v.xi_obj->v.cell.row;
int c = xiev->v.xi_obj->v.cell.column;
c += cur_col > col ? -1 : +1;
if (c < 0) c = _columns-1; else
if (c >= _columns) c = 0;
XI_OBJ cell;
XI_MAKE_CELL(&cell, _list, r, c);
xi_set_focus(&cell);
} }
} }
break; break;
case XIE_OFF_CELL: case XIE_OFF_CELL:
if (edit_field && check_enabled) if (edit_field && check_enabled)
{ {
TMask_field * c = edit_field; // Save field, it could turn out to TMask_field* c = edit_field; // Save field, it could turn out to be NULL on error
// be NULL on error
const TString80 old(c->get()); // Save old value on mask const TString80 old(c->get()); // Save old value on mask
const TString80 nuo(c->picture_data(xi_get_text(xiev->v.xi_obj, NULL, -1), TRUE)); const TString80 nuo(c->picture_data(xi_get_text(xiev->v.xi_obj, NULL, -1), TRUE));
if (old != nuo) if (old != nuo)
@ -563,16 +543,18 @@ case XIE_OFF_CELL:
if (c->on_key(K_TAB) == FALSE) // Test it if (c->on_key(K_TAB) == FALSE) // Test it
{ {
c->set(old); c->set(old);
xi_set_focus (xiev->v.xi_obj); XI_OBJ* itf = xi_get_itf(win());
// xi_set_focus(xiev->v.xi_obj);
} }
else else
{ {
xiev->refused = TRUE;
mask2str(cur_row); // Update sheet row mask2str(cur_row); // Update sheet row
edit_field = NULL; // Reset current field edit_field = NULL; // Reset current field
xi_set_color(xiev->v.xi_obj, XIC_BACK, NORMAL_BACK_COLOR);
} }
check_enabled = TRUE; check_enabled = TRUE;
} }
xi_set_color (xiev->v.xi_obj, XIC_BACK, NORMAL_BACK_COLOR);
} }
break; break;
case XIE_GET_PERCENT: case XIE_GET_PERCENT:
@ -610,7 +592,6 @@ case K_F1:
edit_field->on_key(K_F1); edit_field->on_key(K_F1);
set_focus_cell(cur_row, cur_col); set_focus_cell(cur_row, cur_col);
check_enabled = TRUE; // Enable checks check_enabled = TRUE; // Enable checks
// xiev->refused = TRUE;
break; break;
case K_F2: case K_F2:
case K_F3: case K_F3:
@ -628,26 +609,20 @@ case K_F9:
check_enabled = TRUE; // Enable checks check_enabled = TRUE; // Enable checks
} }
break; break;
case K_PLUS: /*
insert (cur_row);
xiev->refused = TRUE;
break;
case K_PREV: case K_PREV:
xi_scroll(_list, XI_SCROLL_PGUP); xi_scroll(_list, XI_SCROLL_PGUP);
// xiev->refused = TRUE;
break; break;
case K_NEXT: case K_NEXT:
xi_scroll(_list, XI_SCROLL_PGDOWN); xi_scroll(_list, XI_SCROLL_PGDOWN);
// xiev->refused = TRUE;
break; break;
case K_HOME: case K_HOME:
xi_scroll(_list, XI_SCROLL_FIRST); xi_scroll(_list, XI_SCROLL_FIRST);
// xiev->refused = TRUE;
break; break;
case K_END: case K_END:
xi_scroll(_list, XI_SCROLL_LAST); xi_scroll(_list, XI_SCROLL_LAST);
// xiev->refused = TRUE;
break; break;
*/
default: default:
break; break;
} }
@ -704,26 +679,12 @@ class TSpreadsheet:public TArray_sheet
TSpreadsheet(short x, short y, short dx, short dy, const char* maskname, int maskno, TSpreadsheet(short x, short y, short dx, short dy, const char* maskname, int maskno,
const char* head, WINDOW parent); const char* head, WINDOW parent);
TArray & rows_array () const TArray& rows_array() const { return data(); }
{
return data ();
}
TMask & mask () TMask& mask() { return _mask; }
{ void set_notify(SPREADSHEET_NOTIFY n) { _notify = n; }
return _mask; void set_dirty(bool spork = TRUE) { _dirty = spork;}
} bool dirty() const { return _dirty;}
void set_notify (SPREADSHEET_NOTIFY n)
{
_notify = n;
}
void set_dirty (bool spork = TRUE)
{_dirty = spork;
}
bool dirty ()const
{
return _dirty;
}
void enable_column(int col, bool on); void enable_column(int col, bool on);
void enable_cell(int row, int column, bool on = TRUE); void enable_cell(int row, int column, bool on = TRUE);
@ -735,8 +696,7 @@ TSpreadsheet ::TSpreadsheet (short x, short y, short dx, short dy,
const char* head, WINDOW parent) const char* head, WINDOW parent)
: TArray_sheet(x, y, dx, dy, maskname, head, 0, parent), : TArray_sheet(x, y, dx, dy, maskname, head, 0, parent),
_mask(maskname, NO_MODE, maskno), _notify(NULL) _mask(maskname, NO_MODE, maskno), _notify(NULL)
{ {}
}
bool TSpreadsheet::on_key(KEY k) bool TSpreadsheet::on_key(KEY k)
{ {
@ -747,24 +707,18 @@ case K_ESC:
mask().send_key(k, 0); mask().send_key(k, 0);
return TRUE; return TRUE;
case K_ENTER: // Selezione riga per editing case K_ENTER: // Selezione riga per editing
if (items() < 1) k = K_INS; // Se vuoto crea riga da editare if (items() < 1) k = K_INS; // Se vuoto crea riga da editare
case K_INS: case K_INS:
case 'A': // Aggiunge dopo case 'A': // Aggiunge dopo
case 'I': // Aggiunge prima case 'I': // Aggiunge prima
{ {
int n = (int)selected(); int n = (int)selected();
if (k != K_ENTER) if (k != K_ENTER)
{ {
if (k == K_INS) n = items (); if (k == K_INS) n = items(); else // Aggiunge alla fine
else // Aggiunge alla fine
if (k == 'A') n++; if (k == 'A') n++;
if (n < 0) n = 0; if (n < 0) n = 0; else
else
if (n > items()) n = items(); // Controlla range n if (n > items()) n = items(); // Controlla range n
if (notify(n, K_INS) == FALSE) // Chiede l'ok alla applicazione if (notify(n, K_INS) == FALSE) // Chiede l'ok alla applicazione
@ -801,6 +755,7 @@ TMask_field * TSpreadsheet ::field (short id) const
return &_mask.fld(pos); return &_mask.fld(pos);
} }
void TSpreadsheet::mask2str(int riga) void TSpreadsheet::mask2str(int riga)
{ {
TToken_string& r = row(riga); TToken_string& r = row(riga);
@ -816,6 +771,7 @@ void TSpreadsheet ::mask2str (int riga)
#endif #endif
} }
// Certified 50% // Certified 50%
void TSpreadsheet::enable_cell(int row, int column, bool on) void TSpreadsheet::enable_cell(int row, int column, bool on)
{ {
@ -845,11 +801,13 @@ void TSpreadsheet ::enable_cell (int row, int column, bool on)
} }
} }
void TSpreadsheet::enable_column(int col, bool on) void TSpreadsheet::enable_column(int col, bool on)
{ {
_column_disabled.set(col, !on); _column_disabled.set(col, !on);
} }
// Certified 99% // Certified 99%
bool TSpreadsheet::cell_disabled(int row, int column) const bool TSpreadsheet::cell_disabled(int row, int column) const
{ {
@ -858,6 +816,7 @@ bool TSpreadsheet ::cell_disabled (int row, int column) const
return (*ba)[column]; return (*ba)[column];
} }
// Certified 75% // Certified 75%
void TSpreadsheet::str2mask(int riga) void TSpreadsheet::str2mask(int riga)
{ {
@ -899,12 +858,14 @@ void TSpreadsheet ::str2mask (int riga)
_mask.set_caption(format("Riga %d", riga+1)); _mask.set_caption(format("Riga %d", riga+1));
} }
// Certified 100% // Certified 100%
bool TSpreadsheet::notify(int n, KEY k) bool TSpreadsheet::notify(int n, KEY k)
{ {
return _notify ? _notify(n, k) : TRUE; return _notify ? _notify(n, k) : TRUE;
} }
// Certified 99% // Certified 99%
KEY TSpreadsheet::edit(int n) KEY TSpreadsheet::edit(int n)
{ {
@ -914,8 +875,7 @@ KEY TSpreadsheet ::edit (int n)
if (k == K_ENTER) if (k == K_ENTER)
{ {
mask2str(n); mask2str(n);
} } else
else
if (k == K_DEL) if (k == K_DEL)
{ {
const bool ok = notify(n, K_DEL); // Notifica intenzione di cancellare const bool ok = notify(n, K_DEL); // Notifica intenzione di cancellare
@ -935,8 +895,7 @@ KEY TSpreadsheet ::edit (int n)
// Certified 100% // Certified 100%
TSheet_field::TSheet_field(TMask* m) TSheet_field::TSheet_field(TMask* m)
: TMask_field(m), _sheet(NULL) : TMask_field(m), _sheet(NULL)
{ {}
}
// Certified 100% // Certified 100%
word TSheet_field::class_id() const word TSheet_field::class_id() const
@ -964,6 +923,7 @@ void TSheet_field ::parse_head (TScanner & scanner)
if (_size == 0) _size = -1; if (_size == 0) _size = -1;
} }
// Certified 100% // Certified 100%
bool TSheet_field::parse_item(TScanner& scanner) bool TSheet_field::parse_item(TScanner& scanner)
{ {
@ -987,12 +947,14 @@ void TSheet_field ::create (WINDOW parent)
show_window(_win, showed()); show_window(_win, showed());
} }
// Certified 100% // Certified 100%
TArray& TSheet_field::rows_array() const TArray& TSheet_field::rows_array() const
{ {
return _sheet->rows_array(); return _sheet->rows_array();
} }
// Certified 100% // Certified 100%
// Ritorna l'indice della prima riga vuota dello sheet // Ritorna l'indice della prima riga vuota dello sheet
int TSheet_field::first_empty() const int TSheet_field::first_empty() const
@ -1004,6 +966,7 @@ int TSheet_field ::first_empty ()const
return n; return n;
} }
TToken_string& TSheet_field::row(int n) TToken_string& TSheet_field::row(int n)
{ {
const int max = _sheet->items(); const int max = _sheet->items();
@ -1015,6 +978,7 @@ TToken_string & TSheet_field ::row (int n)
return _sheet->row(n); return _sheet->row(n);
} }
void TSheet_field::force_update(int r) void TSheet_field::force_update(int r)
{ {
#if XVTWS == WMWS #if XVTWS == WMWS
@ -1024,6 +988,7 @@ void TSheet_field ::force_update (int r)
#endif #endif
} }
void TSheet_field::set_window_data(const char*) void TSheet_field::set_window_data(const char*)
{ {
_sheet->set_dirty(FALSE); _sheet->set_dirty(FALSE);
@ -1035,31 +1000,37 @@ void TSheet_field ::set_field_data (const char *)
set_dirty(_sheet->dirty()); set_dirty(_sheet->dirty());
} }
int TSheet_field::items() const int TSheet_field::items() const
{ {
return (int)_sheet->items(); return (int)_sheet->items();
} }
void TSheet_field::set_notify(SPREADSHEET_NOTIFY n) void TSheet_field::set_notify(SPREADSHEET_NOTIFY n)
{ {
_sheet->set_notify(n); _sheet->set_notify(n);
} }
void TSheet_field::enable_column(int column, bool on) void TSheet_field::enable_column(int column, bool on)
{ {
_sheet->enable_column(column, on); _sheet->enable_column(column, on);
} }
void TSheet_field::enable_cell(int row, int column, bool on) void TSheet_field::enable_cell(int row, int column, bool on)
{ {
_sheet->enable_cell(row, column, on); _sheet->enable_cell(row, column, on);
} }
TMask& TSheet_field::sheet_mask() const TMask& TSheet_field::sheet_mask() const
{ {
return _sheet->mask(); return _sheet->mask();
} }
bool TSheet_field::on_key(KEY k) bool TSheet_field::on_key(KEY k)
{ {
if (k == K_TAB) if (k == K_TAB)