diff --git a/include/classes.h b/include/classes.h index 074d96f16..950120fb8 100755 --- a/include/classes.h +++ b/include/classes.h @@ -47,6 +47,7 @@ #define CLASS_EDIT_FIELD 244 #define CLASS_REAL_FIELD 245 #define CLASS_DATE_FIELD 246 +#define CLASS_GRID_FIELD 247 #define CLASS_GOLEM 900 diff --git a/include/config.cpp b/include/config.cpp index 1cbab91cf..a2ce1ea68 100755 --- a/include/config.cpp +++ b/include/config.cpp @@ -346,7 +346,7 @@ bool TConfig::get_bool( // @xref // { - const TString16 d(def ? "X" : ""); + const char* d = def ? "X" : ""; const TString& s = get(var, section, index, d).upper(); return s != "" && (s == "X" || s == "ON" || s == "YES" || s == "OK" || s == "TRUE"); } diff --git a/include/form.cpp b/include/form.cpp index 6663ec715..cb4fadd16 100755 --- a/include/form.cpp +++ b/include/form.cpp @@ -1572,9 +1572,8 @@ void TForm_number::apply_format(real& n , TString& s) const } } - int comma = pic.find(','); - int at = pic.find('@'); - if (at >= 0 && comma <0) + const int at = pic.find('@'); + if (at > 0) { const int len = atoi(&pic[at+1]); if (len > 0) diff --git a/include/mask.cpp b/include/mask.cpp index e4c31ec49..0f46d4fca 100755 --- a/include/mask.cpp +++ b/include/mask.cpp @@ -635,7 +635,7 @@ void TMask::handler(WINDOW win, EVENT* ep) { TSheet_field& sht = (TSheet_field&)*_last_sheet; #if (XVT_PTK_VERSION_MAJOR > 4) || (XVT_PTK_VERSION_MAJOR == 4 && XVT_PTK_VERSION_MINOR >= 50) - MENU_ITEM* menu = xvt_res_get_menu(BROWSE_BAR+1); + MENU_ITEM* menu = xvt_res_get_menu(BROWSE_BAR); if (menu) { const PNT& p = ep->v.mouse.where; @@ -647,7 +647,7 @@ void TMask::handler(WINDOW win, EVENT* ep) if (p.h > 2 * cr.right / 3) pa = XVT_POPUP_RIGHT_ALIGN; - xvt_menu_popup(menu, win, p, pa, NULL); + xvt_menu_popup(menu->child, win, p, pa, NULL); xvt_res_free_menu_tree(menu); } #else diff --git a/include/maskfld.cpp b/include/maskfld.cpp index e5d954960..b156fb053 100755 --- a/include/maskfld.cpp +++ b/include/maskfld.cpp @@ -2056,7 +2056,7 @@ void TBrowse::do_output(CheckTime t) } -void TBrowse::do_clear() +void TBrowse::do_clear(CheckTime t) { for (TString16 fld = _out_id.get(0); fld.not_empty(); fld = _out_id.get()) { @@ -2068,7 +2068,7 @@ void TBrowse::do_clear() f.reset(); s_checked.set(id); f.on_hit(); - f.check(); + f.check(t); } } } @@ -2237,7 +2237,9 @@ TToken_string& TBrowse::create_siblings(TToken_string& siblings) KEY TBrowse::run() -{ +{ + begin_wait(); + do_input(TRUE); _cursor->read(_isgteq); @@ -2285,7 +2287,9 @@ KEY TBrowse::run() } } } - + + end_wait(); + TBrowse_sheet s(_cursor, _items, caption, _head, buttons, &field(), siblings); k = s.run(); selected = s.selected(); @@ -2367,15 +2371,18 @@ bool TBrowse::check(CheckTime t) const int ne = do_input(TRUE); if (ne || chk == CHECK_REQUIRED) - { + { +/* Guy: vecchio modo _cursor->setkey(); _cursor->file().read(_isequal); passed = _cursor->ok(); - +*/ + passed = _cursor->test() == NOERR; + if (t != FINAL_CHECK) { if (passed) - { + { _cursor->repos(); do_output(t); } @@ -2387,7 +2394,7 @@ bool TBrowse::check(CheckTime t) } else { - do_clear(); + do_clear(t); if (!field().mask().query_mode() && field().check_enabled()) field().set_dirty(3); } @@ -2406,7 +2413,7 @@ bool TBrowse::check(CheckTime t) else { if (t != FINAL_CHECK) - do_clear(); + do_clear(t); } } } diff --git a/include/maskfld.h b/include/maskfld.h index a8aa8b000..48b77ac62 100755 --- a/include/maskfld.h +++ b/include/maskfld.h @@ -805,7 +805,7 @@ class TBrowse : public TBrowse_button // @access Protected Member protected: // @cmember Azzera i campi di output sulla maschera - void do_clear(); + void do_clear(CheckTime t); // @cmember Chiama la maschera di gestione della ricerca bool do_link(bool insert); diff --git a/include/relapp.cpp b/include/relapp.cpp index 41769fab8..3533c8a8f 100755 --- a/include/relapp.cpp +++ b/include/relapp.cpp @@ -314,47 +314,37 @@ void TRelation_application::query_mode( void TRelation_application::insert_mode() -{ +{ + bool try_auto = TRUE; + if (_mask->query_mode()) - { - if (test_key(1, FALSE) == FALSE) - { - if (!autonum(_mask, FALSE)) - { - query_insert_mode(); - return; - } - } - - const bool changing = changing_mask(MODE_INS); - TFilename workname; workname.temp("msk"); - if (changing) - { - _mask->set_workfile(workname); - _mask->save(); - _mask->close_modal(); - } - _mask = get_mask(MODE_INS); - if (changing) - { - _mask->reset(); - _mask->set_workfile(workname); - _mask->load(); - ::remove(workname); - _mask->open_modal(); - } - } - else + try_auto = test_key(1, FALSE) == FALSE; + + if (try_auto && !autonum(_mask, FALSE)) { - if (!autonum(_mask, FALSE)) - { - query_insert_mode(); - return; - } + query_insert_mode(); + return; } - set_mode(MODE_INS); + const bool changing = changing_mask(MODE_INS); + TFilename workname; workname.temp("msk"); + if (changing) + { + _mask->set_workfile(workname); + _mask->save(); + _mask->close_modal(); + } + _mask = get_mask(MODE_INS); + if (changing) + { + _mask->reset(); + _mask->set_workfile(workname); + _mask->load(); + ::remove(workname); + _mask->open_modal(); + } + set_mode(MODE_INS); get_relation()->zero(); // Azzera tutta la relazione! init_insert_mode(*_mask); } diff --git a/include/relation.cpp b/include/relation.cpp index 8f2a13aa4..6fe1e693c 100755 --- a/include/relation.cpp +++ b/include/relation.cpp @@ -579,49 +579,47 @@ int TRelation::position_rels( TLocalisamfile& from = file(rd.num()); TLocalisamfile& to = file(rd.link()); TReclock lck = rd._allow_lock ? lockop : _nolock; + + TRectype& furr = from.curr(); + furr.zero(); if (to.curr().empty()) - { from.zero(); continue; } + continue; from.setkey(rd._key); - from.curr().zero(); // build record - if (rd._fields.items() && rd._exprs.items()) + for (int j = 0 ; j < rd._fields.items(); j++) // for each field { - for (int j = 0 ; j < rd._fields.items(); j++) // for each field - { - const char* expr = rd.evaluate_expr(j, to); - TFieldref& s = (TFieldref&) rd._fields[j]; - s.write(expr, from.curr()); - } // for each field - } + const char* expr = rd.evaluate_expr(j, to); + TFieldref& s = (TFieldref&) rd._fields[j]; + s.write(expr, furr); + } // for each field // read record: if not found, zero current record - const TRectype rec(from.curr()); + from.read(op, lck, atdate); if (from.bad()) { - rd._first_match = (from.curr() == rec); - if (rd._first_match) + bool eq = TRUE; + for (int kk = 0; eq && kk < rd._fields.items(); kk++) { - bool eq = TRUE; - - for (int kk = 0; eq && kk < rd._fields.items(); kk++) - { - if (rd._forced[kk]) - { - TFieldref& fl = (TFieldref&)rd._fields[kk]; - const TString f_fr(fl.read(from.curr())); - eq = (f_fr == rd.evaluate_expr(kk, to)); - } - } - if (eq) from.setstatus(NOERR); - else { rd._first_match = FALSE; from.curr().zero(); } + TFieldref& fl = (TFieldref&)rd._fields[kk]; + const TString80 f_fr(fl.read(furr)); + const TString80 f_ex(rd.evaluate_expr(kk, to)); + if (rd._forced[kk]) + eq = f_fr == f_ex; + else + eq = f_fr.compare(f_ex, f_ex.len()); } - else from.curr().zero(); + rd._first_match = eq; + if (eq) + from.setstatus(NOERR); + else + furr.zero(); } - else rd._first_match = TRUE; + else + rd._first_match = TRUE; } // for each relation return _errors; } @@ -1010,25 +1008,34 @@ int TCursor::filtercursor(int pagecnt, TRecnotype* page) bool TCursor::ok() const - { - if (file().bad()) return FALSE; + if (file().bad()) + return FALSE; - const TRectype& rec = file().curr(); - TString key(rec.key(_nkey)), kf(from()), kt(to()); + const TRectype& rec = file().curr(); + + const TFixed_string key(rec.key(_nkey)); + const TString& kf = from(); + const TString& kt = to(); + if (file().tab()) { - key.ltrim(3); - kf.ltrim(3); - kt.ltrim(3); + if (key.compare(kf, 3) < 0 || (kt.not_empty() && kt.compare(key, 3) < 0)) + return FALSE; } + else + { + if (key < kf || (kt.not_empty() && kt.compare(key, kt.len()) < 0)) + return FALSE; + } + + if (update_relation()) + _if->update(); - if (key < (const char *) kf || (kt.not_empty() && kt < (const char *) key.left(kt.len()))) - return FALSE; - if (update_relation()) _if->update(); if ((_filterfunction ? _filterfunction(_if) : TRUE ) && (_fexpr ? __evalcondition(*_if, _fexpr) : TRUE)) return TRUE; + return FALSE; } @@ -1140,7 +1147,6 @@ void TCursor::filter( } void TCursor::setkey(int nkey) - { if (nkey != _nkey) { @@ -1151,65 +1157,96 @@ void TCursor::setkey(int nkey) } } +int TCursor::test(TIsamop op, TReclock lockop) const +{ + TLocalisamfile& curfile = file(); + curfile.setkey(_nkey); + + int err = NOERR; + if (op == _isequal) + { + const TString80 match(curfile.curr().key(_nkey)); + bool trovato = FALSE; + + for (err = curfile.read(op, lockop); + err == NOERR && match == curfile.curr().key(_nkey); + err = curfile.next(lockop)) + { + if (ok()) + { + trovato = TRUE; + break; + } + else + err = curfile.next(); + } + if (!trovato && err == NOERR) + { + err = _iskeynotfound; + curfile.setstatus(err); + } + } + else + { + for (err = curfile.read(op, lockop); + err == NOERR && !ok(); + err = curfile.next(lockop)) + { } + } + + return err; +} TRecnotype TCursor::read(TIsamop op, TReclock lockop, TDate& atdate) { - TRecnotype *page; - int pagecnt; - - file().setkey(_nkey); - const bool approx = (op == _isgteq); - - _if->file().read(op, lockop, atdate); - if (approx) - { - while (_if->file().good() && !ok()) - _if->file().next(); - } - const TRecnotype curpos = file().recno(); - + int err = test(op, lockop); + TLocalisamfile& curfile = file(); + const TRecnotype curpos = curfile.recno(); if (changed()) _totrec = update(); - if (approx && _if->file().status() == _iseof) + + if (err != NOERR) { _pos = _totrec - 1; if (_pos < 0) { - file().zero(); - file().setstatus(_isemptyfile); + curfile.zero(); + err = _isemptyfile; } else - { readrec(); - file().setstatus(_iseof); - } - return _pos; + curfile.setstatus(err); } - - FILE* _f = open_index(); - - if (fseek(_f, 0L, SEEK_SET) != 0) - fatal_box("Can't repos cursor : File %d\n", file().filehnd()->ln); - - page = new TRecnotype [CMAXELPAGE]; - _pos = -1; - - for (TRecnotype max = _totrec; _pos == -1 && max > 0; max -= pagecnt) + else { - pagecnt = (max < CMAXELPAGE) ? (int)max : CMAXELPAGE; - fread(page, sizeof(TRecnotype), pagecnt, _f); - for (int i = 0; i < pagecnt; i++) - if (page[i] == curpos) - { - _pos = _totrec - max + i; - break; - } - } - if (_pos == -1) _pos = 0; - delete page; - fclose(_f); + FILE* _f = open_index(); + + if (fseek(_f, 0L, SEEK_SET) != 0) + fatal_box("Can't repos cursor : File %d\n", file().filehnd()->ln); + + TRecnotype *page = new TRecnotype [CMAXELPAGE]; + int pagecnt; + + _pos = -1; + for (TRecnotype max = _totrec; _pos == -1 && max > 0; max -= pagecnt) + { + pagecnt = (max < CMAXELPAGE) ? (int)max : CMAXELPAGE; + fread(page, sizeof(TRecnotype), pagecnt, _f); + for (int i = 0; i < pagecnt; i++) + if (page[i] == curpos) + { + _pos = _totrec - max + i; + break; + } + } + delete page; + fclose(_f); - readrec(); + if (_pos < 0L) + _pos = 0L; + readrec(); + } + return _pos; } diff --git a/include/relation.h b/include/relation.h index 0d637c45a..26b55e7be 100755 --- a/include/relation.h +++ b/include/relation.h @@ -448,6 +448,8 @@ public: // @cmember Ritorna il descrittore della tabella TRectype& curr(const char * tab) const { return _if->lfile(tab).curr(); } + //@cmember Testa la presenza di un record senza spostare il cursore + int test(TIsamop op = _isequal, TReclock lockop = _nolock) const; // @cmember Legge il record TRecnotype read(TIsamop op = _isgteq, TReclock lockop = _nolock, TDate& atdate = (TDate&)botime); // @cmember Mette un lock sul record diff --git a/include/sheet.cpp b/include/sheet.cpp index 8b9f6e845..8c755e0ce 100755 --- a/include/sheet.cpp +++ b/include/sheet.cpp @@ -413,7 +413,7 @@ XI_OBJ* TSheet_control::find_column( { char str[80]; xi_get_text(column[c], str, sizeof(str)); - if (stricmp(str, head) == 0) + if (strcmp(str, head) == 0) break; } return c >= 0 ? column[c] : NULL;