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
This commit is contained in:
guy 1994-11-03 12:46:49 +00:00
parent ddfee1f32c
commit e664d27004
10 changed files with 103 additions and 80 deletions

View File

@ -113,7 +113,8 @@ void TBanner::handler(WINDOW win, EVENT* ep)
set_font(FF_TIMES, FS_BOLD | FS_ITALIC, BIGY); set_font(FF_TIMES, FS_BOLD | FS_ITALIC, BIGY);
char* t = (char*)(const char*)main_app().title(); char* t = (char*)(const char*)main_app().title();
int w = win_get_text_width(win, t, -1); 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); win_draw_text(win, x+1, y+1, t, -1);
set_color(COLOR_BLACK, COLOR_LTGRAY); set_color(COLOR_BLACK, COLOR_LTGRAY);
win_draw_text(win, x, y, t, -1); 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); set_pen(COLOR_BLACK); win_draw_rect(win, &r);
offset_rect(&r, 1, 1); offset_rect(&r, 1, 1);
set_pen(COLOR_WHITE); win_draw_rect(win, &r); set_pen(COLOR_WHITE); win_draw_rect(win, &r);
win_draw_icon(win, CHARX<<1, CHARX<<1, ICON_RSRC); win_draw_icon(win, CHARX<<1, CHARX<<1, ICON_RSRC);
} }
else else

View File

@ -593,7 +593,7 @@ TPush_button::TPush_button(short left, short top, short right, short bottom,
_accel *= CHARX; _accel *= CHARX;
_dx = (right-left-strlen(caption())*CHARX) >> 1; _dx = (right-left-strlen(caption())*CHARX) >> 1;
_dy = byte(height+BASEY) >> 1; _dy = (byte)CHARY;
} }
} }

View File

@ -1,6 +1,6 @@
#ifndef APPNAME #ifndef APPNAME
#define APPNAME CAMPO #define APPNAME PRASSI
#define QAPPNAME "CAMPO" #define QAPPNAME "PRASSI"
#define LIBDIR c:\xvt.322\xvtwin\lib #define LIBDIR c:\xvt.322\xvtwin\lib
#endif #endif

View File

