Migliorata
git-svn-id: svn://10.65.10.50/trunk@3935 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
bf07ca51f3
commit
8f381b6ff9
396
cg/cg3600.cpp
396
cg/cg3600.cpp
@ -969,6 +969,9 @@ public:
|
||||
void set_back_color(COLOR col);
|
||||
void set_fore_color(COLOR col);
|
||||
void set_colors(COLOR back, COLOR fore);
|
||||
|
||||
short get_column() const;
|
||||
short get_size() const;
|
||||
|
||||
TGrid_cell(XI_EVENT* xiev) : _xiev(xiev) { }
|
||||
virtual ~TGrid_cell() { }
|
||||
@ -988,11 +991,12 @@ public:
|
||||
virtual long items() const;
|
||||
virtual void cell_request(long rec, short id, TGrid_cell& cell);
|
||||
|
||||
virtual bool on_rec(long rec) { return TRUE; }
|
||||
virtual bool off_rec(long rec) { return TRUE; }
|
||||
virtual bool on_record(long rec) { return TRUE; }
|
||||
virtual bool off_record(long rec) { return TRUE; }
|
||||
virtual bool on_resize_column(short cid, int new_size) { return TRUE; }
|
||||
virtual void on_dbl_cell(long rec, short id) { }
|
||||
virtual void on_button() { }
|
||||
virtual void on_grid_button() { }
|
||||
virtual void on_record_button(long rec) { }
|
||||
virtual void on_cell_button(long rec, short cid) { }
|
||||
|
||||
long selected() const;
|
||||
@ -1020,14 +1024,22 @@ protected: // TControl
|
||||
//@cmember Gestisce gli eventi delle celle
|
||||
virtual bool event_handler(XI_OBJ* itf, XI_EVENT* xiev);
|
||||
|
||||
//@cmember Chiama gli handlers opportuni per verificare il cambio record
|
||||
bool try_to_select(long rec) const;
|
||||
|
||||
protected:
|
||||
|
||||
//@cmember Ritorna il numero totale di righe
|
||||
long items() const { return _grid->items(); }
|
||||
|
||||
|
||||
//@cmember Converte un record nella eventuale riga corrispondente a video
|
||||
int rec2row(long rec) const;
|
||||
|
||||
//@cmember Converte una riga a video nell'eventuale record corrispondente
|
||||
long row2rec(int row) const;
|
||||
|
||||
XI_OBJ* find_column(int col) const;
|
||||
//@cmember Converte un indice di colonna nel corrispondente id
|
||||
short int col2cid(int pos) const;
|
||||
|
||||
void update_selection(XI_EVENT* xiev);
|
||||
|
||||
public:
|
||||
@ -1185,7 +1197,6 @@ TGrid_control::TGrid_control(
|
||||
XI_COLUMN_DEF* cd = coldef->v.column;
|
||||
cd->heading_platform = TRUE;
|
||||
cd->column_platform = TRUE;
|
||||
cd->size_rows = multi_line;
|
||||
|
||||
for (h = new_header.get(0), i = 0; h; h = new_header.get(), i++)
|
||||
{
|
||||
@ -1202,10 +1213,7 @@ TGrid_control::TGrid_control(
|
||||
cd->heading_platform = TRUE;
|
||||
cd->center_heading = TRUE;
|
||||
if (multi_line)
|
||||
{
|
||||
cd->size_rows = TRUE;
|
||||
cd->wrap_text = _type[i] != 'R';
|
||||
}
|
||||
}
|
||||
|
||||
RCT rd; xi_get_def_rect(listdef, &rd);
|
||||
@ -1220,12 +1228,12 @@ TGrid_control::TGrid_control(
|
||||
update_tab_cid();
|
||||
}
|
||||
|
||||
// Converts a row number in the correspondig record number
|
||||
// Converts a record number in the correspondig row number
|
||||
int TGrid_control::rec2row(long record) const
|
||||
{
|
||||
int rows;
|
||||
const long* rec = xi_get_list_info(_obj, &rows);
|
||||
int r = int(record - rec[0]);
|
||||
int r = rows > 0 ? int(record - rec[0]) : -1;
|
||||
if (r < 0 || r >= rows)
|
||||
r = -1;
|
||||
return r;
|
||||
@ -1308,91 +1316,109 @@ void TGrid_control::update(long n)
|
||||
}
|
||||
|
||||
bool TGrid_control::select(long rec)
|
||||
{
|
||||
if (_cur_rec >= 0 && _cur_rec < items())
|
||||
{
|
||||
bool ok, sel;
|
||||
if (rec >= 0)
|
||||
{
|
||||
if (!_grid->off_rec(_cur_rec))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
const bool ok = rec >= 0 && rec < items();
|
||||
if (ok)
|
||||
{
|
||||
if (!_grid->on_rec(rec))
|
||||
return FALSE;
|
||||
|
||||
int first, last;
|
||||
xi_get_visible_rows(_obj, &first, &last);
|
||||
// Controllo che la nuova riga sia completamente visibile
|
||||
int r = rec2row(rec);
|
||||
if (r >= first && r <= last)
|
||||
{
|
||||
if (_read_only)
|
||||
{
|
||||
XI_OBJ riga; XI_MAKE_ROW(&riga, _obj, r);
|
||||
long attr = xi_get_attrib(&riga);
|
||||
attr |= XI_ATR_SELECTED;
|
||||
xi_set_attrib(&riga, attr);
|
||||
xi_dequeue();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
long attr = XI_ATR_ENABLED;
|
||||
if (_read_only)
|
||||
attr |= XI_ATR_SELECTED;
|
||||
xi_scroll_rec(_obj, rec, NORMAL_COLOR, attr, 0);
|
||||
}
|
||||
ok = try_to_select(rec);
|
||||
sel = ok;
|
||||
}
|
||||
else
|
||||
{
|
||||
ok = _cur_rec >= 0 && _cur_rec < items() && _grid->off_record(_cur_rec);
|
||||
sel = FALSE;
|
||||
}
|
||||
|
||||
const int r = rec2row(_cur_rec);
|
||||
if (r >= 0)
|
||||
if (ok)
|
||||
{
|
||||
if (_read_only)
|
||||
{
|
||||
XI_OBJ riga; XI_MAKE_ROW(&riga, _obj, r);
|
||||
long attr = xi_get_attrib(&riga);
|
||||
attr &= ~XI_ATR_SELECTED;
|
||||
xi_set_attrib(&riga, attr);
|
||||
}
|
||||
else
|
||||
{
|
||||
XI_OBJ cella; XI_MAKE_CELL(&cella, _obj, r, 1);
|
||||
xi_set_focus(&cella);
|
||||
}
|
||||
xi_dequeue();
|
||||
}
|
||||
if (sel)
|
||||
{
|
||||
int first, last;
|
||||
xi_get_visible_rows(_obj, &first, &last);
|
||||
// Controllo che la nuova riga sia completamente visibile
|
||||
const int next_row = rec2row(rec);
|
||||
if (next_row >= first && next_row <= last)
|
||||
{
|
||||
if (_read_only)
|
||||
{
|
||||
XI_OBJ riga; XI_MAKE_ROW(&riga, _obj, next_row);
|
||||
long attr = xi_get_attrib(&riga);
|
||||
attr |= XI_ATR_SELECTED;
|
||||
xi_set_attrib(&riga, attr);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
long attr = XI_ATR_ENABLED;
|
||||
if (_read_only)
|
||||
attr |= XI_ATR_SELECTED;
|
||||
xi_scroll_rec(_obj, rec, NORMAL_COLOR, attr, 0);
|
||||
}
|
||||
|
||||
if (!_read_only)
|
||||
{
|
||||
const int next_row = rec2row(rec);
|
||||
XI_OBJ cella; XI_MAKE_CELL(&cella, _obj, next_row, 1);
|
||||
xi_set_focus(&cella);
|
||||
}
|
||||
} // end if (sel)
|
||||
|
||||
// Deseleziona record precedente se ancora visibile
|
||||
if (_read_only)
|
||||
{
|
||||
const int cur_row = rec2row(_cur_rec);
|
||||
if (cur_row >= 0)
|
||||
{
|
||||
XI_OBJ riga; XI_MAKE_ROW(&riga, _obj, cur_row);
|
||||
long attr = xi_get_attrib(&riga);
|
||||
attr &= ~XI_ATR_SELECTED;
|
||||
xi_set_attrib(&riga, attr);
|
||||
}
|
||||
xi_dequeue();
|
||||
}
|
||||
|
||||
if (rec < 0 || rec >= items())
|
||||
rec = -1;
|
||||
_cur_rec = rec;
|
||||
} // end if (ok)
|
||||
|
||||
if (rec < 0 || rec >= items())
|
||||
rec = -1;
|
||||
_cur_rec = rec;
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
XI_OBJ* TGrid_control::find_column(
|
||||
int col) const // @parm Indice o identificatore colonna
|
||||
{
|
||||
CHECKD(col >= 0, "Bad column ", col);
|
||||
if (col < FIRST_FIELD) // Se e' un indice trasformalo in identificatore
|
||||
col += FIRST_FIELD + 1000;
|
||||
|
||||
short TGrid_control::col2cid(int pos) const
|
||||
{
|
||||
int num;
|
||||
XI_OBJ** columns = xi_get_member_list(_obj, &num);
|
||||
for (int c = num-1; c >= 0; c--)
|
||||
{
|
||||
if (columns[c]->cid == col)
|
||||
break;
|
||||
}
|
||||
return c >= 0 ? columns[c] : NULL;
|
||||
XI_OBJ** column = xi_get_member_list(_obj, &num);
|
||||
CHECKD(pos >= 0 && pos < num, "Bad column ", pos);
|
||||
const short cid = column[pos]->cid - 1000;
|
||||
return cid;
|
||||
}
|
||||
|
||||
bool TGrid_control::try_to_select(long rec) const
|
||||
{
|
||||
bool ok = rec >= 0 && rec < items();
|
||||
if (ok && rec != _cur_rec)
|
||||
{
|
||||
if (_cur_rec >= 0 && _cur_rec < items())
|
||||
ok = _grid->off_record(_cur_rec);
|
||||
if (ok)
|
||||
ok = _grid->on_record(rec);
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
void TGrid_control::update_selection(XI_EVENT* xiev)
|
||||
{
|
||||
if (xiev->v.rec_request.data_rec == _cur_rec)
|
||||
xiev->v.rec_request.attrib |= XI_ATR_SELECTED;
|
||||
const bool is_curr = xiev->v.rec_request.data_rec == _cur_rec;
|
||||
if (_read_only)
|
||||
{
|
||||
if (is_curr)
|
||||
xiev->v.rec_request.attrib |= XI_ATR_SELECTED;
|
||||
else
|
||||
xiev->v.rec_request.attrib &= ~XI_ATR_SELECTED;
|
||||
}
|
||||
else
|
||||
xiev->v.rec_request.attrib &= ~XI_ATR_SELECTED;
|
||||
xiev->v.rec_request.has_focus = is_curr;
|
||||
}
|
||||
|
||||
// Certified 75%
|
||||
@ -1438,7 +1464,7 @@ bool TGrid_control::event_handler(XI_OBJ* itf, XI_EVENT *xiev)
|
||||
{
|
||||
const long rec = xiev->v.get_percent.record;
|
||||
long n = items(); if (n <= 0) n = 1;
|
||||
xiev->v.get_percent.percent = int(rec * 100L / n);
|
||||
xiev->v.get_percent.percent = short(rec * 100L / n);
|
||||
}
|
||||
break;
|
||||
case XIE_COL_MOVE:
|
||||
@ -1449,66 +1475,65 @@ bool TGrid_control::event_handler(XI_OBJ* itf, XI_EVENT *xiev)
|
||||
break;
|
||||
case XIE_COL_SIZE:
|
||||
{
|
||||
int num;
|
||||
XI_OBJ** column = xi_get_member_list(xiev->v.column.list, &num);
|
||||
const short cid = column[xiev->v.column.col_nbr]->cid - 1000;
|
||||
const short cid = col2cid(xiev->v.column.col_nbr);
|
||||
refused = !_grid->on_resize_column(cid, xiev->v.column.new_col_width);
|
||||
}
|
||||
break;
|
||||
case XIE_ROW_SIZE:
|
||||
refused = xiev->v.row_size.new_row_height < XI_FU_MULTIPLE;
|
||||
break;
|
||||
case XIE_SELECT:
|
||||
if (_read_only)
|
||||
{
|
||||
if (xiev->v.select.xi_obj->type == XIT_ROW && xiev->v.select.selected)
|
||||
if (xiev->v.select.xi_obj->type == XIT_ROW) // Considero solo le righe
|
||||
{
|
||||
if (xiev->v.select.selected) // Sto selezionando
|
||||
{
|
||||
const long rec = row2rec(xiev->v.select.xi_obj->v.row_data.row);
|
||||
if (rec >= 0 && _grid->on_rec(rec))
|
||||
_cur_rec = rec;
|
||||
if (try_to_select(rec))
|
||||
{
|
||||
if (xiev->v.select.column == 0)
|
||||
{
|
||||
_cur_rec = rec; // Assegno subito il record corrente
|
||||
_grid->on_record_button(rec);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_read_only && rec == _cur_rec)
|
||||
{
|
||||
const short cid = col2cid(xiev->v.select.column);
|
||||
_grid->on_dbl_cell(rec, cid);
|
||||
}
|
||||
_cur_rec = rec; // Assegno solo ora il record corrente
|
||||
}
|
||||
}
|
||||
else
|
||||
refused = TRUE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
const long rec = row2rec(xiev->v.select.xi_obj->v.row_data.row);
|
||||
if (rec >= 0 && rec < items())
|
||||
_grid->on_cell_button(rec, FIRST_FIELD-1);
|
||||
refused = TRUE;
|
||||
}
|
||||
break;
|
||||
case XIE_CELL_REQUEST:
|
||||
{
|
||||
const long& rec = xiev->v.cell_request.rec;
|
||||
if (rec < 0 || rec >= items())
|
||||
if (rec >= 0 && rec < items())
|
||||
{
|
||||
refused = TRUE;
|
||||
break;
|
||||
TGrid_cell cell(xiev);
|
||||
const short cid = col2cid(cell.get_column());
|
||||
if (cid >= FIRST_FIELD)
|
||||
{
|
||||
_grid->cell_request(rec, cid, cell);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (cell.get_size() > 2)
|
||||
cell.set(rec);
|
||||
}
|
||||
}
|
||||
int columns;
|
||||
XI_OBJ** child = xi_get_member_list(xiev->v.cell_request.list, &columns);
|
||||
XI_OBJ* column = child[xiev->v.cell_request.col_nbr];
|
||||
const short cid = column->cid - 1000;
|
||||
|
||||
TGrid_cell cell(xiev);
|
||||
if (cid >= FIRST_FIELD)
|
||||
{
|
||||
_grid->cell_request(rec, cid, cell);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (xiev->v.cell_request.len > 2)
|
||||
cell.set(rec);
|
||||
}
|
||||
}
|
||||
refused = TRUE; // Ogni tanto succede
|
||||
}
|
||||
break;
|
||||
case XIE_ON_ROW:
|
||||
{
|
||||
{ // Qui ci passa solo se non e' _read_only
|
||||
const long rec = row2rec(xiev->v.xi_obj->v.row);
|
||||
if (rec >= 0)
|
||||
{
|
||||
if (_grid->on_rec(rec))
|
||||
if (_grid->on_record(rec))
|
||||
_cur_rec = rec;
|
||||
else
|
||||
refused = TRUE;
|
||||
@ -1521,40 +1546,34 @@ bool TGrid_control::event_handler(XI_OBJ* itf, XI_EVENT *xiev)
|
||||
}
|
||||
break;
|
||||
case XIE_OFF_ROW:
|
||||
// Qui ci passa solo se non e' _read_only
|
||||
if (_cur_rec >= 0 && _cur_rec < items())
|
||||
refused = !_grid->off_rec(_cur_rec);
|
||||
refused = !_grid->off_record(_cur_rec);
|
||||
break;
|
||||
case XIE_ON_CELL:
|
||||
break;
|
||||
case XIE_DBL_CELL:
|
||||
{
|
||||
const long rec = row2rec(xiev->v.xi_obj->v.cell.row);
|
||||
if (rec >= 0)
|
||||
if (try_to_select(rec))
|
||||
{
|
||||
int num;
|
||||
XI_OBJ** column = xi_get_member_list(_obj, &num);
|
||||
const short cid = column[xiev->v.xi_obj->v.cell.column]->cid - 1000;
|
||||
const short cid = col2cid(xiev->v.xi_obj->v.cell.column);
|
||||
_grid->on_dbl_cell(rec, cid);
|
||||
}
|
||||
else
|
||||
NFCHECK("You are clicking an invalid row: %d", xiev->v.xi_obj->v.cell.row);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case XIE_BUTTON:
|
||||
if (xiev->v.xi_obj->type == XIT_LIST)
|
||||
{
|
||||
_grid->on_button();
|
||||
_grid->on_grid_button();
|
||||
}
|
||||
else
|
||||
{
|
||||
const XI_CELL_DATA& cell = xiev->v.xi_obj->v.cell;
|
||||
const long rec = row2rec(cell.row);
|
||||
if (rec >= 0)
|
||||
if (try_to_select(rec))
|
||||
{
|
||||
int num;
|
||||
XI_OBJ** column = xi_get_member_list(_obj, &num);
|
||||
CHECKD(cell.column >= 0 && cell.column < num, "Invalid column:", cell.column);
|
||||
const short cid = column[cell.column]->cid - FIRST_FIELD - 1000;
|
||||
const short cid = col2cid(cell.column);
|
||||
_grid->on_cell_button(rec, cid);
|
||||
}
|
||||
else
|
||||
@ -1636,6 +1655,16 @@ void TGrid_cell::set_colors(COLOR back, COLOR fore)
|
||||
_xiev->v.cell_request.color = fore;
|
||||
}
|
||||
|
||||
short TGrid_cell::get_column() const
|
||||
{
|
||||
return _xiev->v.cell_request.col_nbr;
|
||||
}
|
||||
|
||||
short TGrid_cell::get_size() const
|
||||
{
|
||||
return _xiev->v.cell_request.len;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
// TGrid_field
|
||||
@ -1887,14 +1916,16 @@ class TMastrini_grid : public TGrid_field
|
||||
COLOR _con_back, _con_fore;
|
||||
|
||||
protected: // TGrid_field
|
||||
virtual bool on_rec(long rec);
|
||||
virtual bool on_record(long rec);
|
||||
virtual void cell_request(long rec, short id, TGrid_cell& cell);
|
||||
virtual void on_button();
|
||||
virtual bool on_resize_column(short cid, int new_size);
|
||||
virtual void on_grid_button();
|
||||
virtual bool on_resize_column(short id, int new_size);
|
||||
virtual void on_dbl_cell(long rec, short id);
|
||||
|
||||
void update_mask() const;
|
||||
|
||||
public:
|
||||
virtual void on_record_button(long rec);
|
||||
virtual long items() const { return _mastrino.items(); }
|
||||
|
||||
void destroy();
|
||||
@ -2062,32 +2093,30 @@ void TMastrini_grid::cell_request(long rec, short id, TGrid_cell& cell)
|
||||
cell.set_colors(_con_back, _con_fore);
|
||||
}
|
||||
|
||||
bool TMastrini_grid::on_rec(long rec)
|
||||
bool TMastrini_grid::on_record(long rec)
|
||||
{
|
||||
if (rec == selected())
|
||||
{
|
||||
if (_mastrino.expandable(rec))
|
||||
_mastrino.expand(rec);
|
||||
else
|
||||
_mastrino.collapse(rec);
|
||||
update();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_mastrino[rec].tipo() != riga_mastrino)
|
||||
rec = _mastrino.pred(rec, riga_mastrino);
|
||||
if (_mastrino[rec].tipo() != riga_mastrino)
|
||||
rec = _mastrino.pred(rec, riga_mastrino);
|
||||
|
||||
TRiga_mastrino& riga = _mastrino[rec];
|
||||
TMask& gm = mask();
|
||||
set_imp(gm.field(F_TOTRIG_SAL), riga.saldo());
|
||||
gm.set(F_TOTRIG_DAR, riga.dare());
|
||||
gm.set(F_TOTRIG_AVE, riga.avere());
|
||||
}
|
||||
TRiga_mastrino& riga = _mastrino[rec];
|
||||
TMask& gm = mask();
|
||||
set_imp(gm.field(F_TOTRIG_SAL), riga.saldo());
|
||||
gm.set(F_TOTRIG_DAR, riga.dare());
|
||||
gm.set(F_TOTRIG_AVE, riga.avere());
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void TMastrini_grid::on_button()
|
||||
void TMastrini_grid::on_dbl_cell(long rec, short id)
|
||||
{
|
||||
if (_mastrino.expandable(rec))
|
||||
_mastrino.expand(rec);
|
||||
else
|
||||
_mastrino.collapse(rec);
|
||||
update();
|
||||
}
|
||||
|
||||
void TMastrini_grid::on_grid_button()
|
||||
{
|
||||
begin_wait();
|
||||
|
||||
@ -2114,6 +2143,31 @@ void TMastrini_grid::on_button()
|
||||
end_wait();
|
||||
}
|
||||
|
||||
void TMastrini_grid::on_record_button(long rec)
|
||||
{
|
||||
begin_wait();
|
||||
|
||||
const TRectype& testata = _mastrino.testata(rec);
|
||||
TString text;
|
||||
text << "1|" << testata.get(MOV_NUMREG);
|
||||
|
||||
const char* const appname = "cg2 -0";
|
||||
TMessage pn(appname, MSG_LN, text);
|
||||
pn.send();
|
||||
|
||||
TExternal_app a(appname);
|
||||
a.run();
|
||||
|
||||
TMailbox mail;
|
||||
if (mail.next_s(MSG_LN) != NULL)
|
||||
{
|
||||
if (yesno_box("Si desidera aggiornare il mastrino?"))
|
||||
reread();
|
||||
}
|
||||
|
||||
end_wait();
|
||||
}
|
||||
|
||||
bool TMastrini_grid::on_resize_column(short cid, int new_size)
|
||||
{
|
||||
return cid == 103 || cid == 104;
|
||||
@ -2235,29 +2289,7 @@ bool TGrid_mask::link_handler(TMask_field& f, KEY k)
|
||||
TMastrini_grid& grid = gm.grid();
|
||||
const long rec = grid.selected();
|
||||
if (rec >= 0 && rec < grid.items())
|
||||
{
|
||||
begin_wait();
|
||||
|
||||
const TRectype& testata = grid.mastrino().testata(rec);
|
||||
TString text;
|
||||
text << "1|" << testata.get(MOV_NUMREG);
|
||||
|
||||
const char* const appname = "cg2 -0";
|
||||
TMessage pn(appname, MSG_LN, text);
|
||||
pn.send();
|
||||
|
||||
TExternal_app a(appname);
|
||||
a.run();
|
||||
|
||||
TMailbox mail;
|
||||
if (mail.next_s(MSG_LN) != NULL)
|
||||
{
|
||||
if (yesno_box("Si desidera aggiornare il mastrino?"))
|
||||
gm.grid().reread();
|
||||
}
|
||||
|
||||
end_wait();
|
||||
}
|
||||
grid.on_record_button(rec);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user