corretti maskfld e isam e validate

git-svn-id: svn://10.65.10.50/trunk@986 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
guy 1995-02-09 14:47:31 +00:00
parent 6215837eea
commit ce400ee43c
12 changed files with 162 additions and 130 deletions

View File

@ -452,7 +452,7 @@ void TApplication::about() const
{ {
#include <prassi.ver> #include <prassi.ver>
const TFilename n(__argv[0]); const TFilename n(__argv[0]);
message_box("PRASSI Versione %4.2f\nProgramma %s\nLibreria del %s", message_box("PRASSI Versione %s\nProgramma %s\nLibreria del %s",
VERSION, (const char*)n.name(), __DATE__); VERSION, (const char*)n.name(), __DATE__);
} }

View File

@ -4,6 +4,7 @@
#ifdef FOXPRO #ifdef FOXPRO
#undef XVT_OS #undef XVT_OS
#include <windows.h>
#include <pro_ext.h> #include <pro_ext.h>
#endif #endif
@ -196,6 +197,7 @@ int error_box(const char* fmt, ...)
int fatal_box(const char* fmt, ...) int fatal_box(const char* fmt, ...)
{ {
MessageBeep(MB_ICONHAND);
buildmsg(); buildmsg();
_UserError(msg); _UserError(msg);
return 0; return 0;

View File

@ -6,24 +6,13 @@
#ifndef FOXPRO #ifndef FOXPRO
#include <expr.h> #include <expr.h>
#endif
#ifndef __EXTCDECL_H
#include <extcdecl.h>
#endif
#ifndef __APPLICAT_H
#include <applicat.h> #include <applicat.h>
#endif #else
#ifndef __STRINGS_H
#include <strings.h> #include <strings.h>
#endif #endif
#ifndef __UTILITY_H #include <extcdecl.h>
#include <utility.h> #include <utility.h>
#endif
#define BLOCKLEN 512 #define BLOCKLEN 512
#define INVFLD 255 #define INVFLD 255
@ -34,8 +23,7 @@ TFile::TFile (int lenrec, int base)
{ {
_file = new SecDef; _file = new SecDef;
if (_file == NULL) // if (_file == NULL) fatal_box ("Can't allocate record file ");
fatal_box ("Can't allocate record file ");
_file->IOR = NOERR; _file->IOR = NOERR;
_len = lenrec; _len = lenrec;
_base = base; _base = base;
@ -233,20 +221,11 @@ int TDir::items (TDirtype dirtype) const
return (int) f.EOD; return (int) f.EOD;
} }
bool TDir::is_active () const
{
int module = (int) flags();
if (module < 0) module = -module;
return main_app().has_module(module, CHK_DONGLE);
}
TTrec::TTrec () TTrec::TTrec ()
{ {
_rec = new RecDes; _rec = new RecDes;
if (_rec == NULL) // if (_rec == NULL) fatal_box ("Can't allocate record description");
fatal_box ("Can't allocate record description");
zero (); zero ();
_num = -1; _num = -1;
} }
@ -355,6 +334,14 @@ const char *TTrec ::keydef (int key) const
#ifndef FOXPRO #ifndef FOXPRO
bool TDir::is_active () const
{
int module = (int) flags();
if (module < 0) module = -module;
return main_app().has_module(module, CHK_DONGLE);
}
void TTrec::update_fielddef (int nfld, const char *desc) void TTrec::update_fielddef (int nfld, const char *desc)
{ {

View File

@ -102,7 +102,7 @@ class TForm_item : public TObject
TString _desc; TString _desc;
TForm_flags _flag; TForm_flags _flag;
TBit_array _group; TBit_array _group;
TArray _message; TString_array _message;
protected: protected:
int _x, _y, _width, _height; int _x, _y, _width, _height;
@ -140,7 +140,7 @@ public:
virtual void read_from(const TMask& m); virtual void read_from(const TMask& m);
bool edit(TMask& m); bool edit(TMask& m);
TPrint_section* section() const { return _section; } TPrint_section& section() const { return *_section; }
bool in_group(byte g) const { return g == 0 || _group[g]; } bool in_group(byte g) const { return g == 0 || _group[g]; }
const TString& key() const { return _desc; } const TString& key() const { return _desc; }
@ -197,12 +197,9 @@ void TForm_item::print_body(ostream& out) const
out << " GROUP " << _group << "\n"; out << " GROUP " << _group << "\n";
out << _flag; out << _flag;
if (_message.items() == 1) if (_message.items() == 1)
{ out << " MESSAGE " << (TToken_string&)_message[0] << endl;
const char* m = (TToken_string&)_message[0];
out << " MESSAGE " << m << endl;
}
} }
@ -226,7 +223,7 @@ bool TForm_item::parse_item(TScanner& scanner)
message(0).add(m); message(0).add(m);
return TRUE; return TRUE;
} }
if (scanner.key() == "KE") if (scanner.key() == "KE")
{ {
_desc = scanner.string(); _desc = scanner.string();
@ -269,8 +266,8 @@ void TForm_item::string_at(int x, int y, const char* s)
{ {
if (hidden()) return; if (hidden()) return;
_section->offset(x, y); section().offset(x, y);
TPrintrow& row = _section->row(y-1); // Seleziona riga di stampa TPrintrow& row = section().row(y-1); // Seleziona riga di stampa
if (_width > 0 && strlen(s) > (word)_width) // Tronca testo se necessario if (_width > 0 && strlen(s) > (word)_width) // Tronca testo se necessario
{ {
@ -309,7 +306,7 @@ void TForm_item::send_message(const TString& cmd, TForm_item& des) const
} else } else
if (cmd == "APPEND") if (cmd == "APPEND")
{ {
TString80 val = des.get(); TString256 val = des.get();
if (val.not_empty()) val << ' '; if (val.not_empty()) val << ' ';
val << get(); val << get();
des.set(val); des.set(val);
@ -326,17 +323,17 @@ void TForm_item::send_message(const TString& cmd, TForm_item& des) const
{ {
des.hide(); des.hide();
} else } else
if (cmd == "SHOW") if (cmd == "RESET")
{ {
des.show(); des.set("");
} else } else
if (cmd == "RESET") if (cmd == "SHOW")
{ {
des.set(""); des.show();
} else } else
if (cmd[0] == '"') if (cmd[0] == '"')
{ {
TString80 val(cmd); TString256 val(cmd);
val.strip("\""); val.strip("\"");
des.set(val); des.set(val);
} else } else
@ -354,16 +351,24 @@ bool TForm_item::do_message(int num)
for (const char* m = messaggio.get(0); m; m = messaggio.get()) for (const char* m = messaggio.get(0); m; m = messaggio.get())
{ {
msg = m; msg = m;
const TString16 cmd = msg.get(); // Get command if (*m == '_')
const word id = msg.get_int(); // Get destination group
// Send the message to all fields with the given group
for (word i = 0; i < section()->fields(); i++)
{ {
TForm_item& des = section()->field(i); const char* s = section().form().validate(get(), msg);
if (des.in_group(id)) if (s) set(s);
send_message(cmd, des);
} }
else
{
const TString16 cmd(msg.get()); // Get command
const word id = msg.get_int(); // Get destination group
// Send the message to all fields with the given group
for (word i = 0; i < section().fields(); i++)
{
TForm_item& des = section().field(i);
if (des.in_group(id))
send_message(cmd, des);
}
}
} }
return TRUE; return TRUE;
@ -400,7 +405,7 @@ void TForm_item::print_on(TMask& m)
m.set(F_HEIGHT, _height); m.set(F_HEIGHT, _height);
_flag.print_on(m); _flag.print_on(m);
for (int g = 1; g <= 12; g++) for (int g = 1; g <= 24; g++)
m.set(F_GROUP+g, _group[g] ? "X" : " "); m.set(F_GROUP+g, _group[g] ? "X" : " ");
} }
@ -415,7 +420,7 @@ void TForm_item::read_from(const TMask& m)
_flag.read_from(m); _flag.read_from(m);
_group.reset(); _group.reset();
for (int g = 1; g <= 12; g++) for (int g = 1; g <= 24; g++)
_group.set(g, m.get_bool(F_GROUP+g)); _group.set(g, m.get_bool(F_GROUP+g));
} }
@ -543,7 +548,7 @@ bool TForm_string::read()
if (_field.items()) if (_field.items())
{ {
const char* s = ""; const char* s = "";
const TRelation* r = section()->form()->relation(); const TRelation* r = section().form().relation();
for (int i = 0; i < _field.items(); i++) for (int i = 0; i < _field.items(); i++)
{ {
s = field(i).read(r); s = field(i).read(r);
@ -909,12 +914,14 @@ bool TPrint_section::parse(TScanner& scanner)
return TRUE; return TRUE;
} }
// Azzera tutte le righe della sezione di stampa
void TPrint_section::reset() void TPrint_section::reset()
{ {
for (word i = 0; i < height(); i++) for (word i = 0; i < height(); i++)
row(i).reset(); row(i).reset();
} }
// Aggiorna tutti i campi e li stampa
bool TPrint_section::update() bool TPrint_section::update()
{ {
bool ok = TRUE; bool ok = TRUE;
@ -925,11 +932,7 @@ bool TPrint_section::update()
const bool esito = field(i).update(); const bool esito = field(i).update();
if (!esito) ok = FALSE; if (!esito) ok = FALSE;
} }
#ifdef DBG
const int l = last()-1;
if (l >= (int)_height)
warning_box("Sezione troppo lunga: %d > %d", l+1, _height);
#endif
return ok; return ok;
} }
@ -1287,7 +1290,10 @@ void TForm::print_section(ostream& out, char s) const
out << "END\n" << endl; out << "END\n" << endl;
} }
} }
} }
const char* TForm::validate(const char*, TToken_string&)
{ return NULL; }
void TForm::print_on(ostream& out) const void TForm::print_on(ostream& out) const
{ {

View File

@ -42,7 +42,7 @@ protected:
public: public:
TPrintrow& row(int num); TPrintrow& row(int num);
TForm* form() const { return _form; } TForm& form() const { return *_form; }
TForm_item& field(int n) const { return (TForm_item&)_item[n]; } TForm_item& field(int n) const { return (TForm_item&)_item[n]; }
word fields() const { return _item.items(); } word fields() const { return _item.items(); }
@ -112,6 +112,7 @@ public:
TRelation* relation() const { return _relation; } TRelation* relation() const { return _relation; }
TCursor* cursor() const { return _cursor; } TCursor* cursor() const { return _cursor; }
virtual const char* validate(const char* cur, TToken_string& val);
TForm(const char* form); TForm(const char* form);
virtual ~TForm(); virtual ~TForm();

View File

@ -1958,8 +1958,8 @@ HIDDEN void __getfieldbuff(byte l, byte t, const char* recin, char *s)
if (l) if (l)
{ {
strncpy(s, recin, l); strncpy(s, recin, l);
while (s[--l] == ' '); for (int i = l-1; i >= 0 && s[i] == ' '; i--);
l++; l = byte(i+1);
} }
s[l] = '\0'; s[l] = '\0';
if (t == _datefld && *s) if (t == _datefld && *s)

View File

@ -1,4 +1,4 @@
// $Id: maskfld.cpp,v 1.76 1995-02-09 08:13:46 villa Exp $ // $Id: maskfld.cpp,v 1.77 1995-02-09 14:47:20 guy Exp $
#include <xvt.h> #include <xvt.h>
#include <applicat.h> #include <applicat.h>
@ -19,9 +19,7 @@
#include <windows.h> #include <windows.h>
#endif #endif
HIDDEN const int MAXSTR = 128; HIDDEN TString256 fpark;
HIDDEN char __fpark[MAXSTR]; // Temporary for get/set window data
HIDDEN TFixed_string fpark(__fpark, MAXSTR);
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
// Field Flags // Field Flags
@ -93,7 +91,7 @@ char TMask_field::TField_Flags::update(const char* s)
int TMask_field::_x; // Position of the field int TMask_field::_x; // Position of the field
int TMask_field::_y; int TMask_field::_y;
int TMask_field::_width; int TMask_field::_width;
TFixed_string TMask_field::_prompt(__fpark, MAXSTR); // Prompt of the field TString80 TMask_field::_prompt;
TMask_field::TMask_field(TMask* m) TMask_field::TMask_field(TMask* m)
: _mask(m), _win(NULL_WIN), _promptwin(NULL_WIN), _dlg(0), : _mask(m), _win(NULL_WIN), _promptwin(NULL_WIN), _dlg(0),
@ -282,7 +280,7 @@ WINDOW TMask_field::parent() const
int TMask_field::create_prompt(WINDOW parent, int width, int heigth) int TMask_field::create_prompt(WINDOW parent, int width, int heigth)
{ {
const WIN_TYPE wt = (heigth < 3) ? WC_TEXT : WC_GROUPBOX; const WIN_TYPE wt = (heigth < 3) ? WC_TEXT : WC_GROUPBOX;
if (width < 1) width = strlen(_prompt); if (width < 1) width = _prompt.len();
_prompt.rtrim(); // Could save some bytes _prompt.rtrim(); // Could save some bytes
if (width) if (width)
@ -290,8 +288,8 @@ int TMask_field::create_prompt(WINDOW parent, int width, int heigth)
const long flags = default_flags() & (~CTL_FLAG_DISABLED); // Static controls shouldn't be grayed const long flags = default_flags() & (~CTL_FLAG_DISABLED); // Static controls shouldn't be grayed
#if XVT_OS == XVT_OS_WIN #if XVT_OS == XVT_OS_WIN
char* k = strchr(_prompt, '~'); const int k = _prompt.find('~');
if (k != NULL) *k = '&'; if (k >= 0) _prompt[k] = '&';
#endif #endif
_promptwin = xvt_create_control _promptwin = xvt_create_control
( (
@ -321,7 +319,7 @@ void TMask_field::destroy()
// Certified 100% // Certified 100%
void TMask_field::create(WINDOW parent) void TMask_field::create(WINDOW parent)
{ {
_width = strlen(_prompt); _width = _prompt.len();
if (_width) if (_width)
wincreate(WC_TEXT, _width, 1, _prompt, parent, CTL_FLAG_LEFT_JUST); wincreate(WC_TEXT, _width, 1, _prompt, parent, CTL_FLAG_LEFT_JUST);
} }
@ -393,7 +391,7 @@ void TMask_field::set_dirty(bool d)
// Certified 99% // Certified 99%
const char* TMask_field::get_window_data() const const char* TMask_field::get_window_data() const
{ {
return get_title(win(), __fpark, MAXSTR); return get_title(win(), (char*)(const char*)fpark, fpark.size());
} }
@ -551,7 +549,7 @@ HIDDEN void run_app(const TMask& mask, TToken_string& msg)
for (const char* m = msg.get(); m; m = msg.get()) for (const char* m = msg.get(); m; m = msg.get())
{ {
a << ' '; a << ' ';
for (const char* f = m; f; f++) for (const char* f = m; *f; f++)
{ {
if (*f == '#') if (*f == '#')
{ {
@ -577,24 +575,26 @@ void TMask_field::send_key(KEY k, short to)
// Certified 90% // Certified 90%
bool TMask_field::do_message(int num) bool TMask_field::do_message(int num)
{ {
const int MAX_CMD = 15; const int MAX_CMD = 17;
static const char* commands[MAX_CMD] = static const char* commands[MAX_CMD] =
{ {
"ADD", // 0 "ADD", // 0
"CLEAR", // 1 "CLEAR", // 1
"CO", // 2 "CO", // 2
"DEL", // 3 "DEL", // 3
"DIRTY", // 4 "DIRTY", // 4
"DISABLE", // 5 "DISABLE", // 5
"ENABLE", // 6 "ENABLE", // 6
"ENABLEDEF", // 7 "ENABLEDEF", // 7
"EXIT", // 8 "EXIT", // 8
"HIDE", // 9 "HIDE", // 9
"PUSH", // 10 "NORMAL", // 10
"RESET", // 11 "PUSH", // 11
"RU", // 12 "REQUIRED", // 12
"SHOW", // 13 "RESET", // 13
"UNDO" // 14 "RU", // 14
"SHOW", // 15
"UNDO" // 16
}; };
TToken_string* message = (TToken_string*)_message.objptr(num); TToken_string* message = (TToken_string*)_message.objptr(num);
@ -608,7 +608,6 @@ bool TMask_field::do_message(int num)
KEY key = 0; KEY key = 0;
msg = m; msg = m;
value = msg.get(); value = msg.get();
// value.trim(); // TBR
const char* dlg = msg.get(); const char* dlg = msg.get();
int cmd = -1; int cmd = -1;
@ -635,7 +634,7 @@ bool TMask_field::do_message(int num)
mask().stop_run(atoi(dlg)); mask().stop_run(atoi(dlg));
continue; continue;
} else } else
if (cmd == 12) if (cmd == 14)
{ {
run_app(mask(), msg); run_app(mask(), msg);
continue; continue;
@ -666,12 +665,16 @@ bool TMask_field::do_message(int num)
case 9: case 9:
key = 11000+'h'; break; key = 11000+'h'; break;
case 10: case 10:
key = K_SPACE; break; mask().efield(fld).check_type(CHECK_NORMAL); continue;
case 11: case 11:
key = K_F2; break; key = K_SPACE; break;
case 12:
mask().efield(fld).check_type(CHECK_REQUIRED); continue;
case 13: case 13:
key = K_F2; break;
case 15:
key = 11000+'s'; break; key = 11000+'s'; break;
case 14: case 16:
key = K_F3; break; key = K_F3; break;
default: default:
key = atoi(value); key = atoi(value);
@ -2067,7 +2070,10 @@ bool TEdit_field::on_key(KEY key)
if (_sheet) ok = query || _sheet->check(); // Check consistency if (_sheet) ok = query || _sheet->check(); // Check consistency
else else
if (check_enabled() && _browse && (!query || forced())) if (_browse &&
check_enabled() &&
(!query || forced()) &&
_validate_func != 21) // 21 = NOT_EMPTY_CHECK_FIELD
ok = _browse->check(); ok = _browse->check();
if (!ok) if (!ok)
@ -2109,17 +2115,18 @@ bool TEdit_field::on_key(KEY key)
const bool query = mask().query_mode(); const bool query = mask().query_mode();
// check consistency // check consistency
if (_sheet) ok = query || _sheet->check(FINAL_CHECK); if (_sheet) ok = query || _sheet->check(FINAL_CHECK);
else if (_browse && check_enabled()) else
{ if (_browse &&
if (!query || forced()) check_enabled() &&
_validate_func != 21 &&
(!query || forced()))
{ {
if (dirty()) ok = _browse->check(FINAL_CHECK); // Check consistency if (dirty()) ok = _browse->check(FINAL_CHECK); // Check consistency
else ok = _browse->empty_check(); else ok = _browse->empty_check();
} }
} else
else ok = query || !(check_type() == CHECK_REQUIRED && get().empty());
ok = query || !(check_type() == CHECK_REQUIRED && get().empty());
if (!ok) if (!ok)
return default_error_box(); return default_error_box();
@ -2198,7 +2205,7 @@ word TBoolean_field::class_id() const
void TBoolean_field::create(WINDOW parent) void TBoolean_field::create(WINDOW parent)
{ {
wincreate(WC_CHECKBOX, strlen(_prompt)+4, 1, _prompt, parent, 0); wincreate(WC_CHECKBOX, _prompt.len()+4, 1, _prompt, parent, 0);
} }

View File

@ -1,4 +1,4 @@
/* $Id: maskfld.h,v 1.23 1995-02-09 08:13:51 villa Exp $ */ /* $Id: maskfld.h,v 1.24 1995-02-09 14:47:24 guy Exp $ */
#ifndef __MASKFLD_H #ifndef __MASKFLD_H
#define __MASKFLD_H #define __MASKFLD_H
@ -44,7 +44,7 @@ protected:
// @DPROT // @DPROT
static int _x, _y; // Coordinate of the control static int _x, _y; // Coordinate of the control
static int _width; // Size of the control static int _width; // Size of the control
static TFixed_string _prompt;// Prompt of the field static TString80 _prompt;
CONTROL_HANDLER _handler; CONTROL_HANDLER _handler;
int _size; // Max length of the string int _size; // Max length of the string

View File

@ -1 +1 @@
#define VERSION 1.5 #define VERSION "1.1.5"

View File

@ -20,9 +20,44 @@
#include <utility.h> #include <utility.h>
HIDDEN const int MAXSTR = 301; class TString512 : public TFixed_string
HIDDEN char __spark[MAXSTR]; // Utility buffer {
TFixed_string spark(__spark, MAXSTR); char _str512[513];
public:
TString512(const char* s = "") : TFixed_string(_str512, 513) { set(s); }
TString512(const TString& s) : TFixed_string(_str512, 513) { set(s); }
const TString& operator =(const char* s);
const TString& operator =(const TString& s) { return operator =((const char*)s); }
void strncpy(const char* s, int n);
};
const TString& TString512::operator =(const char* s)
{
#ifdef FOXPRO
if (_size == 0)
{
_str = _str512;
_size = 512;
}
#endif
return set(s);
}
void TString512::strncpy(const char* s, int n)
{
#ifdef FOXPRO
if (_size == 0)
{
_str = _str512;
_size = 512;
}
#endif
TFixed_string::strncpy(s, n);
}
HIDDEN TString512 spark;
inline bool is_space(char c) inline bool is_space(char c)
{ return c >= '\t' && c <= ' '; } { return c >= '\t' && c <= ' '; }
@ -126,13 +161,13 @@ TString& TString::operator <<(double n)
// Appends an object to the string // Appends an object to the string
// Certified 50% // Certified 50%
// The object should be completely storable in __spark // The object should be completely storable in spark
TString& TString::operator <<(const TObject& obj) TString& TString::operator <<(const TObject& obj)
{ {
ostrstream out(__spark, MAXSTR); ostrstream out((char*)(const char*)spark, spark.size());
obj.print_on(out); obj.print_on(out);
out << ends; out << ends;
return operator <<(__spark); return operator <<(spark);
} }
@ -418,17 +453,17 @@ TString& TString::picture(const char* pic, const char* s)
return *this; return *this;
} }
// Certified 90% (__spark size limited) // Certified 90% (spark size limited)
TString& TString::format(const char* fmt, ...) TString& TString::format(const char* fmt, ...)
{ {
va_list pars; va_list pars;
va_start(pars, fmt); va_start(pars, fmt);
const int tot = vsprintf(__spark, fmt, pars); const int tot = vsprintf((char*)(const char*)spark, fmt, pars);
va_end(pars); va_end(pars);
CHECK(tot >= 0 && tot < spark.size(), "Ue'! Quanto scrivi?"); CHECK(tot >= 0 && tot < spark.size(), "Ue'! Quanto scrivi?");
if (tot > size()) resize(tot, FALSE); if (tot > size()) resize(tot, FALSE);
strcpy(_str, __spark); strcpy(_str, spark);
return *this; return *this;
} }
@ -496,7 +531,12 @@ word TString::hash() const
// Certified 100% // Certified 100%
TFixed_string::TFixed_string(const char* str, int size) TFixed_string::TFixed_string(const char* str, int size)
: TString((char*)str, (size < 1) ? strlen(str) : size-1) : TString((char*)str, (size < 1) ? strlen(str) : size-1)
{ {
CHECK(str, "NULL buffer for fixed string");
if (size == 301)
message_box("Lavori in corso");
if (size > 0 && memchr(str, '\0', size) == NULL) if (size > 0 && memchr(str, '\0', size) == NULL)
cut(0); cut(0);
} }

View File

@ -616,17 +616,8 @@ HIDDEN bool _alpha_val(TEdit_field& f, KEY k)
HIDDEN bool _not_empty_chkfld_val(TEdit_field& f, KEY k) HIDDEN bool _not_empty_chkfld_val(TEdit_field& f, KEY k)
{ {
if (!f.to_check(k) || f.get().empty()) const bool ok = (f.to_check(k) && f.get().not_empty()) ? f.check() : TRUE;
return TRUE; return ok;
else
{
const CheckType c = f.check_type();
f.check_type(CHECK_NORMAL);
const bool ok = f.check();
f.check_type(c);
return ok;
}
} }

View File

@ -299,10 +299,8 @@ void TWindow::handler(WINDOW win, EVENT* ep)
stop_run(K_ESC); stop_run(K_ESC);
break; break;
case E_UPDATE: case E_UPDATE:
{
clear_window(win, NORMAL_BACK_COLOR); clear_window(win, NORMAL_BACK_COLOR);
update(); update();
}
break; break;
case E_CHAR: case E_CHAR:
on_key(e_char_to_key(ep)); on_key(e_char_to_key(ep));