@ -151,12 +151,10 @@ void TMask::handler(WINDOW win, EVENT* ep)
case DLG_F9: case DLG_F9:
{ {
WINDOW w = ep->v.ctl.ci.win; WINDOW w = ep->v.ctl.ci.win;
TMask_field* f = (TMask_field*)get_app_data(w);
w = f->win();
if (test_focus_change(w)) if (test_focus_change(w))
{ f->on_key(K_F9); // Attiva ricerca sul campo associato al bottone
// Attiva ricerca sul campo associato al bottone
TMask_field* f = (TMask_field*)get_app_data(w);
f->on_key(K_F9);
}
} }
break; break;
default: default:
@ -421,7 +419,7 @@ void TMask::start_run()
{ {
TMask_field& f = fld(i); TMask_field& f = fld(i);
if ((f.active() || f.ghost()) && 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.set_dirty(FALSE);
f.on_hit(); f.on_hit();
@ -433,7 +431,7 @@ void TMask::start_run()
{ {
TMask_field& f = fld(i); TMask_field& f = fld(i);
if (mode() == MODE_QUERY && f.is_edit() && f.in_key(1) && 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); f.set_dirty(TRUE);
else else
{ {

View File

@ -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 <xvt.h> #include <xvt.h>
#include <applicat.h> #include <applicat.h>
@ -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"; const bool all = what == "AL";
if (all || what == "US") if (all || what == "US")
{ {
set_insert(b->get_insert()); set_insert(b.get_insert());
_filter = b->get_filter(); _filter = b.get_filter();
if (field()._warning.empty())
field()._warning = b.field()._warning;
if (!all) return TRUE; if (!all) return TRUE;
} }
if (all || what == "IN") if (all || what == "IN")
{ {
_inp_id = b->_inp_id; _inp_id = b._inp_id;
_inp_fn = b->_inp_fn; _inp_fn = b._inp_fn;
if (!all) return TRUE; if (!all) return TRUE;
} }
if (all || what == "DI") if (all || what == "DI")
{ {
_head = b->_head; _head = b._head;
_items = b->_items; _items = b._items;
if (!all) return TRUE; if (!all) return TRUE;
} }
if (all || what == "OU") if (all || what == "OU")
{ {
_out_id = b->_out_id; _out_id = b._out_id;
_out_fn = b->_out_fn; _out_fn = b._out_fn;
_secondary = TRUE; _secondary = TRUE;
} }
return TRUE; return TRUE;
@ -1300,7 +1302,7 @@ bool TBrowse::do_insert()
} }
#if XVT_OS == XVT_OS_WIN #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); app.insert("a", 3);
#endif #endif
@ -1356,7 +1358,7 @@ TToken_string& TBrowse::create_siblings(TToken_string& siblings)
const TCursor* c = b->cursor(); const TCursor* c = b->cursor();
// Considera ricerche sullo stesso file ma con chiave diversa // 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())) (key[c->key()] == FALSE || id == _fld->dlg()))
{ {
const TString16 fn(_out_fn.get(n)); // Legge nome del campo su file const TString16 fn(_out_fn.get(n)); // Legge nome del campo su file
@ -1413,8 +1415,7 @@ KEY TBrowse::run()
long selected = 0; long selected = 0;
TToken_string siblings; TToken_string siblings;
if (_inp_id.items() == 1) create_siblings(siblings);
create_siblings(siblings);
{ {
TToken_string* sib = siblings.empty() ? NULL : &siblings; TToken_string* sib = siblings.empty() ? NULL : &siblings;
@ -1480,7 +1481,7 @@ bool TBrowse::check(CheckTime t)
else else
{ {
do_clear(); 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(); const TBrowse* b = (const TBrowse*)f.browse();
#ifdef DBG #ifdef DBG
if (b == NULL) 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 #endif
return b; return b;
} }
@ -1660,7 +1661,7 @@ bool TEdit_field::parse_item(TScanner& scanner)
_browse = new TBrowse(this, b->cursor()); _browse = new TBrowse(this, b->cursor());
if (_browse) if (_browse)
return _browse->parse_copy(what, b); return _browse->parse_copy(what, *b);
#ifdef DBG #ifdef DBG
return yesnofatal_box("Impossibile COPY senza USE nel campo %d", dlg()); 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) if (fpark.len() > _size)
{ {
#ifdef DBG #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 #endif
fpark.cut(_size); fpark.cut(_size);
} }
@ -2420,13 +2421,8 @@ bool TReal_field::on_key(KEY key)
{ {
const char* n = get(); const char* n = get();
if (*n && !real::is_real(n)) if (*n && !real::is_real(n))
return error_box("Numero non valido"); return error_box("Valore numerico non valido");
if (_flags.uppercase && real(n).sign() < 0)
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("Il numero deve essere positivo"); return error_box("Il numero deve essere positivo");
} }
} }

View File

@ -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 #ifndef __MASKFLD_H
#define __MASKFLD_H #define __MASKFLD_H
@ -64,13 +64,13 @@ protected:
struct TField_Flags struct TField_Flags
{ {
bool automagic : 1; bool automagic : 1;
bool dirty : 1; // Modified during run ? bool dirty : 2; // Modified during run ?
bool enabled : 1; // Is editable bool enabled : 1; // Is editable
bool enable_default : 1; bool enable_default : 1;
bool firm : 1; // Is the current firm ? bool firm : 1; // Is the current firm ?
bool focusdirty : 1; // Modified during focus ? bool focusdirty : 1; // Modified during focus ?
bool ghost : 1; bool ghost : 1;
bool persistent : 1; bool persistent : 1;
bool rightjust : 1; bool rightjust : 1;
bool roman : 1; // Is a Roman number ? bool roman : 1; // Is a Roman number ?
bool showed : 1; // Is visible bool showed : 1; // Is visible
@ -207,14 +207,15 @@ class TEdit_field : public TMask_field
{ {
friend class TBrowse; friend class TBrowse;
friend class TList_sheet; friend class TList_sheet;
friend class TBrowse_sheet;
protected: protected:
// @DPROT // @DPROT
TString80 _str; TString80 _str;
TString16 _picture; TString16 _picture;
TString _warning; TString _warning;
CheckType _check; // Accettabilita' di valori nulli CheckType _check; // Accettabilita' di valori nulli
bool _forced; bool _forced;
bool _check_enabled; // Abilitato bool _check_enabled; // Abilitato
TBrowse* _browse; TBrowse* _browse;
@ -292,6 +293,7 @@ protected:
TToken_string& create_siblings(TToken_string& siblings); TToken_string& create_siblings(TToken_string& siblings);
public: public:
int inputs() { return _inp_id.items(); }
int do_input(bool filter = FALSE); // Serve ai TCursor_sheet int do_input(bool filter = FALSE); // Serve ai TCursor_sheet
TBrowse(TEdit_field* f, TRelation* r, int key = 1, const char* filter = ""); TBrowse(TEdit_field* f, TRelation* r, int key = 1, const char* filter = "");
@ -303,13 +305,13 @@ public:
void parse_display(TScanner& scanner); void parse_display(TScanner& scanner);
void parse_output(TScanner& scanner); void parse_output(TScanner& scanner);
void parse_insert(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;} void set_insert(const char* s) { _insert = s;}
const TString& get_insert() const { return _insert;} const TString& get_insert() const { return _insert;}
const TString& get_filter() const { return _filter;} const TString& get_filter() const { return _filter;}
TEdit_field& field() {return *_fld;} TEdit_field& field() const { return *_fld; }
bool check(CheckTime = RUNNING_CHECK); bool check(CheckTime = RUNNING_CHECK);
bool empty_check(); bool empty_check();

View File

@ -492,14 +492,21 @@ if (xiev->v.xi_obj->type == XIT_LIST)
case XIE_DBL_CELL: case XIE_DBL_CELL:
{ {
_check_enabled = FALSE; _check_enabled = FALSE;
const int oldrow = _cur_row;
_cur_row = row2rec(xiev->v.xi_obj->v.cell.row); _cur_row = row2rec(xiev->v.xi_obj->v.cell.row);
_cur_col = xiev->v.xi_obj->v.cell.column; _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); const KEY k = edit(_cur_row);
if (k == K_ENTER) if (k == K_ENTER)
{ {
update_rec(_cur_row); update_rec(_cur_row);
_row_dirty = TRUE; _row_dirty = TRUE;
} }
if (!cell_disabled(_cur_row, _cur_col)) if (!cell_disabled(_cur_row, _cur_col))
set_focus_cell(_cur_row, _cur_col); set_focus_cell(_cur_row, _cur_col);
_check_enabled = TRUE; _check_enabled = TRUE;
@ -507,7 +514,7 @@ if (xiev->v.xi_obj->type == XIT_LIST)
break; break;
case XIE_ON_LIST: case XIE_ON_LIST:
if (_firstfocus) // Trick to avoid the sheet to keep the focus forever ... 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; xiev->refused = TRUE;
_firstfocus = FALSE; _firstfocus = FALSE;
} }
@ -769,7 +776,7 @@ bool TSpreadsheet::on_key(KEY k)
if (k == 'A') n++; if (k == 'A') n++;
if (n < 0) n = 0; else 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 if (notify(n, K_INS) == FALSE) // Chiede l'ok alla applicazione
return FALSE; return FALSE;
@ -778,7 +785,10 @@ bool TSpreadsheet::on_key(KEY k)
k = K_INS; // Inserimento in corso 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 set_front_window(win()); // Aggiorna sheet a video
open(); open();
@ -962,7 +972,7 @@ bool TSpreadsheet::notify(int n, KEY k)
{ {
const bool ok = _notify ? _notify(n, k) : TRUE; const bool ok = _notify ? _notify(n, k) : TRUE;
if (k == K_ENTER) if (k == K_ENTER)
set_dirty(ok ? TRUE : 2); set_dirty(ok ? TRUE : 3);
return ok; return ok;
} }
@ -976,15 +986,12 @@ KEY TSpreadsheet::edit(int n, KEY tasto)
{ {
const int olditems = items(); const int olditems = items();
str2mask(n); str2mask(n);
notify(n, K_SPACE); // Notifica intenzione di modificare
const KEY k = _mask.run(); const KEY k = _mask.run();
if (k == K_ENTER) if (k == K_ENTER)
{ {
mask2str(n); mask2str(n);
notify(n, K_ENTER);
} else } else
if (k == K_DEL) if (k == K_DEL)
{ {

View File

@ -638,13 +638,16 @@ TBrowse_sheet::TBrowse_sheet(TCursor* cursor, const char* fields,
: TCursor_sheet(cursor, fields, title, head, buttons), _field(f) : TCursor_sheet(cursor, fields, title, head, buttons), _field(f)
{ {
if (field().browse()->inputs() == 1)
{
#if XVT_OS == XVT_OS_WIN #if XVT_OS == XVT_OS_WIN
xvt_create_control(WC_EDIT, 1, -3, f->size()+1, 1, f->get(), win(), xvt_create_control(WC_EDIT, 1, -3, f->size()+1, 1, f->get(), win(),
CTL_FLAG_DISABLED, 0L, 100); CTL_FLAG_DISABLED, 0L, 100);
#else #else
xvt_create_control(WC_EDIT, 1, -3, f->size()+2, 1, f->get(), win(), xvt_create_control(WC_EDIT, 1, -3, f->size()+2, 1, f->get(), win(),
CTL_FLAG_DISABLED, 0L, 100); CTL_FLAG_DISABLED, 0L, 100);
#endif #endif
}
if (s && s->items() > 2) if (s && s->items() > 2)
{ {
@ -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) 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); 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 long oldsel = selected();
// const TString80 old(_field->get()); const bool corre = field().mask().is_running();
WINDOW fwin = get_ctl_window(_field->parent(), _field->dlg()); const WINDOW fldwin = field().win();
TString80 old;
get_title(fwin, (char *) (const char *) old, 80);
old.ltrim();
TString80 old(corre ? field().get_window_data() : field().get_field_data());
TString80 val(ztrim(old));
TString80 val((const char*)old);
if (alnum) if (alnum)
{ {
if (val.len() >= field().size()) if (val.len() >= field().size())
@ -724,23 +732,28 @@ bool TBrowse_sheet::on_key(KEY k)
val << char(k); val << char(k);
} }
else val.rtrim(1); 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); ((TBrowse*)field().browse())->do_input(FALSE);
_cursor->read(); _cursor->read();
if (_cursor->file().bad()) if (_cursor->file().bad())
{ {
beep(); beep();
// field().set(val = old);
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; *_cursor = oldsel;
} }
else else
select(_cursor->pos()); 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; return TRUE;
} }
else else

View File

@ -154,7 +154,7 @@ public:
virtual TString& format(const char* fmt, ...); virtual TString& format(const char* fmt, ...);
const TString& operator =(const TString& s) { return set((const char*)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); }
void strncpy(const char* s, int n); void strncpy(const char* s, int n);
}; };
@ -164,8 +164,9 @@ class TString16 : public TFixed_string
public: public:
TString16(const char* str = "") : TFixed_string(_str16, 17) { set(str); } 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 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 class TString80 : public TFixed_string
@ -174,8 +175,9 @@ class TString80 : public TFixed_string
public: public:
TString80(const char* str = "") : TFixed_string(_str80, 81) { set(str); } 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 TString& s) { return set((const char*)s); }
const TString& operator=(const char* s) { return set(s); }
}; };
class TString256 : public TFixed_string class TString256 : public TFixed_string
@ -184,8 +186,9 @@ class TString256 : public TFixed_string
public: public:
TString256(const char* str = "") : TFixed_string(_str256, 257) { set(str); } 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 TString& s) { return set((const char*)s); }
const TString& operator=(const char* s) { return set(s); }
}; };
@ -200,8 +203,10 @@ public:
// @FPUB // @FPUB
TFilename(const char* n = "") : TString80(n) {} 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 char* s) { return set(s); }
const TString& operator =(const TString& s) { return set((const char*)s); }
// assegnazione tra TFile e stringa // assegnazione tra TFile e stringa
const char* ext() const; // Ritorna l'estensione const char* ext() const; // Ritorna l'estensione

View File

@ -28,7 +28,7 @@ HIDDEN bool _expr_val(TEdit_field& f, KEY)
const char* s = e.varname(i); const char* s = e.varname(i);
if (s[0] != '#') 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); return f.error_box((const char*)err);
} }
s++; s++;