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>
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__);
}

View File

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

View File

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

View File

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

View File

@ -42,7 +42,7 @@ protected:
public:
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]; }
word fields() const { return _item.items(); }
@ -112,6 +112,7 @@ public:
TRelation* relation() const { return _relation; }
TCursor* cursor() const { return _cursor; }
virtual const char* validate(const char* cur, TToken_string& val);
TForm(const char* form);
virtual ~TForm();

View File

@ -1958,8 +1958,8 @@ HIDDEN void __getfieldbuff(byte l, byte t, const char* recin, char *s)
if (l)
{
strncpy(s, recin, l);
while (s[--l] == ' ');
l++;
for (int i = l-1; i >= 0 && s[i] == ' '; i--);
l = byte(i+1);
}
s[l] = '\0';
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 <applicat.h>
@ -19,9 +19,7 @@
#include <windows.h>
#endif
HIDDEN const int MAXSTR = 128;
HIDDEN char __fpark[MAXSTR]; // Temporary for get/set window data
HIDDEN TFixed_string fpark(__fpark, MAXSTR);
HIDDEN TString256 fpark;
///////////////////////////////////////////////////////////
// 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::_y;
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)
: _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)
{
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
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
#if XVT_OS == XVT_OS_WIN
char* k = strchr(_prompt, '~');
if (k != NULL) *k = '&';
const int k = _prompt.find('~');
if (k >= 0) _prompt[k] = '&';
#endif
_promptwin = xvt_create_control
(
@ -321,7 +319,7 @@ void TMask_field::destroy()
// Certified 100%
void TMask_field::create(WINDOW parent)
{
_width = strlen(_prompt);
_width = _prompt.len();
if (_width)
wincreate(WC_TEXT, _width, 1, _prompt, parent, CTL_FLAG_LEFT_JUST);
}
@ -393,7 +391,7 @@ void TMask_field::set_dirty(bool d)
// Certified 99%
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())
{
a << ' ';
for (const char* f = m; f; f++)
for (const char* f = m; *f; f++)
{
if (*f == '#')
{
@ -577,24 +575,26 @@ void TMask_field::send_key(KEY k, short to)
// Certified 90%
bool TMask_field::do_message(int num)
{
const int MAX_CMD = 15;
const int MAX_CMD = 17;
static const char* commands[MAX_CMD] =
{
"ADD", // 0
"CLEAR", // 1
"CO", // 2
"DEL", // 3
"DIRTY", // 4
"DISABLE", // 5
"ENABLE", // 6
"ENABLEDEF", // 7
"EXIT", // 8
"HIDE", // 9
"PUSH", // 10
"RESET", // 11
"RU", // 12
"SHOW", // 13
"UNDO" // 14
"ADD", // 0
"CLEAR", // 1
"CO", // 2
"DEL", // 3
"DIRTY", // 4
"DISABLE", // 5
"ENABLE", // 6
"ENABLEDEF", // 7
"EXIT", // 8
"HIDE", // 9
"NORMAL", // 10
"PUSH", // 11
"REQUIRED", // 12
"RESET", // 13
"RU", // 14
"SHOW", // 15
"UNDO" // 16
};
TToken_string* message = (TToken_string*)_message.objptr(num);
@ -608,7 +608,6 @@ bool TMask_field::do_message(int num)
KEY key = 0;
msg = m;
value = msg.get();
// value.trim(); // TBR
const char* dlg = msg.get();
int cmd = -1;
@ -635,7 +634,7 @@ bool TMask_field::do_message(int num)
mask().stop_run(atoi(dlg));
continue;
} else
if (cmd == 12)
if (cmd == 14)
{
run_app(mask(), msg);
continue;
@ -666,12 +665,16 @@ bool TMask_field::do_message(int num)
case 9:
key = 11000+'h'; break;
case 10:
key = K_SPACE; break;
mask().efield(fld).check_type(CHECK_NORMAL); continue;
case 11:
key = K_F2; break;
key = K_SPACE; break;
case 12:
mask().efield(fld).check_type(CHECK_REQUIRED); continue;
case 13:
key = K_F2; break;
case 15:
key = 11000+'s'; break;
case 14:
case 16:
key = K_F3; break;
default:
key = atoi(value);
@ -2067,7 +2070,10 @@ bool TEdit_field::on_key(KEY key)
if (_sheet) ok = query || _sheet->check(); // Check consistency
else
if (check_enabled() && _browse && (!query || forced()))
if (_browse &&
check_enabled() &&
(!query || forced()) &&
_validate_func != 21) // 21 = NOT_EMPTY_CHECK_FIELD
ok = _browse->check();
if (!ok)
@ -2109,17 +2115,18 @@ bool TEdit_field::on_key(KEY key)
const bool query = mask().query_mode();
// check consistency
if (_sheet) ok = query || _sheet->check(FINAL_CHECK);
else if (_browse && check_enabled())
{
if (!query || forced())
if (_sheet) ok = query || _sheet->check(FINAL_CHECK);
else
if (_browse &&
check_enabled() &&
_validate_func != 21 &&
(!query || forced()))
{
if (dirty()) ok = _browse->check(FINAL_CHECK); // Check consistency
else ok = _browse->empty_check();
}
}
else
ok = query || !(check_type() == CHECK_REQUIRED && get().empty());
else
ok = query || !(check_type() == CHECK_REQUIRED && get().empty());
if (!ok)
return default_error_box();
@ -2198,7 +2205,7 @@ word TBoolean_field::class_id() const
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
#define __MASKFLD_H
@ -44,7 +44,7 @@ protected:
// @DPROT
static int _x, _y; // Coordinate of the control
static int _width; // Size of the control
static TFixed_string _prompt;// Prompt of the field
static TString80 _prompt;
CONTROL_HANDLER _handler;
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>
HIDDEN const int MAXSTR = 301;
HIDDEN char __spark[MAXSTR]; // Utility buffer
TFixed_string spark(__spark, MAXSTR);
class TString512 : public TFixed_string
{
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)
{ return c >= '\t' && c <= ' '; }
@ -126,13 +161,13 @@ TString& TString::operator <<(double n)
// Appends an object to the string
// Certified 50%
// The object should be completely storable in __spark
// The object should be completely storable in spark
TString& TString::operator <<(const TObject& obj)
{
ostrstream out(__spark, MAXSTR);
ostrstream out((char*)(const char*)spark, spark.size());
obj.print_on(out);
out << ends;
return operator <<(__spark);
return operator <<(spark);
}
@ -418,17 +453,17 @@ TString& TString::picture(const char* pic, const char* s)
return *this;
}
// Certified 90% (__spark size limited)
// Certified 90% (spark size limited)
TString& TString::format(const char* fmt, ...)
{
va_list pars;
va_start(pars, fmt);
const int tot = vsprintf(__spark, fmt, pars);
const int tot = vsprintf((char*)(const char*)spark, fmt, pars);
va_end(pars);
CHECK(tot >= 0 && tot < spark.size(), "Ue'! Quanto scrivi?");
if (tot > size()) resize(tot, FALSE);
strcpy(_str, __spark);
strcpy(_str, spark);
return *this;
}
@ -496,7 +531,12 @@ word TString::hash() const
// Certified 100%
TFixed_string::TFixed_string(const char* str, int size)
: 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)
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)
{
if (!f.to_check(k) || f.get().empty())
return TRUE;
else
{
const CheckType c = f.check_type();
f.check_type(CHECK_NORMAL);
const bool ok = f.check();
f.check_type(c);
return ok;
}
const bool ok = (f.to_check(k) && f.get().not_empty()) ? f.check() : TRUE;
return ok;
}

View File

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