From b4703266c9a8e3547f863cc0b8f95a44e3e9573b Mon Sep 17 00:00:00 2001 From: guy Date: Fri, 3 Feb 1995 09:38:46 +0000 Subject: [PATCH] Corretta gestione annullamento di una riga degli sheet git-svn-id: svn://10.65.10.50/trunk@960 c028cbd2-c16b-5b4b-a496-9718f37d4682 --- include/applicat.cpp | 4 +- include/msksheet.cpp | 92 +++++++++++++++++++++++++++----------------- include/msksheet.h | 2 +- include/prassi.ver | 2 +- 4 files changed, 60 insertions(+), 40 deletions(-) diff --git a/include/applicat.cpp b/include/applicat.cpp index 7ef7f6cc3..e43e4fa3d 100755 --- a/include/applicat.cpp +++ b/include/applicat.cpp @@ -128,8 +128,8 @@ void TBanner::handler(WINDOW win, EVENT* ep) x = (r.right-r.left-w)>>1, y = r.bottom - CHARY; win_draw_text(win, x, y, t, -1); - r.left += 4; r.right -= 4; - r.top += 4; r.bottom -= 4; + r.left += 5; r.right -= 4; + r.top += 5; r.bottom -= 4; set_pen(COLOR_WHITE); win_draw_rect(win, &r); offset_rect(&r, -1, -1); set_pen(COLOR_BLACK); win_draw_rect(win, &r); diff --git a/include/msksheet.cpp b/include/msksheet.cpp index 3c6aec216..607bbc815 100755 --- a/include/msksheet.cpp +++ b/include/msksheet.cpp @@ -43,7 +43,8 @@ class TSpreadsheet : public TWindow TMask_field* _edit_field; // Current edit field int _cur_row, _cur_rec, _cur_col; // Current cell bool _row_dirty; // Current row changed - bool _check_enabled; // Perform OFF_ROW checks + bool _check_enabled; // Perform OFF_ROW and OFF_CELL checks + bool _update; // It's safe to update the display TString16 _button; @@ -59,8 +60,8 @@ protected: TMask_field* field(short id) const; int rec2row(int rec); - int row2rec(int row); - int set_pos(int row, int col) { _cur_col = col; return _cur_rec = row2rec(_cur_row = row); } + int row2rec(int& row); + int set_pos(int row, int col) { _cur_col = col; _cur_row = row; return _cur_rec = row2rec(_cur_row); } bool notify(int row, KEY k); void notify_change(); @@ -127,7 +128,7 @@ TSpreadsheet::TSpreadsheet(short x, short y, short dx, short dy, TSheet_field* o) : _mask(maskname, maskno), _notify(NULL), _edit_field(NULL), _owner(o), _cur_row(0), _cur_col(0), _active(TRUE), - _row_dirty(FALSE), _check_enabled(TRUE), _firstfocus(TRUE) + _row_dirty(FALSE), _check_enabled(TRUE), _firstfocus(TRUE), _update(TRUE) { const int NUMBER_WIDTH = 3; const int MAX_COL = 32; @@ -291,22 +292,30 @@ TSpreadsheet::~TSpreadsheet() } - // Converts a row number in the correspondig record number -int TSpreadsheet::row2rec(int row) +int TSpreadsheet::row2rec(int& row) { int rows; const long* rec = xi_get_list_info(_list, &rows); - - if (row < 0 || row >= rows) + + int r = -1; + if (row < 0) { -#ifdef DBG - error_box("Line %d is not visible: the last one is %d", row, rows); -#endif - return 0; - } + row = 0; + r = (int)rec[row]-1; + } + else + if (row >= rows) + { + row = rows-1; + r = (int)rec[row]+1; + } + else + r = (int)rec[row]; + + CHECKD(r >= 0 && r <= items(), "Sheet line out of range: ", row); - return (int)rec[row]; + return r; } @@ -350,7 +359,7 @@ TMask_field* TSpreadsheet::cell2field(const XI_OBJ* cell) const } void TSpreadsheet::update_rec(int rec) -{ +{ const int riga = rec2row(rec); if (riga >= 0) { @@ -375,7 +384,7 @@ void TSpreadsheet::set_focus_cell(int riga, int colonna) if (colonna < _columns) { XI_OBJ cell; - XI_MAKE_CELL(&cell, _list, r, colonna); + XI_MAKE_CELL(&cell, _list, riga, colonna); xi_set_focus(&cell); if (_edit_field == NULL) @@ -433,13 +442,16 @@ bool TSpreadsheet::destroy(int rec) void TSpreadsheet::update(int row) { - if (row < 0) - { - xi_cell_request(_list); // Force updatde - xi_scroll(_list, XI_SCROLL_FIRST); - } - else - update_rec(row); + if (_update) + { + if (row < 0) + { + xi_cell_request(_list); // Force updatde + xi_scroll(_list, XI_SCROLL_FIRST); + } + else + update_rec(row); + } } @@ -538,8 +550,8 @@ void TSpreadsheet::list_handler(XI_EVENT *xiev) } if (field(cid)->has_query()) { - xiev->v.cell_request.button = - xiev->v.cell_request.button_on_focus = TRUE; + xiev->v.cell_request.button = TRUE; + xiev->v.cell_request.button_on_focus = TRUE; } if (cell_disabled(rec, col)) xiev->v.cell_request.back_color = DISABLED_BACK_COLOR; @@ -547,10 +559,12 @@ void TSpreadsheet::list_handler(XI_EVENT *xiev) } } else src = format("%d", rec+1); - const int len = xiev->v.cell_request.len; char* dst = xiev->v.cell_request.s; - if (src) + if (src && *src) + { + const int len = xiev->v.cell_request.len; strncpy(dst, src, len); + } else *dst = '\0'; } @@ -610,7 +624,9 @@ void TSpreadsheet::list_handler(XI_EVENT *xiev) { update_rec(_cur_rec); _row_dirty = TRUE; - } + } else + if (k == K_DEL) + _row_dirty = _cell_dirty = FALSE; if (!cell_disabled(_cur_rec, _cur_col-1)) set_focus_cell(_cur_row, _cur_col); @@ -652,15 +668,17 @@ void TSpreadsheet::list_handler(XI_EVENT *xiev) bool ok = sheet_mask().check_fields(); if (ok) { + _update = FALSE; mask2str(_cur_rec); ok = notify(_cur_rec, K_ENTER); // Notify edit + _update = TRUE; } if (!ok) xiev->refused = TRUE; else xvt_statbar_refresh(); - _check_enabled = TRUE; + _check_enabled = TRUE; } break; case XIE_ON_CELL: @@ -965,17 +983,18 @@ TMask& TSpreadsheet::mask() const } +// Ritorna il campo con l'identificatore dato della maschera dello sheet TMask_field* TSpreadsheet::field(short id) const { const int pos = _mask.id2pos(id); - if (pos < 0) return NULL; - return &_mask.fld(pos); + return pos < 0 ? NULL : &_mask.fld(pos); } -void TSpreadsheet::mask2str(int riga) +// Ricopia i campi della maschera nel record dato ed aggiorna il display +void TSpreadsheet::mask2str(int rec) { - TToken_string& r = row(riga); + TToken_string& r = row(rec); r.cut(0); for (short id = FIRST_FIELD; ; id++) { @@ -1000,7 +1019,7 @@ void TSpreadsheet::mask2str(int riga) #endif } #if XVT_OS == XVT_OS_WIN - update_rec(riga); + update(rec); #endif } @@ -1235,7 +1254,7 @@ void TSheet_field::create(WINDOW parent) // Certified 100% -TArray& TSheet_field::rows_array() const +TString_array& TSheet_field::rows_array() const { return _sheet->rows_array(); } @@ -1268,7 +1287,8 @@ TToken_string& TSheet_field::row(int n) void TSheet_field::force_update(int r) { #if XVT_OS == XVT_OS_WIN - _sheet->update(r); + if (_sheet->_check_enabled) + _sheet->update(r); #else _sheet->open(); #endif diff --git a/include/msksheet.h b/include/msksheet.h index b6c6d679e..245da2c46 100755 --- a/include/msksheet.h +++ b/include/msksheet.h @@ -30,7 +30,7 @@ protected: public: TToken_string& row(int n); // Get/Create a new row - TArray& rows_array() const; // Get all rows + TString_array& rows_array() const; // Get all rows int first_empty() const; // First empty row int items() const; // Number of rows int selected() const; // Number of current row diff --git a/include/prassi.ver b/include/prassi.ver index 65855e643..53b731ba6 100755 --- a/include/prassi.ver +++ b/include/prassi.ver @@ -1 +1 @@ -#define VERSION 1.5 +#define VERSION 1.5