classes.h Aggiunta classe GRID_FIELD_CLASS

config.cpp   Sostituita una TString16 con un const char*
form.cpp     Corretta gestione picture contenente @
mask.cpp     Corretta gestione menu pop-up
maskfld.cpp  Corretta gestione ricerche usando il nuovo metodo test dei cursori
relapp.cpp   Accetta cambio maschera anche si passa da insert a insert
relation.cpp Aggiunto fighissimo metodo test ai cursori
sheet.cpp    Sostituita stricmp con strcmp nel salavataggio colonne


git-svn-id: svn://10.65.10.50/trunk@3986 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
guy 1996-12-10 08:28:14 +00:00
parent ceb86a9c6b
commit 29d9bff0d9
10 changed files with 172 additions and 136 deletions

View File

@ -47,6 +47,7 @@
#define CLASS_EDIT_FIELD 244 #define CLASS_EDIT_FIELD 244
#define CLASS_REAL_FIELD 245 #define CLASS_REAL_FIELD 245
#define CLASS_DATE_FIELD 246 #define CLASS_DATE_FIELD 246
#define CLASS_GRID_FIELD 247
#define CLASS_GOLEM 900 #define CLASS_GOLEM 900

View File

@ -346,7 +346,7 @@ bool TConfig::get_bool(
// @xref <mf TConfig::get> <mf TConfig::get_long> <mf TConfig::get_int> // @xref <mf TConfig::get> <mf TConfig::get_long> <mf TConfig::get_int>
// <mf TConfig::get_color> // <mf TConfig::get_color>
{ {
const TString16 d(def ? "X" : ""); const char* d = def ? "X" : "";
const TString& s = get(var, section, index, d).upper(); const TString& s = get(var, section, index, d).upper();
return s != "" && (s == "X" || s == "ON" || s == "YES" || s == "OK" || s == "TRUE"); return s != "" && (s == "X" || s == "ON" || s == "YES" || s == "OK" || s == "TRUE");
} }

View File

@ -1572,9 +1572,8 @@ void TForm_number::apply_format(real& n , TString& s) const
} }
} }
int comma = pic.find(','); const int at = pic.find('@');
int at = pic.find('@'); if (at > 0)
if (at >= 0 && comma <0)
{ {
const int len = atoi(&pic[at+1]); const int len = atoi(&pic[at+1]);
if (len > 0) if (len > 0)

View File

@ -635,7 +635,7 @@ void TMask::handler(WINDOW win, EVENT* ep)
{ {
TSheet_field& sht = (TSheet_field&)*_last_sheet; TSheet_field& sht = (TSheet_field&)*_last_sheet;
#if (XVT_PTK_VERSION_MAJOR > 4) || (XVT_PTK_VERSION_MAJOR == 4 && XVT_PTK_VERSION_MINOR >= 50) #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) if (menu)
{ {
const PNT& p = ep->v.mouse.where; 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) if (p.h > 2 * cr.right / 3)
pa = XVT_POPUP_RIGHT_ALIGN; 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); xvt_res_free_menu_tree(menu);
} }
#else #else

View File

@ -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()) for (TString16 fld = _out_id.get(0); fld.not_empty(); fld = _out_id.get())
{ {
@ -2068,7 +2068,7 @@ void TBrowse::do_clear()
f.reset(); f.reset();
s_checked.set(id); s_checked.set(id);
f.on_hit(); f.on_hit();
f.check(); f.check(t);
} }
} }
} }
@ -2238,6 +2238,8 @@ TToken_string& TBrowse::create_siblings(TToken_string& siblings)
KEY TBrowse::run() KEY TBrowse::run()
{ {
begin_wait();
do_input(TRUE); do_input(TRUE);
_cursor->read(_isgteq); _cursor->read(_isgteq);
@ -2286,6 +2288,8 @@ KEY TBrowse::run()
} }
} }
end_wait();
TBrowse_sheet s(_cursor, _items, caption, _head, buttons, &field(), siblings); TBrowse_sheet s(_cursor, _items, caption, _head, buttons, &field(), siblings);
k = s.run(); k = s.run();
selected = s.selected(); selected = s.selected();
@ -2368,9 +2372,12 @@ bool TBrowse::check(CheckTime t)
const int ne = do_input(TRUE); const int ne = do_input(TRUE);
if (ne || chk == CHECK_REQUIRED) if (ne || chk == CHECK_REQUIRED)
{ {
/* Guy: vecchio modo
_cursor->setkey(); _cursor->setkey();
_cursor->file().read(_isequal); _cursor->file().read(_isequal);
passed = _cursor->ok(); passed = _cursor->ok();
*/
passed = _cursor->test() == NOERR;
if (t != FINAL_CHECK) if (t != FINAL_CHECK)
{ {
@ -2387,7 +2394,7 @@ bool TBrowse::check(CheckTime t)
} }
else else
{ {
do_clear(); do_clear(t);
if (!field().mask().query_mode() && field().check_enabled()) if (!field().mask().query_mode() && field().check_enabled())
field().set_dirty(3); field().set_dirty(3);
} }
@ -2406,7 +2413,7 @@ bool TBrowse::check(CheckTime t)
else else
{ {
if (t != FINAL_CHECK) if (t != FINAL_CHECK)
do_clear(); do_clear(t);
} }
} }
} }

