1994-11-10 14:17:03 +00:00
|
|
|
#include <ctype.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include <applicat.h>
|
|
|
|
#include <form.h>
|
1994-12-27 14:59:25 +00:00
|
|
|
#include <msksheet.h>
|
1994-11-10 14:17:03 +00:00
|
|
|
#include <relation.h>
|
|
|
|
#include <sheet.h>
|
|
|
|
#include <utility.h>
|
|
|
|
|
1995-01-12 10:45:51 +00:00
|
|
|
#include "../ba/ba2100.h"
|
1994-11-10 14:17:03 +00:00
|
|
|
|
1994-12-20 15:11:26 +00:00
|
|
|
static TForm* _form = NULL;
|
|
|
|
|
|
|
|
static TForm& form()
|
|
|
|
{
|
|
|
|
CHECK(_form, "Can't print NULL form");
|
|
|
|
return *_form;
|
|
|
|
}
|
|
|
|
|
1994-11-10 14:17:03 +00:00
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// TForm_flags
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
struct TForm_flags : public TObject
|
|
|
|
{
|
|
|
|
bool automagic : 1;
|
1994-12-15 18:06:43 +00:00
|
|
|
bool enabled : 1;
|
|
|
|
bool shown : 1;
|
1994-11-10 14:17:03 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void print_on(ostream& out) const;
|
|
|
|
|
|
|
|
public:
|
|
|
|
TForm_flags();
|
|
|
|
|
1994-12-20 15:11:26 +00:00
|
|
|
void print_on(TMask& m);
|
|
|
|
void read_from(const TMask& m);
|
1994-11-10 14:17:03 +00:00
|
|
|
|
|
|
|
bool update(const char* s);
|
|
|
|
};
|
|
|
|
|
|
|
|
TForm_flags::TForm_flags()
|
|
|
|
{
|
1994-12-15 18:06:43 +00:00
|
|
|
automagic = FALSE;
|
|
|
|
shown = enabled = TRUE;
|
1994-11-10 14:17:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool TForm_flags::update(const char* s)
|
|
|
|
{
|
|
|
|
for (; *s; s++) switch(toupper(*s))
|
|
|
|
{
|
1994-12-15 18:06:43 +00:00
|
|
|
case 'A':
|
|
|
|
automagic = TRUE; break;
|
|
|
|
case 'D':
|
|
|
|
enabled = FALSE; break;
|
|
|
|
case 'H':
|
|
|
|
shown = FALSE; break;
|
|
|
|
default :
|
|
|
|
error_box("Unknown form item flag '%c'", *s); break;
|
|
|
|
}
|
1994-11-10 14:17:03 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
1994-12-20 15:11:26 +00:00
|
|
|
|
1994-11-10 14:17:03 +00:00
|
|
|
void TForm_flags::print_on(ostream& out) const
|
|
|
|
{
|
1994-12-07 18:03:51 +00:00
|
|
|
TString16 s;
|
1994-11-10 14:17:03 +00:00
|
|
|
|
|
|
|
if (automagic) s << "A";
|
1994-12-15 18:06:43 +00:00
|
|
|
if (!enabled) s << "D";
|
|
|
|
if (!shown) s << "H";
|
1994-11-10 14:17:03 +00:00
|
|
|
|
1994-12-27 14:59:25 +00:00
|
|
|
if (s.not_empty())
|
|
|
|
out << " FLAGS \"" << s << '"' << endl;
|
1994-11-10 14:17:03 +00:00
|
|
|
}
|
|
|
|
|
1994-12-20 15:11:26 +00:00
|
|
|
|
|
|
|
void TForm_flags::print_on(TMask& m)
|
1994-11-10 14:17:03 +00:00
|
|
|
{
|
1994-12-15 18:06:43 +00:00
|
|
|
m.set(F_DISABLED, enabled ? " " : "X");
|
|
|
|
m.set(F_HIDDEN, shown ? " " : "X");
|
1994-11-10 14:17:03 +00:00
|
|
|
m.set(F_AUTOMAGIC, automagic ? "X" : " ");
|
|
|
|
}
|
|
|
|
|
1994-12-20 15:11:26 +00:00
|
|
|
|
|
|
|
void TForm_flags::read_from(const TMask& m)
|
1994-11-10 14:17:03 +00:00
|
|
|
{
|
1994-12-15 18:06:43 +00:00
|
|
|
shown = !m.get_bool(F_HIDDEN);
|
|
|
|
enabled = !m.get_bool(F_DISABLED);
|
1994-11-10 14:17:03 +00:00
|
|
|
automagic = m.get_bool(F_AUTOMAGIC);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// TForm_item
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
class TForm_item : public TObject
|
|
|
|
{
|
|
|
|
TPrint_section* _section;
|
|
|
|
TString _desc;
|
|
|
|
TForm_flags _flag;
|
|
|
|
TBit_array _group;
|
1995-02-09 14:47:31 +00:00
|
|
|
TString_array _message;
|
1994-11-10 14:17:03 +00:00
|
|
|
|
|
|
|
protected:
|
1994-12-15 18:06:43 +00:00
|
|
|
int _x, _y, _width, _height;
|
1994-11-10 14:17:03 +00:00
|
|
|
TString _prompt;
|
|
|
|
|
|
|
|
virtual void print_on(ostream& out) const;
|
|
|
|
virtual void print_body(ostream& out) const;
|
|
|
|
|
|
|
|
int width() const { return _width; }
|
1994-12-15 18:06:43 +00:00
|
|
|
int height() const { return _height; }
|
1994-11-10 14:17:03 +00:00
|
|
|
|
1994-12-15 18:06:43 +00:00
|
|
|
bool shown() const { return _flag.shown; }
|
|
|
|
bool hidden() const { return !_flag.shown; }
|
|
|
|
bool enabled() const { return _flag.enabled; }
|
|
|
|
bool disabled() const { return !_flag.enabled; }
|
1994-11-10 14:17:03 +00:00
|
|
|
bool automagic() const { return !_flag.automagic; }
|
|
|
|
|
|
|
|
virtual bool parse_head(TScanner&);
|
|
|
|
virtual bool parse_item(TScanner&);
|
|
|
|
|
|
|
|
virtual const char* get() const { return _prompt; }
|
|
|
|
virtual bool set(const char* s) { _prompt = s; return TRUE; }
|
|
|
|
|
|
|
|
TToken_string& message(int m = 0);
|
1994-12-15 18:06:43 +00:00
|
|
|
void send_message(const TString& cmd, TForm_item& dest) const;
|
1994-11-10 14:17:03 +00:00
|
|
|
bool do_message(int m = 0);
|
|
|
|
|
|
|
|
void string_at(int x, int y, const char* s);
|
|
|
|
|
|
|
|
public:
|
|
|
|
virtual bool parse(TScanner&);
|
|
|
|
virtual bool update();
|
|
|
|
|
1994-12-20 15:11:26 +00:00
|
|
|
virtual void print_on(TMask& m);
|
|
|
|
virtual void read_from(const TMask& m);
|
|
|
|
bool edit(TMask& m);
|
1994-11-10 14:17:03 +00:00
|
|
|
|
1995-02-09 14:47:31 +00:00
|
|
|
TPrint_section& section() const { return *_section; }
|
1994-11-10 14:17:03 +00:00
|
|
|
|
|
|
|
bool in_group(byte g) const { return g == 0 || _group[g]; }
|
|
|
|
const TString& key() const { return _desc; }
|
1994-12-27 14:59:25 +00:00
|
|
|
void print_on(TToken_string& row) const;
|
1994-11-10 14:17:03 +00:00
|
|
|
|
1994-12-15 18:06:43 +00:00
|
|
|
void show(bool on = TRUE) { _flag.shown = on; }
|
1994-11-10 14:17:03 +00:00
|
|
|
void hide() { show(FALSE); }
|
|
|
|
void enable(bool on = TRUE);
|
|
|
|
void disable() { enable(FALSE); }
|
|
|
|
|
|
|
|
TForm_item(TPrint_section* section);
|
1995-01-02 09:33:00 +00:00
|
|
|
virtual ~TForm_item() {}
|
1994-11-10 14:17:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
TForm_item::TForm_item(TPrint_section* section)
|
1994-12-15 18:06:43 +00:00
|
|
|
: _section(section), _x(-1), _y(-1), _width(0), _height(0)
|
1994-11-10 14:17:03 +00:00
|
|
|
{}
|
|
|
|
|
1994-12-20 15:11:26 +00:00
|
|
|
|
1994-11-10 14:17:03 +00:00
|
|
|
bool TForm_item::parse_head(TScanner& scanner)
|
|
|
|
{
|
|
|
|
_width = scanner.integer();
|
1994-12-15 18:06:43 +00:00
|
|
|
if (_width) _height = scanner.integer();
|
1994-11-10 14:17:03 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
1994-12-20 15:11:26 +00:00
|
|
|
|
1994-11-10 14:17:03 +00:00
|
|
|
void TForm_item::print_on(ostream& out) const
|
|
|
|
{
|
|
|
|
out << class_name();
|
|
|
|
if (_width > 0)
|
|
|
|
{
|
|
|
|
out << ' ' << _width;
|
1994-12-15 18:06:43 +00:00
|
|
|
if (_height > 0)
|
|
|
|
out << ' ' << _height;
|
1994-11-10 14:17:03 +00:00
|
|
|
}
|
|
|
|
out << "\nBEGIN\n";
|
|
|
|
|
|
|
|
print_body(out);
|
|
|
|
|
|
|
|
out << "END\n" << endl;
|
|
|
|
}
|
|
|
|
|
1994-12-20 15:11:26 +00:00
|
|
|
|
1994-11-10 14:17:03 +00:00
|
|
|
void TForm_item::print_body(ostream& out) const
|
|
|
|
{
|
1995-01-02 09:33:00 +00:00
|
|
|
out << " KEY \"" << _desc << "\"\n";
|
|
|
|
|
1994-11-10 14:17:03 +00:00
|
|
|
if (_y >= 0)
|
|
|
|
out << " PROMPT " << _x << ' ' << _y << " \"" << _prompt << "\"\n";
|
|
|
|
|
|
|
|
if (_group.ones())
|
|
|
|
out << " GROUP " << _group << "\n";
|
|
|
|
|
|
|
|
out << _flag;
|
1995-02-09 14:47:31 +00:00
|
|
|
|
1994-11-10 14:17:03 +00:00
|
|
|
if (_message.items() == 1)
|
1995-02-09 14:47:31 +00:00
|
|
|
out << " MESSAGE " << (TToken_string&)_message[0] << endl;
|
1994-11-10 14:17:03 +00:00
|
|
|
}
|
|
|
|
|
1994-12-20 15:11:26 +00:00
|
|
|
|
1994-11-10 14:17:03 +00:00
|
|
|
bool TForm_item::parse_item(TScanner& scanner)
|
|
|
|
{
|
|
|
|
if (scanner.key() == "PR")
|
|
|
|
{
|
|
|
|
_x = scanner.integer();
|
|
|
|
_y = scanner.integer();
|
|
|
|
_prompt = scanner.string();
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (scanner.key() == "FL")
|
|
|
|
return _flag.update(scanner.string());
|
|
|
|
|
|
|
|
if (scanner.key() == "ME")
|
|
|
|
{
|
1994-12-07 18:03:51 +00:00
|
|
|
TFixed_string m(scanner.line());
|
1994-11-10 14:17:03 +00:00
|
|
|
m.strip_spaces();
|
|
|
|
message(0).add(m);
|
|
|
|
return TRUE;
|
|
|
|
}
|
1995-02-09 14:47:31 +00:00
|
|
|
|
1994-11-10 14:17:03 +00:00
|
|
|
if (scanner.key() == "KE")
|
|
|
|
{
|
|
|
|
_desc = scanner.string();
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (scanner.key() == "GR")
|
|
|
|
{
|
|
|
|
_group.set(scanner.line());
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
1994-12-15 18:06:43 +00:00
|
|
|
yesnofatal_box("Unknown symbol in item '%s': '%s'",
|
|
|
|
(const char*)key(), (const char*)scanner.token());
|
1994-11-10 14:17:03 +00:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TForm_item::parse(TScanner& scanner)
|
|
|
|
{
|
1994-12-15 18:06:43 +00:00
|
|
|
bool ok = parse_head(scanner);
|
1994-11-10 14:17:03 +00:00
|
|
|
|
|
|
|
if (ok && scanner.popkey() != "BE")
|
1994-12-15 18:06:43 +00:00
|
|
|
ok = yesnofatal_box("Missing BEGIN in form item %s", (const char*)key());
|
1994-11-10 14:17:03 +00:00
|
|
|
|
|
|
|
while (ok && scanner.popkey() != "EN")
|
|
|
|
ok = parse_item(scanner);
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TForm_item::enable(bool on)
|
|
|
|
{
|
1994-12-15 18:06:43 +00:00
|
|
|
_flag.enabled = on;
|
|
|
|
show(on);
|
1994-11-10 14:17:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TForm_item::string_at(int x, int y, const char* s)
|
|
|
|
{
|
|
|
|
if (hidden()) return;
|
1995-01-09 16:51:21 +00:00
|
|
|
|
1995-02-09 14:47:31 +00:00
|
|
|
section().offset(x, y);
|
|
|
|
TPrintrow& row = section().row(y-1); // Seleziona riga di stampa
|
1994-11-10 14:17:03 +00:00
|
|
|
|
|
|
|
if (_width > 0 && strlen(s) > (word)_width) // Tronca testo se necessario
|
|
|
|
{
|
|
|
|
strncpy(__tmp_string, s, width());
|
|
|
|
__tmp_string[width()] = '\0';
|
|
|
|
s = __tmp_string;
|
|
|
|
}
|
1995-01-09 16:51:21 +00:00
|
|
|
row.put(s, x-1); // Stampa testo
|
1994-11-10 14:17:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TToken_string& TForm_item::message(int m)
|
|
|
|
{
|
|
|
|
TToken_string* t = (TToken_string*)_message.objptr(m);
|
|
|
|
if (t == NULL)
|
|
|
|
{
|
|
|
|
t = new TToken_string(16);
|
|
|
|
_message.add(t, m);
|
|
|
|
}
|
|
|
|
return *t;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1994-12-15 18:06:43 +00:00
|
|
|
void TForm_item::send_message(const TString& cmd, TForm_item& des) const
|
1994-11-10 14:17:03 +00:00
|
|
|
{
|
|
|
|
if (cmd == "ADD" || cmd == "SUM" || cmd == "INC")
|
|
|
|
{
|
1995-01-09 16:51:21 +00:00
|
|
|
const real n((cmd[0] == 'I') ? "1.0" : get());
|
1994-12-15 18:06:43 +00:00
|
|
|
real r(des.get());
|
1994-11-10 14:17:03 +00:00
|
|
|
r += n;
|
1994-12-15 18:06:43 +00:00
|
|
|
des.set(r.string());
|
1994-11-10 14:17:03 +00:00
|
|
|
} else
|
|
|
|
if (cmd == "COPY")
|
|
|
|
{
|
1994-12-15 18:06:43 +00:00
|
|
|
des.set(get());
|
1994-11-10 14:17:03 +00:00
|
|
|
} else
|
|
|
|
if (cmd == "APPEND")
|
|
|
|
{
|
1995-02-09 14:47:31 +00:00
|
|
|
TString256 val = des.get();
|
1994-11-10 14:17:03 +00:00
|
|
|
if (val.not_empty()) val << ' ';
|
|
|
|
val << get();
|
1994-12-15 18:06:43 +00:00
|
|
|
des.set(val);
|
1994-11-10 14:17:03 +00:00
|
|
|
} else
|
|
|
|
if (cmd == "DISABLE")
|
|
|
|
{
|
1994-12-15 18:06:43 +00:00
|
|
|
des.disable();
|
1994-11-10 14:17:03 +00:00
|
|
|
} else
|
|
|
|
if (cmd == "ENABLE")
|
|
|
|
{
|
1994-12-15 18:06:43 +00:00
|
|
|
des.enable();
|
1994-11-10 14:17:03 +00:00
|
|
|
} else
|
|
|
|
if (cmd == "HIDE")
|
|
|
|
{
|
1994-12-15 18:06:43 +00:00
|
|
|
des.hide();
|
1994-11-10 14:17:03 +00:00
|
|
|
} else
|
1995-02-09 14:47:31 +00:00
|
|
|
if (cmd == "RESET")
|
1994-11-10 14:17:03 +00:00
|
|
|
{
|
1995-02-09 14:47:31 +00:00
|
|
|
des.set("");
|
|
|
|
} else
|
|
|
|
if (cmd == "SHOW")
|
1994-11-10 14:17:03 +00:00
|
|
|
{
|
1995-02-09 14:47:31 +00:00
|
|
|
des.show();
|
1994-11-10 14:17:03 +00:00
|
|
|
} else
|
|
|
|
if (cmd[0] == '"')
|
|
|
|
{
|
1995-02-09 14:47:31 +00:00
|
|
|
TString256 val(cmd);
|
1994-11-10 14:17:03 +00:00
|
|
|
val.strip("\"");
|
1994-12-15 18:06:43 +00:00
|
|
|
des.set(val);
|
1994-11-10 14:17:03 +00:00
|
|
|
} else
|
|
|
|
error_box("Unknown message in item '%s': '%s'",
|
|
|
|
(const char*)key(), (const char*)cmd);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool TForm_item::do_message(int num)
|
|
|
|
{
|
1994-12-15 18:06:43 +00:00
|
|
|
TToken_string& messaggio = message(num);
|
|
|
|
if (messaggio.empty()) return FALSE;
|
1994-11-10 14:17:03 +00:00
|
|
|
|
|
|
|
TToken_string msg(16, ',');
|
1994-12-15 18:06:43 +00:00
|
|
|
for (const char* m = messaggio.get(0); m; m = messaggio.get())
|
1994-11-10 14:17:03 +00:00
|
|
|
{
|
|
|
|
msg = m;
|
1995-02-09 14:47:31 +00:00
|
|
|
if (*m == '_')
|
1994-11-10 14:17:03 +00:00
|
|
|
{
|
1995-02-09 14:47:31 +00:00
|
|
|
const char* s = section().form().validate(get(), msg);
|
|
|
|
if (s) set(s);
|
1994-11-10 14:17:03 +00:00
|
|
|
}
|
1995-02-09 14:47:31 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
1994-11-10 14:17:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool TForm_item::update()
|
|
|
|
{
|
|
|
|
string_at(_x, _y, _prompt);
|
|
|
|
do_message();
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
1994-12-27 14:59:25 +00:00
|
|
|
void TForm_item::print_on(TToken_string& row) const
|
|
|
|
{
|
1994-11-10 14:17:03 +00:00
|
|
|
row = class_name();
|
1994-12-20 15:11:26 +00:00
|
|
|
row.add(_y);
|
|
|
|
row.add(_x);
|
1994-12-27 14:59:25 +00:00
|
|
|
|
|
|
|
const long fu = _group.first_one();
|
|
|
|
if (fu > 0) row.add(fu);
|
|
|
|
else row.add(" ");
|
1994-11-10 14:17:03 +00:00
|
|
|
row.add(key());
|
|
|
|
}
|
|
|
|
|
1994-12-20 15:11:26 +00:00
|
|
|
void TForm_item::print_on(TMask& m)
|
1994-11-10 14:17:03 +00:00
|
|
|
{
|
|
|
|
m.set(F_CLASS, class_name());
|
|
|
|
m.set(F_KEY, key());
|
|
|
|
m.set(F_X, _x);
|
|
|
|
m.set(F_Y, _y);
|
|
|
|
m.set(F_PROMPT, _prompt);
|
|
|
|
m.set(F_WIDTH, _width);
|
1994-12-15 18:06:43 +00:00
|
|
|
m.set(F_HEIGHT, _height);
|
1994-12-20 15:11:26 +00:00
|
|
|
_flag.print_on(m);
|
|
|
|
|
1995-02-09 14:47:31 +00:00
|
|
|
for (int g = 1; g <= 24; g++)
|
1994-12-20 15:11:26 +00:00
|
|
|
m.set(F_GROUP+g, _group[g] ? "X" : " ");
|
1994-11-10 14:17:03 +00:00
|
|
|
}
|
|
|
|
|
1994-12-20 15:11:26 +00:00
|
|
|
void TForm_item::read_from(const TMask& m)
|
1994-11-10 14:17:03 +00:00
|
|
|
{
|
|
|
|
_desc = m.get(F_KEY);
|
|
|
|
_x = atoi(m.get(F_X));
|
|
|
|
_y = atoi(m.get(F_Y));
|
|
|
|
_prompt = m.get(F_PROMPT);
|
|
|
|
_width = atoi(m.get(F_WIDTH));
|
1994-12-15 18:06:43 +00:00
|
|
|
_height = atoi(m.get(F_HEIGHT));
|
1994-12-20 15:11:26 +00:00
|
|
|
_flag.read_from(m);
|
|
|
|
|
1994-12-15 18:06:43 +00:00
|
|
|
_group.reset();
|
1995-02-09 14:47:31 +00:00
|
|
|
for (int g = 1; g <= 24; g++)
|
1994-12-20 15:11:26 +00:00
|
|
|
_group.set(g, m.get_bool(F_GROUP+g));
|
1994-11-10 14:17:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1994-12-20 15:11:26 +00:00
|
|
|
bool TForm_item::edit(TMask& m)
|
1994-11-10 14:17:03 +00:00
|
|
|
{
|
1994-12-20 15:11:26 +00:00
|
|
|
m.reset();
|
|
|
|
|
|
|
|
if (m.insert_mode()) m.enable(F_CLASS);
|
|
|
|
else print_on(m);
|
|
|
|
|
1994-11-10 14:17:03 +00:00
|
|
|
const bool dirty = (m.run() == K_ENTER) && m.dirty();
|
1994-12-20 15:11:26 +00:00
|
|
|
|
|
|
|
if (m.insert_mode()) m.disable(F_CLASS);
|
|
|
|
else if (dirty) read_from(m);
|
|
|
|
|
1994-11-10 14:17:03 +00:00
|
|
|
return dirty;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// TForm_string
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
class TForm_string : public TForm_item
|
|
|
|
{
|
|
|
|
TString _str, _picture;
|
|
|
|
TArray _field;
|
|
|
|
|
|
|
|
protected:
|
1994-12-15 18:06:43 +00:00
|
|
|
virtual const char* class_name() const { return "STRINGA"; }
|
1994-11-10 14:17:03 +00:00
|
|
|
virtual void print_body(ostream& out) const;
|
|
|
|
|
1994-12-20 15:11:26 +00:00
|
|
|
virtual void print_on(TMask& m);
|
|
|
|
virtual void read_from(const TMask& m);
|
1994-11-10 14:17:03 +00:00
|
|
|
|
|
|
|
virtual bool parse_item(TScanner&);
|
1995-01-03 14:19:41 +00:00
|
|
|
virtual bool read();
|
1994-11-10 14:17:03 +00:00
|
|
|
virtual bool update();
|
|
|
|
|
|
|
|
const char* get() const;
|
|
|
|
bool set(const char*);
|
|
|
|
|
|
|
|
const TString& picture() const { return _picture; }
|
|
|
|
|
1994-12-15 18:06:43 +00:00
|
|
|
TFieldref& field(int i) const { return (TFieldref&)_field[i]; }
|
1994-11-10 14:17:03 +00:00
|
|
|
void put_paragraph(const char* s);
|
|
|
|
|
|
|
|
public:
|
|
|
|
TForm_string(TPrint_section* section) : TForm_item(section) {}
|
1995-01-02 09:33:00 +00:00
|
|
|
virtual ~TForm_string() {}
|
1994-11-10 14:17:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
bool TForm_string::parse_item(TScanner& scanner)
|
|
|
|
{
|
|
|
|
if (scanner.key() == "FI")
|
|
|
|
{
|
|
|
|
TFieldref* fr = new TFieldref(scanner.line(), 0);
|
|
|
|
_field.add(fr);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (scanner.key() == "PI")
|
|
|
|
{
|
|
|
|
_picture = scanner.string();
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TForm_item::parse_item(scanner);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TForm_string::print_body(ostream& out) const
|
|
|
|
{
|
|
|
|
TForm_item::print_body(out);
|
|
|
|
if (_picture.not_empty())
|
|
|
|
out << " PICTURE \"" << _picture << "\"" << endl;
|
|
|
|
for (int i = 0; i < _field.items(); i++)
|
1994-12-15 18:06:43 +00:00
|
|
|
out << " FIELD " << field(i) << endl;
|
1994-11-10 14:17:03 +00:00
|
|
|
}
|
|
|
|
|
1994-12-20 15:11:26 +00:00
|
|
|
void TForm_string::print_on(TMask& m)
|
1994-11-10 14:17:03 +00:00
|
|
|
{
|
1994-12-20 15:11:26 +00:00
|
|
|
TForm_item::print_on(m);
|
1994-12-15 18:06:43 +00:00
|
|
|
for (int i = 0; i < 2; i++) if (i < _field.items())
|
|
|
|
{
|
|
|
|
TString80 f;
|
|
|
|
f << field(i);
|
|
|
|
m.set(i == 0 ? F_FIELD : F_FIELD2, f);
|
|
|
|
}
|
|
|
|
|
1994-11-10 14:17:03 +00:00
|
|
|
m.set(F_PICTURE, _picture);
|
|
|
|
}
|
|
|
|
|
1994-12-20 15:11:26 +00:00
|
|
|
void TForm_string::read_from(const TMask& m)
|
1994-11-10 14:17:03 +00:00
|
|
|
{
|
1994-12-20 15:11:26 +00:00
|
|
|
TForm_item::read_from(m);
|
1994-11-10 14:17:03 +00:00
|
|
|
_picture = m.get(F_PICTURE);
|
1994-12-15 18:06:43 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < 2; i++)
|
|
|
|
{
|
|
|
|
const TString& f = m.get(i == 0 ? F_FIELD : F_FIELD2);
|
|
|
|
if (f.not_empty())
|
|
|
|
_field.add(new TFieldref(f, 0), i);
|
|
|
|
else
|
|
|
|
_field.destroy(i);
|
|
|
|
}
|
1994-11-10 14:17:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool TForm_string::set(const char* s)
|
|
|
|
{
|
|
|
|
_str = s;
|
|
|
|
if (width()) _str.cut(width());
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* TForm_string::get() const
|
|
|
|
{ return _str; }
|
|
|
|
|
|
|
|
bool TForm_string::read()
|
|
|
|
{
|
1995-01-09 16:51:21 +00:00
|
|
|
bool ok = TRUE;
|
|
|
|
|
|
|
|
if (enabled())
|
|
|
|
{
|
|
|
|
if (_field.items())
|
1994-11-10 14:17:03 +00:00
|
|
|
{
|
1995-01-09 16:51:21 +00:00
|
|
|
const char* s = "";
|
1995-02-09 14:47:31 +00:00
|
|
|
const TRelation* r = section().form().relation();
|
1995-01-09 16:51:21 +00:00
|
|
|
for (int i = 0; i < _field.items(); i++)
|
|
|
|
{
|
|
|
|
s = field(i).read(r);
|
|
|
|
if (*s) break;
|
|
|
|
}
|
|
|
|
set(s);
|
|
|
|
}
|
|
|
|
} else ok = FALSE;
|
1994-11-10 14:17:03 +00:00
|
|
|
|
1995-01-09 16:51:21 +00:00
|
|
|
return ok;
|
1994-11-10 14:17:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TForm_string::put_paragraph(const char* s)
|
|
|
|
{
|
|
|
|
if (hidden()) return;
|
|
|
|
|
1994-12-15 18:06:43 +00:00
|
|
|
if (height() > 1)
|
1994-11-10 14:17:03 +00:00
|
|
|
{
|
|
|
|
TParagraph_string p(s, width());
|
|
|
|
int i = _prompt.not_empty() ? 1 : 0;
|
1994-12-15 18:06:43 +00:00
|
|
|
for (; (s = p.get()) != NULL && i < height(); i++)
|
1994-11-10 14:17:03 +00:00
|
|
|
string_at(_x, _y+i, s);
|
|
|
|
}
|
|
|
|
else string_at(-1, _y, s);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool TForm_string::update()
|
|
|
|
{
|
|
|
|
if (read())
|
|
|
|
{
|
1995-01-09 16:51:21 +00:00
|
|
|
TForm_item::update();
|
1994-11-10 14:17:03 +00:00
|
|
|
if (_picture.not_empty())
|
|
|
|
{
|
1994-12-15 18:06:43 +00:00
|
|
|
TString80 p;
|
1994-11-10 14:17:03 +00:00
|
|
|
p.picture(_picture, get());
|
|
|
|
put_paragraph(p);
|
1994-12-15 18:06:43 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
put_paragraph(get());
|
1995-01-03 14:19:41 +00:00
|
|
|
}
|
|
|
|
|
1994-11-10 14:17:03 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// TForm_number
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
class TForm_number : public TForm_string
|
|
|
|
{
|
|
|
|
protected:
|
1994-12-15 18:06:43 +00:00
|
|
|
virtual const char* class_name() const { return "NUMERO"; }
|
1994-11-10 14:17:03 +00:00
|
|
|
virtual bool parse_head(TScanner& scanner);
|
|
|
|
virtual bool update();
|
1994-12-15 18:06:43 +00:00
|
|
|
|
1995-01-09 16:51:21 +00:00
|
|
|
int decimals() const { return _height; }
|
1994-11-10 14:17:03 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
TForm_number(TPrint_section* section) : TForm_string(section) {}
|
1995-01-02 09:33:00 +00:00
|
|
|
virtual ~TForm_number() {}
|
1994-11-10 14:17:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
bool TForm_number::parse_head(TScanner& scanner)
|
|
|
|
{
|
|
|
|
_width = 0;
|
1994-12-15 18:06:43 +00:00
|
|
|
_height = scanner.integer();
|
1994-11-10 14:17:03 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool TForm_number::update()
|
|
|
|
{
|
|
|
|
if (read())
|
1994-12-15 18:06:43 +00:00
|
|
|
{
|
1995-01-09 16:51:21 +00:00
|
|
|
TForm_item::update();
|
1994-12-15 18:06:43 +00:00
|
|
|
const char* s = get();
|
|
|
|
real n(s);
|
|
|
|
n.round(decimals());
|
|
|
|
s = n.string(picture());
|
1995-01-09 16:51:21 +00:00
|
|
|
string_at(-1, _y, s);
|
1994-11-10 14:17:03 +00:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// TForm_date
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
class TForm_date : public TForm_string
|
|
|
|
{
|
|
|
|
protected:
|
1994-12-15 18:06:43 +00:00
|
|
|
virtual const char* class_name() const { return "DATA"; }
|
1995-01-03 14:19:41 +00:00
|
|
|
virtual bool read();
|
1994-11-10 14:17:03 +00:00
|
|
|
virtual bool set(const char*);
|
1995-01-03 14:19:41 +00:00
|
|
|
bool set(const TDate& d);
|
1994-11-10 14:17:03 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
TForm_date(TPrint_section* section);
|
1995-01-02 09:33:00 +00:00
|
|
|
virtual ~TForm_date() {}
|
1994-11-10 14:17:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
1994-12-15 18:06:43 +00:00
|
|
|
TForm_date::TForm_date(TPrint_section* section)
|
1994-11-10 14:17:03 +00:00
|
|
|
: TForm_string(section)
|
1995-01-03 14:19:41 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
bool TForm_date::read()
|
|
|
|
{
|
|
|
|
bool ok = TForm_string::read();
|
1995-01-09 16:51:21 +00:00
|
|
|
if (ok && !get()[0] && automagic())
|
1995-01-03 14:19:41 +00:00
|
|
|
set(main_app().printer().getdate());
|
|
|
|
return ok;
|
1994-11-10 14:17:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool TForm_date::set(const char* s)
|
|
|
|
{
|
1994-12-15 18:06:43 +00:00
|
|
|
const TDate d(s);
|
|
|
|
TForm_string::set(d.string((width() == 8) ? 2 : 4));
|
|
|
|
return TRUE;
|
1995-01-03 14:19:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool TForm_date::set(const TDate& d)
|
|
|
|
{
|
|
|
|
TForm_string::set(d.string((width() == 8) ? 2 : 4));
|
|
|
|
return TRUE;
|
1994-11-10 14:17:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// TForm_list
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
class TForm_list : public TForm_string
|
|
|
|
{
|
|
|
|
TToken_string _codes;
|
|
|
|
TToken_string _values;
|
|
|
|
|
|
|
|
protected:
|
1994-12-15 18:06:43 +00:00
|
|
|
virtual const char* class_name() const { return "LISTA"; }
|
1994-12-20 15:11:26 +00:00
|
|
|
virtual bool parse_item(TScanner& scanner);
|
|
|
|
virtual void print_on(TMask& m);
|
|
|
|
virtual void read_from(const TMask& m);
|
1994-11-10 14:17:03 +00:00
|
|
|
virtual void print_body(ostream& out) const;
|
|
|
|
virtual bool update();
|
|
|
|
|
|
|
|
public:
|
|
|
|
TForm_list(TPrint_section* section);
|
1995-01-02 09:33:00 +00:00
|
|
|
virtual ~TForm_list() {}
|
1994-11-10 14:17:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
TForm_list::TForm_list(TPrint_section* section)
|
|
|
|
: TForm_string(section)
|
|
|
|
{}
|
|
|
|
|
|
|
|
bool TForm_list::parse_item(TScanner& scanner)
|
|
|
|
{
|
|
|
|
if (scanner.key() == "IT")
|
|
|
|
{
|
|
|
|
TToken_string s(scanner.string());
|
|
|
|
_codes.add(s.get());
|
|
|
|
_values.add(s.get());
|
1994-12-15 18:06:43 +00:00
|
|
|
|
|
|
|
TString m(80);
|
1994-11-10 14:17:03 +00:00
|
|
|
while (scanner.popkey() == "ME")
|
|
|
|
{
|
1994-12-15 18:06:43 +00:00
|
|
|
m = scanner.line();
|
1994-11-10 14:17:03 +00:00
|
|
|
m.strip_spaces();
|
|
|
|
message(_values.items()-1).add(m);
|
|
|
|
}
|
|
|
|
scanner.push();
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TForm_string::parse_item(scanner);
|
|
|
|
}
|
|
|
|
|
1994-12-20 15:11:26 +00:00
|
|
|
void TForm_list::print_on(TMask& m)
|
|
|
|
{
|
|
|
|
TForm_string::print_on(m);
|
|
|
|
TSheet_field& s = (TSheet_field&)m.field(F_ITEMS);
|
|
|
|
|
|
|
|
_codes.restart(); _values.restart();
|
|
|
|
for (int i = 0; i < _codes.items(); i++)
|
|
|
|
{
|
|
|
|
TToken_string& row = s.row(i);
|
|
|
|
row = _codes.get();
|
|
|
|
row.add(_values.get());
|
|
|
|
row.add(message(i));
|
|
|
|
}
|
|
|
|
s.force_update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TForm_list::read_from(const TMask& m)
|
|
|
|
{
|
|
|
|
TForm_string::read_from(m);
|
|
|
|
|
|
|
|
TSheet_field& s = (TSheet_field&)m.field(F_ITEMS);
|
|
|
|
|
|
|
|
_codes = _values = "";
|
|
|
|
for (int i = 0; i < s.items(); i++)
|
|
|
|
{
|
|
|
|
TToken_string& row = s.row(i);
|
|
|
|
_codes.add(row.get(0));
|
|
|
|
_values.add(row.get());
|
|
|
|
message(i) = row.get();
|
|
|
|
}
|
|
|
|
}
|
1994-11-10 14:17:03 +00:00
|
|
|
|
|
|
|
void TForm_list::print_body(ostream& out) const
|
|
|
|
{
|
|
|
|
TForm_string::print_body(out);
|
|
|
|
|
|
|
|
TToken_string& cod = (TToken_string&)_codes; // Trick to skip const
|
|
|
|
TToken_string& val = (TToken_string&)_values;
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
TString c(cod.get(0));
|
|
|
|
TString v(val.get(0));
|
|
|
|
|
|
|
|
for (; c[0]; c = cod.get(), v = val.get(), i++)
|
|
|
|
{
|
|
|
|
out << " ITEM \"" << c;
|
|
|
|
if (v.not_empty()) out << '|' << v;
|
|
|
|
out << '"';
|
|
|
|
|
|
|
|
const char* m = ((TForm_list*)this)->message(i);
|
|
|
|
if (*m) out << " MESSAGE " << m;
|
|
|
|
|
|
|
|
out << endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool TForm_list::update()
|
|
|
|
{
|
|
|
|
bool ok = TRUE;
|
|
|
|
|
|
|
|
if (!read()) return ok;
|
|
|
|
|
1994-12-15 18:06:43 +00:00
|
|
|
const TString& val =get();
|
1994-12-28 11:01:33 +00:00
|
|
|
int pos = _codes.get_pos(val);
|
1994-11-10 14:17:03 +00:00
|
|
|
if (pos < 0)
|
|
|
|
{
|
1994-12-28 11:01:33 +00:00
|
|
|
ok = yesno_box("Il campo '%s' non puo' valere '%s': continuare ugualmente",
|
1994-12-20 15:11:26 +00:00
|
|
|
(const char*)key(), (const char*)val);
|
1994-12-28 11:01:33 +00:00
|
|
|
set(_codes.get(pos = 0));
|
1994-11-10 14:17:03 +00:00
|
|
|
}
|
1994-12-28 11:01:33 +00:00
|
|
|
if (ok)
|
|
|
|
{
|
|
|
|
do_message(pos);
|
1994-11-10 14:17:03 +00:00
|
|
|
|
1994-12-28 11:01:33 +00:00
|
|
|
if (!hidden())
|
|
|
|
{
|
|
|
|
const char* c = _values.get(pos);
|
|
|
|
if (c == NULL) c = val;
|
|
|
|
if (c) string_at(_x, _y, c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1994-11-10 14:17:03 +00:00
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
1995-01-02 09:33:00 +00:00
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// TForm_group
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
class TForm_group : public TForm_item
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
virtual const char* class_name() const { return "GRUPPO"; }
|
|
|
|
virtual bool parse_head(TScanner&) { return TRUE; }
|
|
|
|
virtual bool update() { return TRUE; }
|
|
|
|
|
|
|
|
public:
|
|
|
|
TForm_group(TPrint_section* section) : TForm_item(section) {};
|
|
|
|
virtual ~TForm_group() {}
|
|
|
|
};
|
1994-11-10 14:17:03 +00:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// TPrint_section
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
1994-12-27 14:59:25 +00:00
|
|
|
TMask* TPrint_section::_msk = NULL;
|
|
|
|
|
|
|
|
TPrint_section::TPrint_section(TForm* f) : _height(0), _form(f)
|
1994-12-20 15:11:26 +00:00
|
|
|
{}
|
1994-11-10 14:17:03 +00:00
|
|
|
|
1994-12-27 14:59:25 +00:00
|
|
|
TPrint_section::~TPrint_section()
|
|
|
|
{
|
|
|
|
if (_msk)
|
|
|
|
{
|
|
|
|
delete _msk;
|
|
|
|
_msk = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const TPrint_section& TPrint_section::copy(const TPrint_section& ps)
|
|
|
|
{
|
|
|
|
_item = ps._item;
|
|
|
|
_height = ps._height;
|
|
|
|
return ps;
|
|
|
|
}
|
|
|
|
|
1994-11-10 14:17:03 +00:00
|
|
|
TPrintrow& TPrint_section::row(int num)
|
|
|
|
{
|
|
|
|
TPrintrow* pr = (TPrintrow*)objptr(num);
|
|
|
|
if (!pr)
|
|
|
|
{
|
|
|
|
pr = new TPrintrow;
|
|
|
|
add(pr, num);
|
|
|
|
}
|
|
|
|
return *pr;
|
|
|
|
}
|
|
|
|
|
1995-01-09 16:51:21 +00:00
|
|
|
void TPrint_section::offset(int& x, int& y) const
|
|
|
|
{
|
|
|
|
if (x >= 0) x += _x;
|
|
|
|
if (y >= 0) y += _y;
|
|
|
|
}
|
|
|
|
|
1994-12-20 15:11:26 +00:00
|
|
|
|
|
|
|
TForm_item* TPrint_section::parse_item(const TString& s)
|
1994-11-10 14:17:03 +00:00
|
|
|
{
|
1994-12-20 15:11:26 +00:00
|
|
|
if (s == "ST")
|
1994-11-10 14:17:03 +00:00
|
|
|
return new TForm_string(this);
|
1994-12-20 15:11:26 +00:00
|
|
|
if (s == "NU")
|
1994-11-10 14:17:03 +00:00
|
|
|
return new TForm_number(this);
|
1994-12-20 15:11:26 +00:00
|
|
|
if (s == "DA")
|
1994-11-10 14:17:03 +00:00
|
|
|
return new TForm_date(this);
|
1994-12-20 15:11:26 +00:00
|
|
|
if (s == "LI")
|
1994-11-10 14:17:03 +00:00
|
|
|
return new TForm_list(this);
|
1995-01-02 09:33:00 +00:00
|
|
|
if (s == "GR")
|
|
|
|
return new TForm_group(this);
|
1994-12-15 18:06:43 +00:00
|
|
|
|
1994-12-27 14:59:25 +00:00
|
|
|
CHECKS(NULL, "Campo di stampa sconosciuto: ", (const char*)s);
|
1994-11-10 14:17:03 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
1994-12-20 15:11:26 +00:00
|
|
|
|
|
|
|
TForm_item* TPrint_section::parse_item(TScanner& scanner)
|
|
|
|
{
|
|
|
|
return parse_item(scanner.key());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1994-11-10 14:17:03 +00:00
|
|
|
bool TPrint_section::parse(TScanner& scanner)
|
|
|
|
{
|
1994-12-15 18:06:43 +00:00
|
|
|
_height = scanner.integer();
|
1995-01-09 16:51:21 +00:00
|
|
|
_x = scanner.integer();
|
|
|
|
_y = scanner.integer();
|
1994-11-10 14:17:03 +00:00
|
|
|
|
|
|
|
while (scanner.popkey() != "EN")
|
|
|
|
{
|
|
|
|
TForm_item *fi = parse_item(scanner);
|
|
|
|
if (!fi) return FALSE;
|
|
|
|
|
|
|
|
if (fi->parse(scanner))
|
|
|
|
_item.add(fi);
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
1995-02-09 14:47:31 +00:00
|
|
|
// Azzera tutte le righe della sezione di stampa
|
1994-12-20 15:11:26 +00:00
|
|
|
void TPrint_section::reset()
|
|
|
|
{
|
|
|
|
for (word i = 0; i < height(); i++)
|
|
|
|
row(i).reset();
|
|
|
|
}
|
|
|
|
|
1995-02-09 14:47:31 +00:00
|
|
|
// Aggiorna tutti i campi e li stampa
|
1994-11-10 14:17:03 +00:00
|
|
|
bool TPrint_section::update()
|
|
|
|
{
|
|
|
|
bool ok = TRUE;
|
1994-12-20 15:11:26 +00:00
|
|
|
|
|
|
|
reset();
|
|
|
|
for (word i = 0; i < fields(); i++)
|
1994-11-10 14:17:03 +00:00
|
|
|
{
|
1994-12-20 15:11:26 +00:00
|
|
|
const bool esito = field(i).update();
|
1994-11-10 14:17:03 +00:00
|
|
|
if (!esito) ok = FALSE;
|
|
|
|
}
|
1995-02-09 14:47:31 +00:00
|
|
|
|
1994-11-10 14:17:03 +00:00
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1995-01-31 16:15:45 +00:00
|
|
|
bool TPrint_section::edit(const char* title, bool all)
|
1994-12-27 14:59:25 +00:00
|
|
|
{
|
|
|
|
TMask m("ba2100s");
|
|
|
|
m.set_caption(title);
|
|
|
|
|
|
|
|
m.set(F_HEIGHT, _height);
|
1995-01-09 16:51:21 +00:00
|
|
|
m.set(F_X, _x);
|
|
|
|
m.set(F_Y, _y);
|
1994-12-27 14:59:25 +00:00
|
|
|
|
|
|
|
if (m.run() == K_ESC)
|
|
|
|
return FALSE;
|
1994-12-20 15:11:26 +00:00
|
|
|
|
1994-12-27 14:59:25 +00:00
|
|
|
bool dirty = m.dirty() != 0;
|
|
|
|
|
|
|
|
if (dirty)
|
1995-01-09 16:51:21 +00:00
|
|
|
{
|
1994-12-27 14:59:25 +00:00
|
|
|
_height = m.get_int(F_HEIGHT);
|
1995-01-09 16:51:21 +00:00
|
|
|
_x = m.get_int(F_X);
|
|
|
|
_y = m.get_int(F_Y);
|
|
|
|
}
|
1994-12-27 14:59:25 +00:00
|
|
|
|
1995-01-31 16:15:45 +00:00
|
|
|
TArray_sheet a(-1, -1, 0, 0, title, "Tipo@8|Riga|Col.|Gr.|Descrizione@40", all ? 0xE : 0x8);
|
1994-12-20 15:11:26 +00:00
|
|
|
|
|
|
|
for (word i = 0; i < fields(); i++)
|
1994-11-10 14:17:03 +00:00
|
|
|
{
|
1994-12-20 15:11:26 +00:00
|
|
|
TToken_string* s = new TToken_string(128);
|
1994-12-27 14:59:25 +00:00
|
|
|
field(i).print_on(*s);
|
1994-11-10 14:17:03 +00:00
|
|
|
a.add(s);
|
|
|
|
}
|
|
|
|
|
1994-12-20 15:11:26 +00:00
|
|
|
KEY k;
|
1995-01-31 16:15:45 +00:00
|
|
|
while ((k = a.run()) != K_ESC)
|
1994-12-20 15:11:26 +00:00
|
|
|
{
|
|
|
|
i = (word)a.selected();
|
|
|
|
|
1995-01-31 16:15:45 +00:00
|
|
|
if (_msk == NULL && (k == K_ENTER || k == K_INS))
|
|
|
|
{
|
1994-12-27 14:59:25 +00:00
|
|
|
_msk = new TMask("ba2100f");
|
1995-01-31 16:15:45 +00:00
|
|
|
if (!all) _msk->disable(-7);
|
|
|
|
}
|
1994-12-27 14:59:25 +00:00
|
|
|
|
1994-12-20 15:11:26 +00:00
|
|
|
switch(k)
|
1994-11-10 14:17:03 +00:00
|
|
|
{
|
1994-12-20 15:11:26 +00:00
|
|
|
case K_ENTER:
|
1994-12-27 14:59:25 +00:00
|
|
|
_msk->set_mode(MODE_MOD);
|
|
|
|
if (field(i).edit(*_msk))
|
1994-12-20 15:11:26 +00:00
|
|
|
{
|
1994-12-27 14:59:25 +00:00
|
|
|
field(i).print_on(a.row(i));
|
1994-12-20 15:11:26 +00:00
|
|
|
dirty = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case K_INS:
|
1995-01-31 16:15:45 +00:00
|
|
|
if (all)
|
|
|
|
{
|
|
|
|
_msk->set_mode(MODE_INS);
|
|
|
|
TForm_string dummy(this);
|
|
|
|
if (dummy.edit(*_msk))
|
|
|
|
{
|
|
|
|
const TString& c = _msk->get(F_CLASS).left(2);
|
|
|
|
TForm_item* item = parse_item(c);
|
|
|
|
item->read_from(*_msk);
|
|
|
|
_item.insert(item, i);
|
|
|
|
|
|
|
|
TToken_string s(128); item->print_on(s);
|
|
|
|
a.insert(s, i);
|
|
|
|
dirty = TRUE;
|
|
|
|
}
|
|
|
|
} else error_box("L'inserimento e' disabilitato");
|
1994-12-20 15:11:26 +00:00
|
|
|
break;
|
|
|
|
case K_DEL:
|
1995-01-31 16:15:45 +00:00
|
|
|
if (all && yesno_box("Confermare la cancellazione"))
|
1994-12-20 15:11:26 +00:00
|
|
|
{
|
|
|
|
_item.destroy(i, TRUE);
|
|
|
|
a.destroy(i);
|
1994-12-27 14:59:25 +00:00
|
|
|
dirty = TRUE;
|
1995-01-31 16:15:45 +00:00
|
|
|
} else error_box("La cancellazione e' disabilitata");
|
1994-12-20 15:11:26 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
1995-01-31 16:15:45 +00:00
|
|
|
}
|
1994-12-20 15:11:26 +00:00
|
|
|
|
1994-11-10 14:17:03 +00:00
|
|
|
return dirty;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TPrint_section::print_on(ostream& out) const
|
|
|
|
{
|
1995-01-09 16:51:21 +00:00
|
|
|
out << ' ' << _height << ' ' << _x << ' ' << _y << endl;
|
1994-12-20 15:11:26 +00:00
|
|
|
for(word i = 0; i < fields(); i++)
|
|
|
|
out << field(i);
|
1994-11-10 14:17:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// TForm
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
bool TForm::parse_use(TScanner& scanner)
|
|
|
|
{
|
|
|
|
const int logicnum = scanner.integer();
|
|
|
|
const char* tab = NULL;
|
|
|
|
|
|
|
|
if (logicnum > 0)
|
|
|
|
_relation = new TRelation(logicnum);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tab = scanner.pop();
|
|
|
|
_relation = new TRelation(tab);
|
|
|
|
}
|
|
|
|
|
|
|
|
int key = 1;
|
|
|
|
if (scanner.popkey() == "KE")
|
|
|
|
key = scanner.integer();
|
1994-12-27 14:59:25 +00:00
|
|
|
else
|
|
|
|
scanner.push();
|
1994-11-10 14:17:03 +00:00
|
|
|
|
|
|
|
_cursor = new TCursor(_relation, "", key);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool TForm::parse_join(TScanner& scanner)
|
|
|
|
{
|
1994-12-27 14:59:25 +00:00
|
|
|
TString16 j(scanner.pop()); // File or table
|
1994-11-10 14:17:03 +00:00
|
|
|
|
|
|
|
int to = 0;
|
|
|
|
if (scanner.popkey() == "TO") // TO keyword
|
|
|
|
{
|
|
|
|
const char* n = scanner.pop();
|
|
|
|
to = name2log(n);
|
|
|
|
}
|
|
|
|
else scanner.push();
|
|
|
|
|
|
|
|
int key = 1;
|
|
|
|
if (scanner.popkey() == "KE")
|
|
|
|
key = scanner.integer();
|
|
|
|
else scanner.push();
|
|
|
|
|
|
|
|
int alias = 0;
|
|
|
|
if (scanner.popkey() == "AL")
|
|
|
|
alias = scanner.integer();
|
|
|
|
else scanner.push();
|
|
|
|
|
|
|
|
TToken_string exp(80);
|
|
|
|
if (scanner.pop() == "INTO")
|
|
|
|
{
|
|
|
|
const char* r = scanner.pop();
|
|
|
|
while (strchr(r, '=') != NULL)
|
|
|
|
{
|
|
|
|
exp.add(r);
|
|
|
|
r = scanner.pop();
|
|
|
|
}
|
|
|
|
}
|
1994-12-15 18:06:43 +00:00
|
|
|
if (exp.empty())
|
|
|
|
yesnofatal_box("JOIN senza espressioni INTO");
|
1994-11-10 14:17:03 +00:00
|
|
|
scanner.push();
|
|
|
|
|
|
|
|
if (isdigit(j[0]))
|
|
|
|
_relation->add(atoi(j), exp, key, to, alias); // join file
|
|
|
|
else
|
|
|
|
_relation->add(j, exp, key, to, alias); // join table
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1994-12-28 11:01:33 +00:00
|
|
|
TPrint_section* TForm::exist(char s, pagetype t, bool create)
|
|
|
|
{
|
|
|
|
TArray* a = NULL;
|
|
|
|
switch (s)
|
|
|
|
{
|
|
|
|
case 'H':
|
|
|
|
a = &_head; break;
|
|
|
|
case 'F':
|
|
|
|
a = &_foot; break;
|
|
|
|
default:
|
|
|
|
a = &_body; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
TPrint_section* sec = (TPrint_section*)a->objptr(t);
|
|
|
|
if (sec == NULL && create)
|
|
|
|
{
|
|
|
|
sec = new TPrint_section(this);
|
|
|
|
a->add(sec, t);
|
|
|
|
}
|
|
|
|
|
|
|
|
return sec;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1994-12-27 14:59:25 +00:00
|
|
|
TPrint_section& TForm::section(char s, word p)
|
1994-12-20 15:11:26 +00:00
|
|
|
{
|
|
|
|
pagetype pos = odd_page;
|
1994-12-27 14:59:25 +00:00
|
|
|
if (p == 0 && exist(s, last_page)) pos = last_page;
|
|
|
|
if (p == 1 && exist(s, first_page)) pos = first_page;
|
|
|
|
if (pos == 0 && (p & 0x1) == 0 && exist(s, even_page)) pos = even_page;
|
|
|
|
|
1994-12-28 11:01:33 +00:00
|
|
|
TPrint_section* sec = exist(s, pos, TRUE);
|
1994-12-27 14:59:25 +00:00
|
|
|
return *sec;
|
1994-12-20 15:11:26 +00:00
|
|
|
}
|
|
|
|
|
1994-12-28 11:01:33 +00:00
|
|
|
|
1994-12-20 15:11:26 +00:00
|
|
|
word TForm::set_header(word p, bool u)
|
1994-11-10 14:17:03 +00:00
|
|
|
{
|
|
|
|
TPrinter& printer = main_app().printer();
|
|
|
|
printer.resetheader();
|
|
|
|
|
1994-12-27 14:59:25 +00:00
|
|
|
TPrint_section& head = section('H', p);
|
1994-12-20 15:11:26 +00:00
|
|
|
|
|
|
|
if (u) head.update();
|
1994-12-27 14:59:25 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
head.reset();
|
|
|
|
printer.headerlen(head.height());
|
|
|
|
}
|
1994-12-20 15:11:26 +00:00
|
|
|
|
|
|
|
for (word j = 0; j < head.height(); j++)
|
|
|
|
printer.setheaderline(j, head.row(j));
|
1994-11-10 14:17:03 +00:00
|
|
|
|
1994-12-20 15:11:26 +00:00
|
|
|
return head.height();
|
1994-11-10 14:17:03 +00:00
|
|
|
}
|
|
|
|
|
1994-12-20 15:11:26 +00:00
|
|
|
word TForm::set_body(word p, bool u)
|
|
|
|
{
|
1994-12-27 14:59:25 +00:00
|
|
|
TPrint_section& body = section('B', p);
|
1994-12-28 11:01:33 +00:00
|
|
|
|
1994-12-20 15:11:26 +00:00
|
|
|
if (u) body.update();
|
|
|
|
else body.reset();
|
|
|
|
|
|
|
|
if (u)
|
|
|
|
{
|
|
|
|
TPrinter& printer = main_app().printer();
|
|
|
|
for (word j = 0; j < body.height(); j++)
|
|
|
|
printer.print(body.row(j));
|
|
|
|
}
|
|
|
|
|
|
|
|
return body.height();
|
|
|
|
}
|
1994-11-10 14:17:03 +00:00
|
|
|
|
1994-12-20 15:11:26 +00:00
|
|
|
word TForm::set_footer(word p, bool u)
|
1994-11-10 14:17:03 +00:00
|
|
|
{
|
|
|
|
TPrinter& printer = main_app().printer();
|
|
|
|
printer.resetfooter();
|
|
|
|
|
1994-12-27 14:59:25 +00:00
|
|
|
TPrint_section& foot = section('F', p);
|
1994-12-20 15:11:26 +00:00
|
|
|
|
|
|
|
if (u) foot.update();
|
1994-12-27 14:59:25 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
foot.reset();
|
|
|
|
printer.footerlen(foot.height());
|
|
|
|
}
|
1994-12-20 15:11:26 +00:00
|
|
|
|
|
|
|
for (word j = 0; j < foot.height(); j++)
|
|
|
|
printer.setfooterline(j, foot.row(j));
|
1994-11-10 14:17:03 +00:00
|
|
|
|
1994-12-20 15:11:26 +00:00
|
|
|
return foot.height();
|
|
|
|
}
|
1994-11-10 14:17:03 +00:00
|
|
|
|
1994-12-20 15:11:26 +00:00
|
|
|
void TForm::header_handler(TPrinter& p)
|
|
|
|
{
|
|
|
|
const word page = form().page(p);
|
|
|
|
form().set_header(page, TRUE);
|
|
|
|
form().set_footer(page, FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TForm::footer_handler(TPrinter& p)
|
|
|
|
{
|
|
|
|
const word page = form().page(p);
|
|
|
|
form().set_footer(page, TRUE);
|
|
|
|
if (page)
|
|
|
|
form().set_header(page+1, FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
word TForm::page(const TPrinter& p) const
|
|
|
|
{
|
|
|
|
return _lastpage ? 0 : p.getcurrentpage();
|
|
|
|
}
|
|
|
|
|
|
|
|
long TForm::records() const
|
|
|
|
{
|
|
|
|
const long r = _cursor ? _cursor->items() : 0;
|
1994-12-28 11:01:33 +00:00
|
|
|
return r;
|
1994-11-10 14:17:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Stampa gli items dal from a to
|
|
|
|
// se to < 0 stampa fino alla fine del file
|
|
|
|
|
|
|
|
bool TForm::print(long from, long to)
|
1994-12-20 15:11:26 +00:00
|
|
|
{
|
1995-01-05 17:50:40 +00:00
|
|
|
_form = this; // Setta il form corrente
|
1994-12-20 15:11:26 +00:00
|
|
|
|
1995-01-05 17:50:40 +00:00
|
|
|
TPrinter& printer = main_app().printer(); // Setta handlers
|
1994-12-20 15:11:26 +00:00
|
|
|
printer.setheaderhandler(header_handler);
|
|
|
|
printer.setfooterhandler(footer_handler);
|
1994-12-27 14:59:25 +00:00
|
|
|
printer.formlen(height());
|
1994-11-10 14:17:03 +00:00
|
|
|
const bool was_open = printer.isopen();
|
|
|
|
|
1995-01-05 17:50:40 +00:00
|
|
|
_lastpage = FALSE; // non e' l'ultima pagina
|
|
|
|
|
1994-11-10 14:17:03 +00:00
|
|
|
if (!was_open && !printer.open())
|
|
|
|
return FALSE;
|
|
|
|
|
1994-12-20 15:11:26 +00:00
|
|
|
if (to < 0) to = records()-1;
|
|
|
|
|
|
|
|
bool ok = TRUE;
|
1994-11-10 14:17:03 +00:00
|
|
|
|
|
|
|
for (long i = from; i <= to && ok; i++)
|
|
|
|
{
|
|
|
|
if (from < 0) to = from;
|
1994-12-20 15:11:26 +00:00
|
|
|
else if (_cursor) *_cursor = i;
|
|
|
|
|
|
|
|
const word h = set_body(page(printer), FALSE);
|
|
|
|
if (h > printer.rows_left())
|
|
|
|
printer.formfeed();
|
1994-11-10 14:17:03 +00:00
|
|
|
|
1994-12-20 15:11:26 +00:00
|
|
|
set_body(page(printer), TRUE);
|
1994-11-10 14:17:03 +00:00
|
|
|
}
|
1994-12-20 15:11:26 +00:00
|
|
|
|
|
|
|
if (i > records())
|
|
|
|
{
|
1994-12-27 14:59:25 +00:00
|
|
|
if (exist('H', last_page) || exist('B', last_page) || exist('F', last_page))
|
1994-12-20 15:11:26 +00:00
|
|
|
{
|
|
|
|
_lastpage = TRUE;
|
|
|
|
set_header(0, TRUE);
|
|
|
|
set_body(0, TRUE);
|
|
|
|
printer.formfeed();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1994-11-10 14:17:03 +00:00
|
|
|
if (!was_open)
|
|
|
|
printer.close();
|
|
|
|
|
1995-01-05 17:50:40 +00:00
|
|
|
_form = NULL; // resetta handlers
|
|
|
|
printer.setheaderhandler(NULL);
|
|
|
|
printer.setfooterhandler(NULL);
|
|
|
|
|
1994-11-10 14:17:03 +00:00
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
1994-12-27 14:59:25 +00:00
|
|
|
void TForm::print_section(ostream& out, char s) const
|
1994-12-20 15:11:26 +00:00
|
|
|
{
|
1994-12-27 14:59:25 +00:00
|
|
|
for (pagetype t = odd_page; t <= last_page; t = pagetype(t+1))
|
1994-12-20 15:11:26 +00:00
|
|
|
{
|
1994-12-27 14:59:25 +00:00
|
|
|
const TPrint_section* sec = ((TForm*)this)->exist(s, t);
|
1994-12-28 11:01:33 +00:00
|
|
|
if (sec && sec->ok())
|
1994-12-27 14:59:25 +00:00
|
|
|
{
|
|
|
|
const char* name = s == 'H' ? "HEADER" : (s == 'F' ? "FOOTER" : "BODY");
|
|
|
|
out << "SECTION " << name << ' ' << int(t);
|
|
|
|
out << *sec;
|
|
|
|
out << "END\n" << endl;
|
|
|
|
}
|
1994-12-20 15:11:26 +00:00
|
|
|
}
|
1995-02-09 14:47:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char* TForm::validate(const char*, TToken_string&)
|
|
|
|
{ return NULL; }
|
1994-11-10 14:17:03 +00:00
|
|
|
|
|
|
|
void TForm::print_on(ostream& out) const
|
1995-01-04 15:39:38 +00:00
|
|
|
{
|
|
|
|
main_app().begin_wait();
|
|
|
|
|
1994-12-20 15:11:26 +00:00
|
|
|
if (relation())
|
|
|
|
out << *relation() << endl;
|
|
|
|
|
1994-12-27 14:59:25 +00:00
|
|
|
print_section(out, 'H');
|
|
|
|
print_section(out, 'B');
|
|
|
|
print_section(out, 'F');
|
1994-12-20 15:11:26 +00:00
|
|
|
|
|
|
|
out << "END" << endl;
|
1995-01-04 15:39:38 +00:00
|
|
|
|
|
|
|
main_app().end_wait();
|
1994-12-20 15:11:26 +00:00
|
|
|
}
|
|
|
|
|
1994-12-27 14:59:25 +00:00
|
|
|
|
|
|
|
word TForm::height()
|
|
|
|
{
|
|
|
|
word h = 0;
|
|
|
|
if (_head.items())
|
|
|
|
h += section('H', 1).height();
|
|
|
|
if (_body.items())
|
|
|
|
h += section('B', 1).height();
|
|
|
|
if (_foot.items())
|
|
|
|
h += section('F', 1).height();
|
|
|
|
return h;
|
1994-11-10 14:17:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1995-01-31 16:15:45 +00:00
|
|
|
TForm::TForm(const char* name)
|
|
|
|
: _name(name), _relation(NULL), _cursor(NULL)
|
1994-11-10 14:17:03 +00:00
|
|
|
{
|
1995-01-03 15:06:43 +00:00
|
|
|
main_app().begin_wait();
|
|
|
|
|
1994-11-10 14:17:03 +00:00
|
|
|
_name.ext("frm");
|
|
|
|
TScanner scanner(_name);
|
|
|
|
|
1994-12-20 15:11:26 +00:00
|
|
|
bool ok = TRUE;
|
1994-11-10 14:17:03 +00:00
|
|
|
if (scanner.popkey() == "US")
|
|
|
|
{
|
1994-12-20 15:11:26 +00:00
|
|
|
ok = parse_use(scanner);
|
|
|
|
while (ok && scanner.popkey() == "JO")
|
|
|
|
ok = parse_join(scanner);
|
1994-11-10 14:17:03 +00:00
|
|
|
}
|
1994-12-20 15:11:26 +00:00
|
|
|
|
1994-12-27 14:59:25 +00:00
|
|
|
while (ok)
|
|
|
|
{
|
|
|
|
scanner.popkey();
|
|
|
|
const char sec = toupper(scanner.key()[0]);
|
|
|
|
if (sec <= ' ' || sec == 'E')
|
|
|
|
break;
|
1994-12-20 15:11:26 +00:00
|
|
|
const pagetype p = (pagetype)scanner.integer();
|
1994-12-27 14:59:25 +00:00
|
|
|
TPrint_section* ps = exist(sec, p, TRUE);
|
|
|
|
ok = ps->parse(scanner);
|
1994-12-20 15:11:26 +00:00
|
|
|
}
|
|
|
|
|
1995-01-03 15:06:43 +00:00
|
|
|
main_app().end_wait();
|
1994-11-10 14:17:03 +00:00
|
|
|
}
|
|
|
|
|
1994-12-20 15:11:26 +00:00
|
|
|
|
1994-11-10 14:17:03 +00:00
|
|
|
TForm::~TForm()
|
|
|
|
{
|
|
|
|
if (_cursor)
|
|
|
|
{
|
|
|
|
delete _cursor;
|
|
|
|
delete _relation;
|
|
|
|
}
|
|
|
|
}
|