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