Attivati anche gli sheet vuoti

Aggiunto supporto per i variable sheet


git-svn-id: svn://10.65.10.50/trunk@3678 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
alex 1996-09-26 15:32:58 +00:00
parent 21e521fb82
commit a762a75a50

View File

@ -94,11 +94,16 @@ protected:
// @cmember Ritorna il campo della maschera corrispondente alla cella dello
// spreadsheet indicata da <p pos>
TOperable_field* col2field(int pos) const;
// @cmember Controlla se esiste il campo della maschera corrispondente alla cella dello
// spreadsheet indicata da <p pos>
TOperable_field* test_field(int pos) const;
// @cmember Ritorna il campo della maschera corrispondente alla cella dello
// spreadsheet indicata da <p cell> (chiama <mf TMask::col2field>)
TOperable_field* cell2field(const XI_OBJ* cell) const;
// @cmember Ritorna la posizione della colonna con identificatore <p cid>
int cid2col(short cid) const;
// @cmember Ritorna la colonna logica con identificatore <p cid>
int cid2index(short cid) const;
// @cmember Ritorna la colonna corrispondente al campo <p f> della maschera
int field2col(const TOperable_field* f) const;
@ -136,6 +141,8 @@ public:
void update(int row);
// @cmember Ritorna la disabilitazione della colonna <p col>
bool column_disabled(int col) const { return _column_disabled[col]; }
// @cmember Ritorna l' abilitazione della colonna <p col>
bool column_enabled(int col) const { return !column_disabled(col); }
// @cmember Ritorna il contenuto della riga <p n>-esima
TToken_string& row(int n)
@ -280,13 +287,13 @@ TSpreadsheet::TSpreadsheet(
{
CHECKD(i < MAX_COL, "Tu meni calumns in scit: ", i);
const int cid = FIRST_FIELD+i; // Column & Field ID
const TOperable_field* f = field(cid); // Field on mask
CHECKD(f, "The spreadsheet mask needs ALSO field ", cid);
const int cid = FIRST_FIELD+i; // Column & Field ID
const TOperable_field & f = (TOperable_field &) _mask.field(cid); // Field on mask
// CHECKD(f, "The spreadsheet mask needs ALSO field ", cid);
TString testa(h);
const int at = testa.find('@');
const int m = f->size(); // Memory width
const int m = f.size(); // Memory width
int v = m; // Video width
if (at >= 0)
{
@ -298,11 +305,11 @@ TSpreadsheet::TSpreadsheet(
f_width += v+1;
}
testa.cut(at);
v = max(at, v+(f->has_query_button() ? 1 : 0));
v = max(at, v+(f.has_query_button() ? 1 : 0));
}
else
{
v = max(testa.len(), m+(f->has_query_button() ? 1 : 0));
v = max(testa.len(), m+(f.has_query_button() ? 1 : 0));
}
if (v > 69)
v = 69;
@ -376,8 +383,8 @@ TSpreadsheet::TSpreadsheet(
{
const TString testo(h);
const int cid = FIRST_FIELD+i; // Column & Field ID
const TOperable_field* f = field(cid); // Field on mask
const int acqua = f->class_id();
const TOperable_field & f = (const TOperable_field &)_mask.field(cid); // Field on mask
const int acqua = f.class_id();
long flags = XI_ATR_EDITMENU | XI_ATR_AUTOSCROLL | XI_ATR_FOCUSBORDER;
@ -387,7 +394,7 @@ TSpreadsheet::TSpreadsheet(
switch (acqua)
{
case CLASS_EDIT_FIELD:
if (f->right_justified())
if (f.right_justified())
flags |= XI_ATR_RJUST;
break;
case CLASS_REAL_FIELD:
@ -396,7 +403,7 @@ TSpreadsheet::TSpreadsheet(
default:
break;
}
if (f->active()) flags |= XI_ATR_ENABLED;
if (f.active()) flags |= XI_ATR_ENABLED;
else _column_disabled.set(i);
coldef = xi_add_column_def(listdef, cid, flags, cid,
@ -424,7 +431,7 @@ TSpreadsheet::~TSpreadsheet()
TMask& TSpreadsheet::sheet_mask() const
{
return ((TSpreadsheet*)this)->_mask;
return ((TSpreadsheet*)this)->_mask;
}
@ -461,9 +468,8 @@ int TSpreadsheet::rec2row(int record)
return r;
}
// Retrieves the corresponding field of the mask from a spredsheet cell
TOperable_field* TSpreadsheet::col2field(int pos) const
TOperable_field* TSpreadsheet::test_field(int pos) const
{
int num;
XI_OBJ** column = xi_get_member_list(_obj, &num);
@ -476,7 +482,14 @@ TOperable_field* TSpreadsheet::col2field(int pos) const
if (f == NULL) break; // Search failed
good = f; // We've found a field with the proper ID ...
if (f->active()) break; // ... and it's active: end of search
}
}
return good;
}
// Retrieves the corresponding field of the mask from a spredsheet cell
TOperable_field* TSpreadsheet::col2field(int pos) const
{
TOperable_field* good = test_field(pos);
CHECKD(good, "Can't find field corresponding to column ", pos);
return good;
@ -496,11 +509,11 @@ TOperable_field* TSpreadsheet::cell2field(const XI_OBJ* cell) const
}
int TSpreadsheet::cid2col(short cid) const
{
{
CHECKD(cid >= FIRST_FIELD, "Bad column id ", cid);
int num;
XI_OBJ** column = xi_get_member_list(_obj, &num);
for (int c = num-1; c > 1; c--)
for (int c = num-1; c > 0; c--)
{
if (column[c]->cid == cid)
return c;
@ -508,9 +521,15 @@ int TSpreadsheet::cid2col(short cid) const
return 0;
}
int TSpreadsheet::cid2index(short cid) const
{
CHECKD(cid >= FIRST_FIELD, "Bad column id ", cid);
return (cid % 100) - 1;
}
int TSpreadsheet::field2col(const TOperable_field* f) const
{
const short cid = FIRST_FIELD + (f->dlg() % 100) - 1;
const short cid = FIRST_FIELD + cid2index(f->dlg());
return cid2col(cid);
}
@ -603,7 +622,6 @@ void TSpreadsheet::set_focus_cell(int riga, int colonna)
xi_set_focus(&cell);
_edit_field = col2field(_cur_col = colonna);
if (rec != _cur_rec)
{
_cur_rec = rec;
@ -611,6 +629,7 @@ void TSpreadsheet::set_focus_cell(int riga, int colonna)
/* Guy! str2mask(_cur_rec); */
_row_dirty = FALSE;
}
_edit_field = col2field(_cur_col = colonna); // qui
}
}
@ -639,13 +658,14 @@ int TSpreadsheet::insert(
const bool ok = notify(r, K_INS);
if (ok)
{
{
_disabled.insert(NULL, r);
owner().post_insert(r);
xi_insert_row(_obj, INT_MAX);
xi_cell_request(_obj);
// Notifica che l'inserimento è terminato
// Notifica che l'inserimento h terminato
notify(r, K_CTRL + K_INS);
xi_cell_request(_obj);
}
else
{
@ -709,7 +729,6 @@ void TSpreadsheet::update(
{
if (rec < 0)
{
// xi_cell_request(_obj); // Update cell values
int num = 0;
const long* handle = xi_get_list_info(_obj, &num);
@ -762,10 +781,14 @@ const char* TSpreadsheet::copy_cell2field(XI_OBJ* cell)
}
else
txt = xi_get_text(cell, NULL, -1);
if (_edit_field->is_editable())
{
if (_edit_field->class_id() == CLASS_ZOOM_FIELD)
_edit_field->set(row(_cur_row).get(_cur_col - 1));
const char* val = _edit_field->is_kind_of(CLASS_LIST_FIELD) ? txt :
(const char*)((TEditable_field*)_edit_field)->win2raw(txt);
_edit_field->set(val);
_edit_field->set_dirty(); // Get it dirty!
}
@ -842,8 +865,11 @@ bool TSpreadsheet::event_handler(XI_OBJ* itf, XI_EVENT *xiev)
if (rec < items())
{
const int col = cid - FIRST_FIELD;
const int curr = _cur_rec;
_cur_rec = rec;
const TOperable_field* f = field(cid);
if (f->is_editable())
_cur_rec = curr;
if (f)
{
const TEditable_field* e = (const TEditable_field*)f;
src = row(rec).get(col); // Set value for cell
@ -867,6 +893,8 @@ bool TSpreadsheet::event_handler(XI_OBJ* itf, XI_EVENT *xiev)
xiev->v.cell_request.button_on_focus = TRUE;
}
}
else
xiev->v.cell_request.back_color = DISABLED_BACK_COLOR;
}
}
else
@ -937,13 +965,14 @@ bool TSpreadsheet::event_handler(XI_OBJ* itf, XI_EVENT *xiev)
const int button_pos = sheet_mask().id2pos(FIRST_FIELD-1);
if (button_pos >= 0)
{
TMask_field& button = sheet_mask().fld(button_pos);
{
TMask & sm = owner().sheet_mask();
TMask_field& button = sm.fld(button_pos);
if (button.active())
{
str2mask(_cur_rec);
button.on_hit();
if (sheet_mask().dirty())
if (sm.dirty())
{
notify_change();
mask2str(_cur_rec);
@ -1040,7 +1069,7 @@ bool TSpreadsheet::event_handler(XI_OBJ* itf, XI_EVENT *xiev)
_check_enabled = FALSE; // Avoid recursion!
if (_row_dirty && active())
{
bool ok = sheet_mask().check_fields();
bool ok = owner().sheet_mask().check_fields();
if (ok)
{
mask2str(_cur_rec); // Update sheet with mask contents
@ -1065,20 +1094,23 @@ bool TSpreadsheet::event_handler(XI_OBJ* itf, XI_EVENT *xiev)
case XIE_ON_CELL:
if (_check_enabled)
{
TOperable_field* f = cell2field(xiev->v.xi_obj);
const int logical_column = (f->dlg()-FIRST_FIELD) % 100;
const int physical_column = xiev->v.xi_obj->v.cell.column;
if (cell_disabled(_cur_rec, logical_column)) // If the cell is disabled ...
TOperable_field* f = test_field(physical_column);
bool disabled = TRUE;
if (f)
{
const int logical_column = (f->dlg()-FIRST_FIELD) % 100;
disabled = cell_disabled(_cur_rec, logical_column); // If the cell is disabled ...
}
if (disabled)
{
const int dir = _lastab == K_TAB ? +1 : -1;
const int nex = find_enabled_column(_cur_rec, physical_column, dir);
if (nex > 0) // If at least one enabled cell exists
{
set_focus_cell(_cur_row, nex);
}
else
refused = TRUE;
}
}
else
{
_edit_field = f;
@ -1110,7 +1142,7 @@ bool TSpreadsheet::event_handler(XI_OBJ* itf, XI_EVENT *xiev)
case XIE_CLEANUP:
break;
case XIE_CHAR_CELL:
if (_edit_field)
if (_edit_field)
{
const KEY k = xiev_to_key(xiev);
switch(k)
@ -1151,7 +1183,7 @@ bool TSpreadsheet::event_handler(XI_OBJ* itf, XI_EVENT *xiev)
if (!ok && k == K_F9) // Ricerca non completata?
{
_edit_field = &sheet_mask().focus_field();
_edit_field = &owner().sheet_mask().focus_field();
const int col = field2col(_edit_field);
if (col != _cur_col) // Ricerca alternativa
@ -1427,7 +1459,7 @@ XI_OBJ* TSpreadsheet::find_column(
col += FIRST_FIELD;
else
if (col >= FIRST_FIELD+100) // Riportalo nel range 101 - 199
col = FIRST_FIELD + (col % 100) -1;
col = FIRST_FIELD + cid2index(col);
int num;
XI_OBJ** columns = xi_get_member_list(_obj, &num);
@ -1456,9 +1488,10 @@ TMask& TSpreadsheet::mask() const
// Ritorna il campo con l'identificatore dato della maschera dello sheet
TOperable_field* TSpreadsheet::field(short id) const
{
const int pos = sheet_mask().id2pos(id);
return pos < 0 ? NULL : (TOperable_field*)&sheet_mask().fld(pos);
{
const TMask & sm = owner().sheet_mask();
const int pos = sm.id2pos(id);
return pos < 0 ? NULL : (TOperable_field*)&sm.fld(pos);
}
@ -1490,6 +1523,8 @@ void TSpreadsheet::enable_cell(
// @flag TRUE | La cella viene abilitata (default)
// @flag FALSE| La cella viene disabilitata
{
if (column >= FIRST_FIELD)
column = cid2index(column);
TBit_array* ba = (TBit_array*)_disabled.objptr(row);
if (ba == NULL)
{
@ -1525,7 +1560,8 @@ void TSpreadsheet::enable_column(
// @flag FALSE| Disabilita la colonna
{
if (col >= FIRST_FIELD)
col = cid2col(col);
col = cid2index(col);
const bool change = _column_disabled[col] == on;
_column_disabled.set(col, !on);
@ -1650,8 +1686,11 @@ bool TSpreadsheet::cell_disabled(int row, int column) const
void TSpreadsheet::str2mask(int riga)
{
if (riga == items())
{
sheet_mask().reset();
{
const int curr = _cur_rec;
_cur_rec = riga;
owner().sheet_mask().reset();
_cur_rec = curr;
mask2str(riga);
return;
}
@ -1714,7 +1753,8 @@ KEY TSpreadsheet::edit(int n)
// Certified 100%
TSheet_field::TSheet_field(TMask* m)
: TOperable_field(m), _append(TRUE)
{ }
{
}
// Certified 100%
word TSheet_field::class_id() const
@ -1733,7 +1773,9 @@ TSheet_field::~TSheet_field()
// Certified 100%
void TSheet_field::reset()
{
TSpreadsheet* s = (TSpreadsheet*)_ctl;
TSpreadsheet* s = (TSpreadsheet*)_ctl;
if (s->items())
s->select(0, FALSE);
s->destroy();
s->sheet_mask().reset();
set_dirty(); // Reset any error (dirty = 3)
@ -1781,6 +1823,11 @@ void TSheet_field::create(WINDOW parent)
_flags.enabled = TRUE; // Lo sheet e' sempre operabile anche se non editabile
disable();
}
const TMask & s = sheet_mask();
for (short id = FIRST_FIELD; ; id++)
if (s.id2pos(id) < 0) break;
_last_column_id = id - 1;
}
@ -1849,8 +1896,9 @@ int TSheet_field::items() const
int TSheet_field::selected() const
{
TSpreadsheet* s = (TSpreadsheet*)_ctl;
return (int)s->selected();
TSpreadsheet* s = (TSpreadsheet*)_ctl;
return s != NULL ?(int)s->selected() : -1;
}
void TSheet_field::set_notify(SPREADSHEET_NOTIFY n)
@ -1886,7 +1934,14 @@ void TSheet_field::enable(bool on)
bool TSheet_field::enabled() const
{
return items() > 0;
// return items() > 0;
return TMask_field::enabled();
}
int TSheet_field::cid2index(short cid) const
{
TSpreadsheet* s = (TSpreadsheet*)_ctl;
return s->cid2index(cid);
}
void TSheet_field::enable_column(int column, bool on)
@ -1902,6 +1957,18 @@ void TSheet_field::enable_cell(int row, int column, bool on)
s->enable_cell(row, column, on);
}
bool TSheet_field::column_enabled(int column) const
{
TSpreadsheet* s = (TSpreadsheet*)_ctl;
return s->column_enabled(column);
}
bool TSheet_field::column_disabled(int column) const
{
TSpreadsheet* s = (TSpreadsheet*)_ctl;
return s->column_disabled(column);
}
bool TSheet_field::cell_disabled(int row, int column) const
{
TSpreadsheet* s = (TSpreadsheet*)_ctl;
@ -1966,9 +2033,12 @@ bool TSheet_field::on_hit()
if (!mask().is_running()) // Inizializzazione maschera
{
force_update();
mask().notify_focus_field(dlg()); // Fa' credere alla maschera che ha il focus ...
select(0); // ... cosi' la set_focus_cell funziona bene
if (items() > 0)
{
mask().notify_focus_field(dlg()); // Fa' credere alla maschera che ha il focus ...
select(0); // ... cosi' la set_focus_cell funziona bene
}
set_dirty(FALSE);
}
@ -2056,43 +2126,44 @@ void TSheet_field::exchange(bool show_value, const real& nuo)
// Ricopia i campi della maschera nel record dato
void TSheet_field::mask2row(int n, TToken_string & rec)
{
const TMask& m = TSheet_field::sheet_mask();
const TMask& m = sheet_mask();
rec.cut(0);
const TSpreadsheet& s = (const TSpreadsheet&)*_ctl;
for (short id = FIRST_FIELD; ; id++)
for (short id = FIRST_FIELD; id <= _last_column_id ; id++)
{
int pos = m.id2pos(id);
if (pos < 0) break;
const int firstpos = pos;
for(int dlg = id; pos >= 0; pos = m.id2pos(dlg += 100))
{
const TMask_field& f = m.fld(pos);
if (f.shown() || f.ghost())
{
rec.add(f.get());
if (s.active())
{
const int col = id-FIRST_FIELD;
if (!s.column_disabled(col))
if (pos >= 0)
{
for(int dlg = id; pos >= 0; pos = m.id2pos(dlg += 100))
{
const TMask_field& f = m.fld(pos);
if (f.shown() || f.ghost())
{
rec.add(f.get());
if (active() && s.active())
{
const bool on = f.enabled();
enable_cell(n, col, on);
const int col = cid2index(id);
if (!s.column_disabled(col))
{
const bool on = f.enabled();
enable_cell(n, col, on);
}
}
break;
}
break;
}
}
if (pos < 0)
{
#ifdef DBG
if (s.cid2col(id) > 0)
yesnofatal_box("Mask2str: Non e' visibile il campo %d", dlg);
if (pos < 0 && s.cid2col(id) > 0)
yesnofatal_box("Mask2row: Non e' visibile il campo %d", id);
#endif
rec.add(" ");
}
if (pos < 0)
rec.add(firstpos >= 0 ? m.fld(firstpos).get() : " ");
}
}
@ -2102,7 +2173,7 @@ void TSheet_field::row2mask(int n, TToken_string & r)
{
TString val(80);
TMask& m = TSheet_field::sheet_mask();
TMask& m = sheet_mask();
const int campi = m.fields();
const TSpreadsheet& s = (const TSpreadsheet&)*_ctl;
@ -2110,9 +2181,11 @@ void TSheet_field::row2mask(int n, TToken_string & r)
{
TMask_field& f = m.fld(i);
const short id = f.dlg();
if (id >= FIRST_FIELD)
if (id >= FIRST_FIELD && id <= _last_column_id)
{
const int index = (id % 100)-1;
const int index = cid2index(id);
val = r.get(index);
f.set(val);
const bool on = s.active() && !cell_disabled(n, index);
@ -2125,6 +2198,7 @@ void TSheet_field::row2mask(int n, TToken_string & r)
{
TMask_field& f = m.fld(i);
const short id = f.dlg();
if (id >= FIRST_FIELD &&
!f.is_kind_of(CLASS_BUTTON_FIELD) &&
(f.active() || f.ghost()))
@ -2150,4 +2224,3 @@ void TSheet_field::row2mask(int n, TToken_string & r)
val.format("Riga %d", n+1);
m.set_caption(val);
}