From e664d27004b2299c82482aec90926ced4b5dda87 Mon Sep 17 00:00:00 2001 From: guy Date: Thu, 3 Nov 1994 12:46:49 +0000 Subject: [PATCH] Corretta gestione errori in maskfld Cambiata campo.ico in prassi.ico git-svn-id: svn://10.65.10.50/trunk@519 c028cbd2-c16b-5b4b-a496-9718f37d4682 --- include/applicat.cpp | 4 ++- include/controls.cpp | 2 +- include/default.url | 4 +-- include/mask.cpp | 12 ++++----- include/maskfld.cpp | 46 ++++++++++++++++------------------ include/maskfld.h | 16 ++++++------ include/msksheet.cpp | 25 ++++++++++++------- include/sheet.cpp | 59 +++++++++++++++++++++++++++----------------- include/strings.h | 13 +++++++--- include/validate.cpp | 2 +- 10 files changed, 103 insertions(+), 80 deletions(-) diff --git a/include/applicat.cpp b/include/applicat.cpp index 3b726a7d8..0560ee277 100755 --- a/include/applicat.cpp +++ b/include/applicat.cpp @@ -113,7 +113,8 @@ void TBanner::handler(WINDOW win, EVENT* ep) set_font(FF_TIMES, FS_BOLD | FS_ITALIC, BIGY); char* t = (char*)(const char*)main_app().title(); int w = win_get_text_width(win, t, -1); - int x = (r.right-r.left-w)>>1, y = r.bottom - BIGY; + int a; win_get_font_metrics(win, NULL, &a, NULL); + int x = (r.right-r.left-w)>>1, y = 32 + CHARX + a; win_draw_text(win, x+1, y+1, t, -1); set_color(COLOR_BLACK, COLOR_LTGRAY); win_draw_text(win, x, y, t, -1); @@ -134,6 +135,7 @@ void TBanner::handler(WINDOW win, EVENT* ep) set_pen(COLOR_BLACK); win_draw_rect(win, &r); offset_rect(&r, 1, 1); set_pen(COLOR_WHITE); win_draw_rect(win, &r); + win_draw_icon(win, CHARX<<1, CHARX<<1, ICON_RSRC); } else diff --git a/include/controls.cpp b/include/controls.cpp index 6844764ff..2a957758e 100755 --- a/include/controls.cpp +++ b/include/controls.cpp @@ -593,7 +593,7 @@ TPush_button::TPush_button(short left, short top, short right, short bottom, _accel *= CHARX; _dx = (right-left-strlen(caption())*CHARX) >> 1; - _dy = byte(height+BASEY) >> 1; + _dy = (byte)CHARY; } } diff --git a/include/default.url b/include/default.url index 8be4b7fa7..9107ed45d 100755 --- a/include/default.url +++ b/include/default.url @@ -1,6 +1,6 @@ #ifndef APPNAME -#define APPNAME CAMPO -#define QAPPNAME "CAMPO" +#define APPNAME PRASSI +#define QAPPNAME "PRASSI" #define LIBDIR c:\xvt.322\xvtwin\lib #endif diff --git a/include/mask.cpp b/include/mask.cpp index b42124d9b..332758b91 100755 --- a/include/mask.cpp +++ b/include/mask.cpp @@ -151,12 +151,10 @@ void TMask::handler(WINDOW win, EVENT* ep) case DLG_F9: { WINDOW w = ep->v.ctl.ci.win; + TMask_field* f = (TMask_field*)get_app_data(w); + w = f->win(); if (test_focus_change(w)) - { - // Attiva ricerca sul campo associato al bottone - TMask_field* f = (TMask_field*)get_app_data(w); - f->on_key(K_F9); - } + f->on_key(K_F9); // Attiva ricerca sul campo associato al bottone } break; default: @@ -421,7 +419,7 @@ void TMask::start_run() { TMask_field& f = fld(i); if ((f.active() || f.ghost()) && - f.class_id() != CLASS_BUTTON_FIELD && f.dirty() != 2) + f.class_id() != CLASS_BUTTON_FIELD && f.dirty() != 3) { f.set_dirty(FALSE); f.on_hit(); @@ -433,7 +431,7 @@ void TMask::start_run() { TMask_field& f = fld(i); if (mode() == MODE_QUERY && f.is_edit() && f.in_key(1) && - !f.automagic() && !f.get().empty() || f.dirty() == 2) + !f.automagic() && !f.get().empty() || f.dirty() == 3) f.set_dirty(TRUE); else { diff --git a/include/maskfld.cpp b/include/maskfld.cpp index fcaec2068..322291295 100755 --- a/include/maskfld.cpp +++ b/include/maskfld.cpp @@ -1,4 +1,4 @@ -// $Id: maskfld.cpp,v 1.38 1994-10-31 12:09:31 guy Exp $ +// $Id: maskfld.cpp,v 1.39 1994-11-03 12:46:38 guy Exp $ #include #include @@ -1034,31 +1034,33 @@ void TBrowse::parse_output(TScanner& scanner) } -bool TBrowse::parse_copy(const TString& what, const TBrowse* b) +bool TBrowse::parse_copy(const TString& what, const TBrowse& b) { const bool all = what == "AL"; if (all || what == "US") { - set_insert(b->get_insert()); - _filter = b->get_filter(); + set_insert(b.get_insert()); + _filter = b.get_filter(); + if (field()._warning.empty()) + field()._warning = b.field()._warning; if (!all) return TRUE; } if (all || what == "IN") { - _inp_id = b->_inp_id; - _inp_fn = b->_inp_fn; + _inp_id = b._inp_id; + _inp_fn = b._inp_fn; if (!all) return TRUE; } if (all || what == "DI") { - _head = b->_head; - _items = b->_items; + _head = b._head; + _items = b._items; if (!all) return TRUE; } if (all || what == "OU") { - _out_id = b->_out_id; - _out_fn = b->_out_fn; + _out_id = b._out_id; + _out_fn = b._out_fn; _secondary = TRUE; } return TRUE; @@ -1300,7 +1302,7 @@ bool TBrowse::do_insert() } #if XVT_OS == XVT_OS_WIN - if (strnicmp(app, MainApp()->name(), 3) == 0) + if (strnicmp(app, main_app().name(), 3) == 0) app.insert("a", 3); #endif @@ -1356,7 +1358,7 @@ TToken_string& TBrowse::create_siblings(TToken_string& siblings) const TCursor* c = b->cursor(); // Considera ricerche sullo stesso file ma con chiave diversa - if (c && c->file().num() == _cursor->file().num() && + if (c->file().num() == _cursor->file().num() && (key[c->key()] == FALSE || id == _fld->dlg())) { const TString16 fn(_out_fn.get(n)); // Legge nome del campo su file @@ -1413,8 +1415,7 @@ KEY TBrowse::run() long selected = 0; TToken_string siblings; - if (_inp_id.items() == 1) - create_siblings(siblings); + create_siblings(siblings); { TToken_string* sib = siblings.empty() ? NULL : &siblings; @@ -1480,7 +1481,7 @@ bool TBrowse::check(CheckTime t) else { do_clear(); - _fld->set_dirty(2); + _fld->set_dirty(3); } } } @@ -1561,7 +1562,7 @@ const TBrowse* TEdit_field::get_browse(TScanner& scanner) const const TBrowse* b = (const TBrowse*)f.browse(); #ifdef DBG if (b == NULL) - error_box("La USE del campo %d e' nulla e non puo' essere copiata nel campo %d", id, dlg()); + yesnofatal_box("La USE del campo %d e' nulla e non puo' essere copiata nel campo %d", id, dlg()); #endif return b; } @@ -1660,7 +1661,7 @@ bool TEdit_field::parse_item(TScanner& scanner) _browse = new TBrowse(this, b->cursor()); if (_browse) - return _browse->parse_copy(what, b); + return _browse->parse_copy(what, *b); #ifdef DBG return yesnofatal_box("Impossibile COPY senza USE nel campo %d", dlg()); @@ -1846,7 +1847,7 @@ const char* TEdit_field::format(const char* d) if (fpark.len() > _size) { #ifdef DBG - error_box("Campo %d troppo lungo: %d > %d", dlg(), fpark.len(), _size); + yesnofatal_box("Campo %d troppo lungo: %d > %d", dlg(), fpark.len(), _size); #endif fpark.cut(_size); } @@ -2420,13 +2421,8 @@ bool TReal_field::on_key(KEY key) { const char* n = get(); if (*n && !real::is_real(n)) - return error_box("Numero non valido"); - - const int segno = real(n).sign(); - if (required() && segno == 0 && !mask().query_mode()) - return error_box("Manca un valore indispensabile"); - - if (_flags.uppercase && segno < 0) + return error_box("Valore numerico non valido"); + if (_flags.uppercase && real(n).sign() < 0) return error_box("Il numero deve essere positivo"); } } diff --git a/include/maskfld.h b/include/maskfld.h index f998aa024..8e9714e3d 100755 --- a/include/maskfld.h +++ b/include/maskfld.h @@ -1,4 +1,4 @@ -/* $Id: maskfld.h,v 1.5 1994-09-27 09:55:39 alex Exp $ */ +/* $Id: maskfld.h,v 1.6 1994-11-03 12:46:42 guy Exp $ */ #ifndef __MASKFLD_H #define __MASKFLD_H @@ -64,13 +64,13 @@ protected: struct TField_Flags { bool automagic : 1; - bool dirty : 1; // Modified during run ? + bool dirty : 2; // Modified during run ? bool enabled : 1; // Is editable bool enable_default : 1; bool firm : 1; // Is the current firm ? bool focusdirty : 1; // Modified during focus ? bool ghost : 1; - bool persistent : 1; + bool persistent : 1; bool rightjust : 1; bool roman : 1; // Is a Roman number ? bool showed : 1; // Is visible @@ -207,14 +207,15 @@ class TEdit_field : public TMask_field { friend class TBrowse; friend class TList_sheet; + friend class TBrowse_sheet; protected: // @DPROT TString80 _str; TString16 _picture; TString _warning; - CheckType _check; // Accettabilita' di valori nulli - bool _forced; + CheckType _check; // Accettabilita' di valori nulli + bool _forced; bool _check_enabled; // Abilitato TBrowse* _browse; @@ -292,6 +293,7 @@ protected: TToken_string& create_siblings(TToken_string& siblings); public: + int inputs() { return _inp_id.items(); } int do_input(bool filter = FALSE); // Serve ai TCursor_sheet TBrowse(TEdit_field* f, TRelation* r, int key = 1, const char* filter = ""); @@ -303,13 +305,13 @@ public: void parse_display(TScanner& scanner); void parse_output(TScanner& scanner); void parse_insert(TScanner& scanner); - bool parse_copy(const TString& what, const TBrowse* b); + bool parse_copy(const TString& what, const TBrowse& b); void set_insert(const char* s) { _insert = s;} const TString& get_insert() const { return _insert;} const TString& get_filter() const { return _filter;} - TEdit_field& field() {return *_fld;} + TEdit_field& field() const { return *_fld; } bool check(CheckTime = RUNNING_CHECK); bool empty_check(); diff --git a/include/msksheet.cpp b/include/msksheet.cpp index 56df5d700..a6ba7d85e 100755 --- a/include/msksheet.cpp +++ b/include/msksheet.cpp @@ -492,14 +492,21 @@ if (xiev->v.xi_obj->type == XIT_LIST) case XIE_DBL_CELL: { _check_enabled = FALSE; + + const int oldrow = _cur_row; _cur_row = row2rec(xiev->v.xi_obj->v.cell.row); _cur_col = xiev->v.xi_obj->v.cell.column; + + if (oldrow != _cur_row || !_row_dirty) + notify(_cur_row, K_SPACE); + const KEY k = edit(_cur_row); if (k == K_ENTER) { update_rec(_cur_row); _row_dirty = TRUE; } + if (!cell_disabled(_cur_row, _cur_col)) set_focus_cell(_cur_row, _cur_col); _check_enabled = TRUE; @@ -507,7 +514,7 @@ if (xiev->v.xi_obj->type == XIT_LIST) break; case XIE_ON_LIST: if (_firstfocus) // Trick to avoid the sheet to keep the focus forever ... -{ // .. it costed me two day worth of hard work! +{ // .. it costed me two day worth of hard work! xiev->refused = TRUE; _firstfocus = FALSE; } @@ -769,7 +776,7 @@ bool TSpreadsheet::on_key(KEY k) if (k == 'A') n++; if (n < 0) n = 0; 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 return FALSE; @@ -778,8 +785,11 @@ bool TSpreadsheet::on_key(KEY k) k = K_INS; // Inserimento in corso } - edit(n, k); // Edita riga selezionata o creata - + notify(n, K_SPACE); // Notifica inizio cambiamento + k = edit(n, k); // Edita riga selezionata o creata + if (k == K_ENTER) + notify(n, K_ENTER); // Notifica avvenuto cambiamento + set_front_window(win()); // Aggiorna sheet a video open(); } @@ -962,7 +972,7 @@ bool TSpreadsheet::notify(int n, KEY k) { const bool ok = _notify ? _notify(n, k) : TRUE; if (k == K_ENTER) - set_dirty(ok ? TRUE : 2); + set_dirty(ok ? TRUE : 3); return ok; } @@ -976,15 +986,12 @@ KEY TSpreadsheet::edit(int n, KEY tasto) { const int olditems = items(); str2mask(n); - notify(n, K_SPACE); // Notifica intenzione di modificare const KEY k = _mask.run(); - if (k == K_ENTER) { mask2str(n); - notify(n, K_ENTER); } else if (k == K_DEL) { @@ -1140,7 +1147,7 @@ void TSheet_field::enable_column(int column, bool on) void TSheet_field::enable_cell(int row, int column, bool on) -{ +{ _sheet->enable_cell(row, column, on); } diff --git a/include/sheet.cpp b/include/sheet.cpp index 9fad7918d..e8d32bd86 100755 --- a/include/sheet.cpp +++ b/include/sheet.cpp @@ -638,14 +638,17 @@ TBrowse_sheet::TBrowse_sheet(TCursor* cursor, const char* fields, : TCursor_sheet(cursor, fields, title, head, buttons), _field(f) { + if (field().browse()->inputs() == 1) + { #if XVT_OS == XVT_OS_WIN - xvt_create_control(WC_EDIT, 1, -3, f->size()+1, 1, f->get(), win(), - CTL_FLAG_DISABLED, 0L, 100); + xvt_create_control(WC_EDIT, 1, -3, f->size()+1, 1, f->get(), win(), + CTL_FLAG_DISABLED, 0L, 100); #else - xvt_create_control(WC_EDIT, 1, -3, f->size()+2, 1, f->get(), win(), - CTL_FLAG_DISABLED, 0L, 100); + xvt_create_control(WC_EDIT, 1, -3, f->size()+2, 1, f->get(), win(), + CTL_FLAG_DISABLED, 0L, 100); #endif - + } + if (s && s->items() > 2) { int maxlen = 0; @@ -701,22 +704,27 @@ void TBrowse_sheet::repos_buttons() const } +HIDDEN const char* ztrim(TString& s) +{ + for (int i = 0; s[i] == ' ' || s[i] == '0'; i++); + if (i > 0) s.ltrim(i); + return s; +} + bool TBrowse_sheet::on_key(KEY k) { - WINDOW ctl = get_ctl_window(win(), 100); - + const WINDOW ctl = get_ctl_window(win(), 100); const bool alnum = k < 256 && isprint(k); - if (alnum || k == K_BACKSPACE || k == K_DEL) + + if (ctl != NULL_WIN && (alnum || k == K_BACKSPACE || k == K_DEL)) { const long oldsel = selected(); - // const TString80 old(_field->get()); - WINDOW fwin = get_ctl_window(_field->parent(), _field->dlg()); - TString80 old; - get_title(fwin, (char *) (const char *) old, 80); - old.ltrim(); - - - TString80 val((const char*)old); + const bool corre = field().mask().is_running(); + const WINDOW fldwin = field().win(); + + TString80 old(corre ? field().get_window_data() : field().get_field_data()); + TString80 val(ztrim(old)); + if (alnum) { if (val.len() >= field().size()) @@ -724,25 +732,30 @@ bool TBrowse_sheet::on_key(KEY k) val << char(k); } else val.rtrim(1); - // field().set(val); - set_title(fwin, (char *) (const char*) val); + if (corre) set_title(fldwin, (char*)(const char*)val); + else field().set_field_data(val); + ((TBrowse*)field().browse())->do_input(FALSE); _cursor->read(); if (_cursor->file().bad()) { beep(); - // field().set(val = old); val = old; - set_title(fwin, (char *) (const char *)val); + if (corre) set_title(fldwin, (char*)(const char*)val); + else field().set_field_data(val); *_cursor = oldsel; } else select(_cursor->pos()); - - if (ctl != NULL_WIN) set_title(ctl, (char*)(const char*)field().get()); + + if (ctl != NULL_WIN) + { + val = corre ? field().get_window_data() : field().get_field_data(); + set_title(ctl, (char*)(const char*)val); + } return TRUE; - } + } else { field().set(""); diff --git a/include/strings.h b/include/strings.h index a8c950ff7..c0bc7c3f7 100755 --- a/include/strings.h +++ b/include/strings.h @@ -154,7 +154,7 @@ public: virtual TString& format(const char* fmt, ...); const TString& operator =(const TString& s) { return set((const char*)s); } - const TString& operator=(const char* s) { return set(s); } + const TString& operator=(const char* str) { return set(str); } void strncpy(const char* s, int n); }; @@ -164,8 +164,9 @@ class TString16 : public TFixed_string public: TString16(const char* str = "") : TFixed_string(_str16, 17) { set(str); } + TString16(const TString& s) : TFixed_string(_str16, 17) { set(s); } const TString& operator =(const TString& s) { return set((const char*)s); } - const TString& operator=(const char* s) { return set(s); } + const TString& operator =(const char* str) { return set(str); } }; class TString80 : public TFixed_string @@ -174,8 +175,9 @@ class TString80 : public TFixed_string public: TString80(const char* str = "") : TFixed_string(_str80, 81) { set(str); } + TString80(const TString& s) : TFixed_string(_str80, 81) { set(s); } + const TString& operator =(const char* str) { return set(str); } const TString& operator =(const TString& s) { return set((const char*)s); } - const TString& operator=(const char* s) { return set(s); } }; class TString256 : public TFixed_string @@ -184,8 +186,9 @@ class TString256 : public TFixed_string public: TString256(const char* str = "") : TFixed_string(_str256, 257) { set(str); } + TString256(const TString& s) : TFixed_string(_str256, 257) { set(s); } + const TString& operator =(const char* str) { return set(str); } const TString& operator =(const TString& s) { return set((const char*)s); } - const TString& operator=(const char* s) { return set(s); } }; @@ -200,8 +203,10 @@ public: // @FPUB TFilename(const char* n = "") : TString80(n) {} + TFilename(const TString& n) : TString80(n) {} const TString& operator =(const char* s) { return set(s); } + const TString& operator =(const TString& s) { return set((const char*)s); } // assegnazione tra TFile e stringa const char* ext() const; // Ritorna l'estensione diff --git a/include/validate.cpp b/include/validate.cpp index 6fad2a933..b4b524fb1 100755 --- a/include/validate.cpp +++ b/include/validate.cpp @@ -28,7 +28,7 @@ HIDDEN bool _expr_val(TEdit_field& f, KEY) const char* s = e.varname(i); if (s[0] != '#') { - TString80 err; err << "Cannot load variable " << s << " in " << e; + TString80 err; err << "Non trovo la variabile " << s << " in " << e; return f.error_box((const char*)err); } s++;