View File

@ -805,7 +805,7 @@ class TBrowse : public TBrowse_button
// @access Protected Member // @access Protected Member
protected: protected:
// @cmember Azzera i campi di output sulla maschera // @cmember Azzera i campi di output sulla maschera
void do_clear(); void do_clear(CheckTime t);
// @cmember Chiama la maschera di gestione della ricerca // @cmember Chiama la maschera di gestione della ricerca
bool do_link(bool insert); bool do_link(bool insert);

View File

@ -315,46 +315,36 @@ void TRelation_application::query_mode(
void TRelation_application::insert_mode() void TRelation_application::insert_mode()
{ {
if (_mask->query_mode()) bool try_auto = TRUE;
{
if (test_key(1, FALSE) == FALSE)
{
if (!autonum(_mask, FALSE))
{
query_insert_mode();
return;
}
}
const bool changing = changing_mask(MODE_INS); if (_mask->query_mode())
TFilename workname; workname.temp("msk"); try_auto = test_key(1, FALSE) == FALSE;
if (changing)
{ if (try_auto && !autonum(_mask, FALSE))
_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
{ {
if (!autonum(_mask, FALSE)) query_insert_mode();
{ return;
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();
} }
set_mode(MODE_INS); set_mode(MODE_INS);
get_relation()->zero(); // Azzera tutta la relazione! get_relation()->zero(); // Azzera tutta la relazione!
init_insert_mode(*_mask); init_insert_mode(*_mask);
} }

View File

@ -580,48 +580,46 @@ int TRelation::position_rels(
TLocalisamfile& to = file(rd.link()); TLocalisamfile& to = file(rd.link());
TReclock lck = rd._allow_lock ? lockop : _nolock; TReclock lck = rd._allow_lock ? lockop : _nolock;
TRectype& furr = from.curr();
furr.zero();
if (to.curr().empty()) if (to.curr().empty())
{ from.zero(); continue; } continue;
from.setkey(rd._key); from.setkey(rd._key);
from.curr().zero();
// build record // 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];
const char* expr = rd.evaluate_expr(j, to); s.write(expr, furr);
TFieldref& s = (TFieldref&) rd._fields[j]; } // for each field
s.write(expr, from.curr());
} // for each field
}
// read record: if not found, zero current record // read record: if not found, zero current record
const TRectype rec(from.curr());
from.read(op, lck, atdate); from.read(op, lck, atdate);
if (from.bad()) if (from.bad())
{ {
rd._first_match = (from.curr() == rec); bool eq = TRUE;
if (rd._first_match) for (int kk = 0; eq && kk < rd._fields.items(); kk++)
{ {
bool eq = TRUE; TFieldref& fl = (TFieldref&)rd._fields[kk];
const TString80 f_fr(fl.read(furr));
for (int kk = 0; eq && kk < rd._fields.items(); kk++) const TString80 f_ex(rd.evaluate_expr(kk, to));
{ if (rd._forced[kk])
if (rd._forced[kk]) eq = f_fr == f_ex;
{ else
TFieldref& fl = (TFieldref&)rd._fields[kk]; eq = f_fr.compare(f_ex, f_ex.len());
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(); }
} }
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 } // for each relation
return _errors; return _errors;
} }
@ -1010,25 +1008,34 @@ int TCursor::filtercursor(int pagecnt, TRecnotype* page)
bool TCursor::ok() const bool TCursor::ok() const
{ {
if (file().bad()) return FALSE; if (file().bad())
return FALSE;
const TRectype& rec = file().curr(); const TRectype& rec = file().curr();
TString key(rec.key(_nkey)), kf(from()), kt(to());
const TFixed_string key(rec.key(_nkey));
const TString& kf = from();
const TString& kt = to();
if (file().tab()) if (file().tab())
{ {
key.ltrim(3); if (key.compare(kf, 3) < 0 || (kt.not_empty() && kt.compare(key, 3) < 0))
kf.ltrim(3); return FALSE;
kt.ltrim(3); }
else
{
if (key < kf || (kt.not_empty() && kt.compare(key, kt.len()) < 0))
return FALSE;
} }
if (key < (const char *) kf || (kt.not_empty() && kt < (const char *) key.left(kt.len()))) if (update_relation())
return FALSE; _if->update();
if (update_relation()) _if->update();
if ((_filterfunction ? _filterfunction(_if) : TRUE ) && if ((_filterfunction ? _filterfunction(_if) : TRUE ) &&
(_fexpr ? __evalcondition(*_if, _fexpr) : TRUE)) (_fexpr ? __evalcondition(*_if, _fexpr) : TRUE))
return TRUE; return TRUE;
return FALSE; return FALSE;
} }
@ -1140,7 +1147,6 @@ void TCursor::filter(
} }
void TCursor::setkey(int nkey) void TCursor::setkey(int nkey)
{ {
if (nkey != _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 TCursor::read(TIsamop op, TReclock lockop, TDate& atdate)
{ {
TRecnotype *page; int err = test(op, lockop);
int pagecnt; TLocalisamfile& curfile = file();
const TRecnotype curpos = curfile.recno();
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();
if (changed()) if (changed())
_totrec = update(); _totrec = update();
if (approx && _if->file().status() == _iseof)
if (err != NOERR)
{ {
_pos = _totrec - 1; _pos = _totrec - 1;
if (_pos < 0) if (_pos < 0)
{ {
file().zero(); curfile.zero();
file().setstatus(_isemptyfile); err = _isemptyfile;
} }
else else
{
readrec(); readrec();
file().setstatus(_iseof); curfile.setstatus(err);
}
return _pos;
} }
else
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)
{ {
pagecnt = (max < CMAXELPAGE) ? (int)max : CMAXELPAGE; FILE* _f = open_index();
fread(page, sizeof(TRecnotype), pagecnt, _f);
for (int i = 0; i < pagecnt; i++) if (fseek(_f, 0L, SEEK_SET) != 0)
if (page[i] == curpos) fatal_box("Can't repos cursor : File %d\n", file().filehnd()->ln);
{
_pos = _totrec - max + i; TRecnotype *page = new TRecnotype [CMAXELPAGE];
break; int pagecnt;
}
} _pos = -1;
if (_pos == -1) _pos = 0; for (TRecnotype max = _totrec; _pos == -1 && max > 0; max -= pagecnt)
delete page; {
fclose(_f); 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);
if (_pos < 0L)
_pos = 0L;
readrec();
}
readrec();
return _pos; return _pos;
} }

View File

@ -448,6 +448,8 @@ public:
// @cmember Ritorna il descrittore della tabella // @cmember Ritorna il descrittore della tabella
TRectype& curr(const char * tab) const TRectype& curr(const char * tab) const
{ return _if->lfile(tab).curr(); } { 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 // @cmember Legge il record
TRecnotype read(TIsamop op = _isgteq, TReclock lockop = _nolock, TDate& atdate = (TDate&)botime); TRecnotype read(TIsamop op = _isgteq, TReclock lockop = _nolock, TDate& atdate = (TDate&)botime);
// @cmember Mette un lock sul record // @cmember Mette un lock sul record

View File

@ -413,7 +413,7 @@ XI_OBJ* TSheet_control::find_column(
{ {
char str[80]; char str[80];
xi_get_text(column[c], str, sizeof(str)); xi_get_text(column[c], str, sizeof(str));
if (stricmp(str, head) == 0) if (strcmp(str, head) == 0)
break; break;
} }
return c >= 0 ? column[c] : NULL; return c >= 0 ? column[c] : NULL;