Patch level : 2.1 nopatch
Files correlati : ba8.exe Ricompilazione Demo : [ ] Commento : Risolti conflitti vari e spostate funzioni in cpp piu' consoni git-svn-id: svn://10.65.10.50/trunk@11862 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
3da790cb94
commit
baf2659f8f
249
ba/ba8200.cpp
249
ba/ba8200.cpp
@ -5,6 +5,7 @@
|
||||
#include <defmask.h>
|
||||
#include <extcdecl.h>
|
||||
#include <prefix.h>
|
||||
#include <progind.h>
|
||||
#include <relation.h>
|
||||
#include <sheet.h>
|
||||
#include <tree.h>
|
||||
@ -16,48 +17,6 @@
|
||||
#include "ba8200.h"
|
||||
#include "ba8201.h"
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
// Utility
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
// Ritorna l'indice di somiglianza tra due stringhe:
|
||||
// va da 0.0 (assolutamente diverse) a 1.0 (veramente identiche)
|
||||
// Inventata sul momento: in letteratura si dovrebbe trovare di meglio
|
||||
double fuzzy_strcmp(const char* s1, const char* s2)
|
||||
{
|
||||
if (xvt_str_compare_ignoring_case(s1, s2) == 0)
|
||||
return 1.0;
|
||||
|
||||
TString p1(s1), p2(s2);
|
||||
if (p1.len() > p2.len())
|
||||
{ p1 = s2; p2 = s1; }
|
||||
p1.upper(); p2.upper();
|
||||
const int l1 = p1.len(), l2 = p2.len();
|
||||
|
||||
double idx = 0.0;
|
||||
if (p2.find(p1) < 0)
|
||||
{
|
||||
if (l1 >= 3)
|
||||
{
|
||||
for (int i = l1-3; i >= 0; i--)
|
||||
if (p2.find(p1.mid(i, 3), i) >= i)
|
||||
idx++;
|
||||
idx /= l1-2;
|
||||
}
|
||||
}
|
||||
else
|
||||
idx = 1.0;
|
||||
|
||||
if (idx >= 1.0)
|
||||
{
|
||||
idx = (double)l1 / (double)l2;
|
||||
if (idx >= 1.0)
|
||||
idx = 0.99;
|
||||
}
|
||||
|
||||
return idx;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
// TRelation_node & TRelation_tree
|
||||
///////////////////////////////////////////////////////////
|
||||
@ -222,7 +181,7 @@ const char* TTable_mask::find_linked_field(int logicnum, const RecFieldDes& fd)
|
||||
const RecFieldDes& field = rd.Fd[i];
|
||||
if (field.TypeF == fd.TypeF && field.Len == fd.Len)
|
||||
{
|
||||
const double fuzzy = fuzzy_strcmp(field.Name, fd.Name);
|
||||
const double fuzzy = xvt_str_fuzzy_compare(field.Name, fd.Name);
|
||||
if (fuzzy > dBest)
|
||||
{
|
||||
nBest = i;
|
||||
@ -324,6 +283,8 @@ TTable_mask::~TTable_mask()
|
||||
// TQuery_mask
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
enum TQueryExportFormat { fmt_unknown, fmt_html, fmt_txt, fmt_slk, fmt_campo };
|
||||
|
||||
// Maschera principale della costruzione della query
|
||||
class TQuery_mask : public TAutomask
|
||||
{
|
||||
@ -361,7 +322,12 @@ protected:
|
||||
|
||||
bool save_tables_tree(TXmlItem& xml);
|
||||
bool save_fields_sheet(TXmlItem& xml);
|
||||
void esporta(TQueryExportFormat fmt);
|
||||
|
||||
bool save_as_html(TSQL_query& qry, const TFilename& path, TProgind& pi) const;
|
||||
bool save_as_silk(TSQL_query& qry, const TFilename& path, TProgind& pi) const;
|
||||
bool save_as_text(TSQL_query& qry, const TFilename& path, TProgind& pi) const;
|
||||
bool save_as_campo(TSQL_query& qry, const TFilename& path, TProgind& pi) const;
|
||||
void save_as(TQueryExportFormat fmt);
|
||||
|
||||
public:
|
||||
bool load_query();
|
||||
@ -730,7 +696,168 @@ void TQuery_mask::edit_query()
|
||||
warning_box(TR("Nessuna riga risultato"));
|
||||
}
|
||||
|
||||
void TQuery_mask::esporta(TQueryExportFormat fmt)
|
||||
bool TQuery_mask::save_as_html(TSQL_query& qry, const TFilename& path, TProgind& pi) const
|
||||
{
|
||||
ofstream out(path);
|
||||
out << "<html>" << endl;
|
||||
out << "<body>" << endl;
|
||||
out << "<table border=\"1\">" << endl;
|
||||
out << " <caption><h1>" << get(F_CODICE) << "</h1></caption>" << endl;
|
||||
|
||||
out << " <thead>";
|
||||
for (unsigned int c = 0; c < qry.columns(); c++)
|
||||
{
|
||||
const TSQL_column_info& ci = qry.column_info(c);
|
||||
TToken_string header(ci._name, '.');
|
||||
TString str;
|
||||
FOR_EACH_TOKEN(header, tok)
|
||||
{
|
||||
if (str.not_empty())
|
||||
str << "<br/>";
|
||||
str << tok;
|
||||
}
|
||||
out << " <th>" << str << "</th>" << endl;
|
||||
}
|
||||
out << " </thead>" << endl;
|
||||
|
||||
for (TRecnotype n = 0; n < qry.items(); n++)
|
||||
{
|
||||
pi.addstatus(1);
|
||||
if (pi.iscancelled())
|
||||
break;
|
||||
const TString_array* arr = qry.row(n);
|
||||
const int last = arr != NULL ? arr->last() : 0;
|
||||
out << " <tr>" << endl;
|
||||
for (int c = 0; c <= last; c++)
|
||||
{
|
||||
const TSQL_column_info& ci = qry.column_info(c);
|
||||
out << " <td";
|
||||
if (ci._numeric)
|
||||
out << " align=\"right\"";
|
||||
out << ">";
|
||||
TString* val = (TString*)arr->objptr(c);
|
||||
if (val && !val->blank())
|
||||
{
|
||||
val->rtrim();
|
||||
out << *val;
|
||||
}
|
||||
out << " </td>" << endl;
|
||||
}
|
||||
out << " </tr>" << endl;
|
||||
}
|
||||
|
||||
out << "</table>" << endl;
|
||||
out << "</body>" << endl;
|
||||
out << "</html>" << endl;
|
||||
|
||||
return !pi.iscancelled();
|
||||
}
|
||||
|
||||
bool TQuery_mask::save_as_silk(TSQL_query& qry, const TFilename& path, TProgind& pi) const
|
||||
{
|
||||
ofstream out(path);
|
||||
out << "ID;PWXL;N;E" << endl;
|
||||
|
||||
for (unsigned int c = 0; c < qry.columns(); c++)
|
||||
{
|
||||
const TSQL_column_info& ci = qry.column_info(c);
|
||||
out << "C;Y1;X" << (c+1) << ";K\"" << ci._name << '"' << endl;
|
||||
}
|
||||
for (TRecnotype n = 0; n < qry.items(); n++)
|
||||
{
|
||||
pi.addstatus(1);
|
||||
if (pi.iscancelled())
|
||||
break;
|
||||
const TString_array* arr = qry.row(n);
|
||||
const int last = arr->last();
|
||||
for (int c = 0; c <= last; c++)
|
||||
{
|
||||
out << "C;Y" << (n+2) << ";X" << (c+1) << ";K\"";
|
||||
TString* val = (TString*)arr->objptr(c);
|
||||
if (val && !val->blank())
|
||||
{
|
||||
val->rtrim();
|
||||
val->replace('"', '\'');
|
||||
out << *val;
|
||||
}
|
||||
out << '"' << endl;
|
||||
}
|
||||
}
|
||||
out << "E" << endl;
|
||||
|
||||
return !pi.iscancelled();
|
||||
}
|
||||
|
||||
bool TQuery_mask::save_as_text(TSQL_query& qry, const TFilename& path, TProgind& pi) const
|
||||
{
|
||||
ofstream out(path);
|
||||
for (TRecnotype n = 0; n < qry.items(); n++)
|
||||
{
|
||||
const TString_array* arr = qry.row(n);
|
||||
const int last = arr != NULL ? arr->last() : 0;
|
||||
for (int c = 0; c <= last; c++)
|
||||
{
|
||||
if (c > 0)
|
||||
out << '\t';
|
||||
TString* val = (TString*)arr->objptr(c);
|
||||
if (val && !val->blank())
|
||||
{
|
||||
val->rtrim();
|
||||
out << *val;
|
||||
}
|
||||
}
|
||||
out << endl;
|
||||
pi.addstatus(1);
|
||||
if (pi.iscancelled())
|
||||
break;
|
||||
}
|
||||
|
||||
return !pi.iscancelled();
|
||||
}
|
||||
|
||||
bool TQuery_mask::save_as_campo(TSQL_query& qry, const TFilename& path, TProgind& pi) const
|
||||
{
|
||||
ofstream out(path);
|
||||
|
||||
out << "[Head]" << endl;
|
||||
out << "Version=0";
|
||||
|
||||
for (unsigned int c = 0; c < qry.columns(); c++)
|
||||
{
|
||||
const TSQL_column_info& ci = qry.column_info(c);
|
||||
if ((c % 8) == 0)
|
||||
out << endl << "Fields=";
|
||||
else
|
||||
out << '|';
|
||||
out << ci._name;
|
||||
}
|
||||
out << endl << endl << "[Data]" << endl;
|
||||
|
||||
for (TRecnotype n = 0; n < qry.items(); n++)
|
||||
{
|
||||
const TString_array* arr = qry.row(n);
|
||||
const int last = arr != NULL ? arr->last() : 0;
|
||||
for (int c = 0; c <= last; c++)
|
||||
{
|
||||
if (c > 0)
|
||||
out << '|';
|
||||
TString* val = (TString*)arr->objptr(c);
|
||||
if (val && !val->blank())
|
||||
{
|
||||
val->rtrim();
|
||||
out << *val;
|
||||
}
|
||||
}
|
||||
out << endl;
|
||||
pi.addstatus(1);
|
||||
if (pi.iscancelled())
|
||||
break;
|
||||
}
|
||||
|
||||
return !pi.iscancelled();
|
||||
}
|
||||
|
||||
void TQuery_mask::save_as(TQueryExportFormat fmt)
|
||||
{
|
||||
xvt_fsys_save_dir();
|
||||
TFilename path; path.tempdir();
|
||||
@ -757,8 +884,22 @@ void TQuery_mask::esporta(TQueryExportFormat fmt)
|
||||
path.add(fs.name);
|
||||
|
||||
TSQL_query qry(get(F_SQL));
|
||||
if (qry.save_as(path, fmt))
|
||||
xvt_sys_goto_url(path, "open");
|
||||
bool ok = qry.items() > 0;
|
||||
|
||||
if (ok)
|
||||
{
|
||||
TProgind pi(qry.items(), TR("Esportazione in corso..."), true, true);
|
||||
switch (fmt)
|
||||
{
|
||||
case fmt_html : ok = save_as_html(qry, path, pi); break;
|
||||
case fmt_slk : ok = save_as_silk(qry, path, pi); break;
|
||||
case fmt_txt : ok = save_as_text(qry, path, pi); break;
|
||||
case fmt_campo: ok = save_as_campo(qry, path, pi); break;
|
||||
default: break;
|
||||
}
|
||||
if (ok)
|
||||
xvt_sys_goto_url(path, "open");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -997,10 +1138,10 @@ bool TQuery_mask::load_query()
|
||||
if (sql != NULL)
|
||||
{
|
||||
TString str; sql->GetEnclosedText(str);
|
||||
set(F_SQL, str, true);
|
||||
set(F_SQL, str, true); // Aggiorna anche stato bottoni di esportazione
|
||||
field(F_SQL).set_dirty(false); // Evita falsi allarmi di registrazione
|
||||
}
|
||||
|
||||
_is_dirty = false;
|
||||
_is_dirty = false; // Resetta definitivamente il dirty
|
||||
}
|
||||
}
|
||||
return ok;
|
||||
@ -1088,19 +1229,19 @@ bool TQuery_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
||||
break;
|
||||
case F_EXPORT_HTML:
|
||||
if (e == fe_button)
|
||||
esporta(fmt_html);
|
||||
save_as(fmt_html);
|
||||
break;
|
||||
case F_EXPORT_EXCEL:
|
||||
if (e == fe_button)
|
||||
esporta(fmt_slk);
|
||||
save_as(fmt_slk);
|
||||
break;
|
||||
case F_EXPORT_TXT:
|
||||
if (e == fe_button)
|
||||
esporta(fmt_txt);
|
||||
save_as(fmt_txt);
|
||||
break;
|
||||
case F_EXPORT_CAMPO:
|
||||
if (e == fe_button)
|
||||
esporta(fmt_campo);
|
||||
save_as(fmt_campo);
|
||||
break;
|
||||
case F_SHEET:
|
||||
enable_sql_button();
|
||||
|
194
ba/ba8201.cpp
194
ba/ba8201.cpp
@ -579,200 +579,6 @@ const TToken_string& TSQL_query::sheet_head() const
|
||||
return head;
|
||||
}
|
||||
|
||||
bool TSQL_query::save_as_html(const TFilename& path)
|
||||
{
|
||||
TProgind pi(items(), TR("Esportazione in corso..."), true, true);
|
||||
|
||||
ofstream out(path);
|
||||
out << "<html>" << endl;
|
||||
out << "<body>" << endl;
|
||||
out << "<table border=\"1\">" << endl;
|
||||
out << " <caption>" << _sql << "</caption>" << endl;
|
||||
|
||||
out << " <thead>";
|
||||
for (unsigned int c = 0; c < columns(); c++)
|
||||
{
|
||||
const TSQL_column_info& ci = column_info(c);
|
||||
TToken_string header(ci._name, '.');
|
||||
TString str;
|
||||
FOR_EACH_TOKEN(header, tok)
|
||||
{
|
||||
if (str.not_empty())
|
||||
str << "<br/>";
|
||||
str << tok;
|
||||
}
|
||||
out << " <th>" << str << "</th>" << endl;
|
||||
}
|
||||
out << " </thead>" << endl;
|
||||
|
||||
for (TRecnotype n = 0; n < items(); n++)
|
||||
{
|
||||
pi.addstatus(1);
|
||||
if (pi.iscancelled())
|
||||
break;
|
||||
const TString_array* arr = row(n);
|
||||
const int last = arr != NULL ? arr->last() : 0;
|
||||
out << " <tr>" << endl;
|
||||
for (int c = 0; c <= last; c++)
|
||||
{
|
||||
const TSQL_column_info& ci = column_info(c);
|
||||
out << " <td";
|
||||
if (ci._numeric)
|
||||
out << " align=\"right\"";
|
||||
out << ">";
|
||||
TString* val = (TString*)arr->objptr(c);
|
||||
if (val && !val->blank())
|
||||
{
|
||||
val->rtrim();
|
||||
out << *val;
|
||||
}
|
||||
out << " </td>" << endl;
|
||||
}
|
||||
out << " </tr>" << endl;
|
||||
}
|
||||
|
||||
out << "</table>" << endl;
|
||||
out << "</body>" << endl;
|
||||
out << "</html>" << endl;
|
||||
|
||||
return !pi.iscancelled();
|
||||
}
|
||||
|
||||
bool TSQL_query::save_as_silk(const TFilename& path)
|
||||
{
|
||||
TProgind pi(items(), TR("Esportazione in corso..."), true, true);
|
||||
|
||||
ofstream out(path);
|
||||
out << "ID;PWXL;N;E" << endl;
|
||||
|
||||
for (unsigned int c = 0; c < columns(); c++)
|
||||
{
|
||||
const TSQL_column_info& ci = column_info(c);
|
||||
out << "C;Y1;X" << (c+1) << ";K\"" << ci._name << '"' << endl;
|
||||
}
|
||||
for (TRecnotype n = 0; n < items(); n++)
|
||||
{
|
||||
pi.addstatus(1);
|
||||
if (pi.iscancelled())
|
||||
break;
|
||||
const TString_array* arr = row(n);
|
||||
const int last = arr->last();
|
||||
for (int c = 0; c <= last; c++)
|
||||
{
|
||||
out << "C;Y" << (n+2) << ";X" << (c+1) << ";K\"";
|
||||
TString* val = (TString*)arr->objptr(c);
|
||||
if (val && !val->blank())
|
||||
{
|
||||
val->rtrim();
|
||||
val->replace('"', '\'');
|
||||
out << *val;
|
||||
}
|
||||
out << '"' << endl;
|
||||
}
|
||||
}
|
||||
out << "E" << endl;
|
||||
|
||||
return !pi.iscancelled();
|
||||
}
|
||||
|
||||
bool TSQL_query::save_as_text(const TFilename& path)
|
||||
{
|
||||
TProgind pi(items(), TR("Esportazione in corso..."), true, true);
|
||||
|
||||
ofstream out(path);
|
||||
for (TRecnotype n = 0; n < items(); n++)
|
||||
{
|
||||
const TString_array* arr = row(n);
|
||||
const int last = arr != NULL ? arr->last() : 0;
|
||||
for (int c = 0; c <= last; c++)
|
||||
{
|
||||
if (c > 0)
|
||||
out << '\t';
|
||||
TString* val = (TString*)arr->objptr(c);
|
||||
if (val && !val->blank())
|
||||
{
|
||||
val->rtrim();
|
||||
out << *val;
|
||||
}
|
||||
}
|
||||
out << endl;
|
||||
pi.addstatus(1);
|
||||
if (pi.iscancelled())
|
||||
break;
|
||||
}
|
||||
|
||||
return !pi.iscancelled();
|
||||
}
|
||||
|
||||
bool TSQL_query::save_as_campo(const TFilename& path)
|
||||
{
|
||||
TProgind pi(items(), TR("Esportazione in corso..."), true, true);
|
||||
|
||||
ofstream out(path);
|
||||
|
||||
out << "[Head]" << endl;
|
||||
out << "Version=0";
|
||||
|
||||
for (unsigned int c = 0; c < columns(); c++)
|
||||
{
|
||||
const TSQL_column_info& ci = column_info(c);
|
||||
if ((c % 8) == 0)
|
||||
out << endl << "Fields=";
|
||||
else
|
||||
out << '|';
|
||||
out << ci._name;
|
||||
}
|
||||
out << endl << endl << "[Data]" << endl;
|
||||
|
||||
for (TRecnotype n = 0; n < items(); n++)
|
||||
{
|
||||
const TString_array* arr = row(n);
|
||||
const int last = arr != NULL ? arr->last() : 0;
|
||||
for (int c = 0; c <= last; c++)
|
||||
{
|
||||
if (c > 0)
|
||||
out << '|';
|
||||
TString* val = (TString*)arr->objptr(c);
|
||||
if (val && !val->blank())
|
||||
{
|
||||
val->rtrim();
|
||||
out << *val;
|
||||
}
|
||||
}
|
||||
out << endl;
|
||||
pi.addstatus(1);
|
||||
if (pi.iscancelled())
|
||||
break;
|
||||
}
|
||||
|
||||
return !pi.iscancelled();
|
||||
}
|
||||
|
||||
bool TSQL_query::save_as(const char* fn, TQueryExportFormat fmt)
|
||||
{
|
||||
TFilename path(fn);
|
||||
TString ext = path.ext(); ext.lower();
|
||||
if (fmt == fmt_unknown)
|
||||
{
|
||||
if (ext.starts_with("htm") || ext == "xml")
|
||||
fmt = fmt_html; else
|
||||
if (ext == "slk" || ext == "xls")
|
||||
fmt = fmt_slk; else
|
||||
if (ext == "txt")
|
||||
fmt = fmt_txt;
|
||||
}
|
||||
bool ok = fmt != fmt_unknown;
|
||||
switch (fmt)
|
||||
{
|
||||
case fmt_html : ok = save_as_html(path); break;
|
||||
case fmt_slk : ok = save_as_silk(path); break;
|
||||
case fmt_txt : ok = save_as_text(path); break;
|
||||
case fmt_campo: ok = save_as_campo(path); break;
|
||||
default: break;
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
TSQL_query::TSQL_query(const char* sql)
|
||||
{
|
||||
set(sql);
|
||||
|
@ -16,7 +16,6 @@ struct TSQL_column_info : public TObject
|
||||
bool _numeric;
|
||||
};
|
||||
|
||||
enum TQueryExportFormat { fmt_unknown, fmt_html, fmt_txt, fmt_slk, fmt_campo };
|
||||
|
||||
class TSQL_query : public TObject
|
||||
{
|
||||
@ -44,8 +43,6 @@ public:
|
||||
unsigned int columns() const;
|
||||
const TSQL_column_info& column_info(unsigned int c) const;
|
||||
const TToken_string& sheet_head() const; // Used by TQuery_sheet
|
||||
|
||||
bool save_as(const char* filename, TQueryExportFormat = fmt_unknown);
|
||||
|
||||
TSQL_query(const char* sql);
|
||||
virtual ~TSQL_query() { }
|
||||
|
597
ba/ba8300.cpp
597
ba/ba8300.cpp
@ -12,182 +12,80 @@
|
||||
|
||||
#include "ba8201.h"
|
||||
#include "ba8300.h"
|
||||
#include "ba8301.h"
|
||||
#include <bagn003.h>
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
// TXVT_font
|
||||
// TReport_tree
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
class TXVT_font : public TObject
|
||||
class TReport_tree_node : public TObject
|
||||
{
|
||||
public:
|
||||
XVT_FNTID _fontid;
|
||||
|
||||
void create(const TString& name, int size, XVT_FONT_STYLE_MASK style);
|
||||
void destroy();
|
||||
|
||||
TXVT_font() : _fontid(NULL) { }
|
||||
virtual ~TXVT_font() { destroy(); }
|
||||
};
|
||||
|
||||
void TXVT_font::create(const TString& name, int size, XVT_FONT_STYLE_MASK style)
|
||||
{
|
||||
destroy();
|
||||
_fontid = xvt_font_create();
|
||||
xvt_font_set_family(_fontid, (char*)(const char*)name);
|
||||
xvt_font_set_size(_fontid, size);
|
||||
xvt_font_set_style(_fontid, style);
|
||||
}
|
||||
|
||||
void TXVT_font::destroy()
|
||||
{
|
||||
if (_fontid != NULL)
|
||||
{
|
||||
xvt_font_destroy(_fontid);
|
||||
_fontid = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
// TReport_font
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
class TReport_font : public TObject
|
||||
{
|
||||
enum { DEFAULT_FONT_SIZE = 12 };
|
||||
|
||||
TString _name;
|
||||
int _size;
|
||||
bool _bold, _italic, _underline;
|
||||
TArray _physical;
|
||||
TReport_section& _sec;
|
||||
|
||||
public:
|
||||
const TString& name() const { return _name; }
|
||||
int size() const { return _size; }
|
||||
XVT_FNTID get_xvt_font(WINDOW win, int size) const;
|
||||
|
||||
TReport_font();
|
||||
virtual ~TReport_font() { }
|
||||
TReport_section& section() { return _sec; }
|
||||
TReport_tree_node(TReport_section& sec) : _sec(sec) { }
|
||||
};
|
||||
|
||||
XVT_FNTID TReport_font::get_xvt_font(WINDOW win, int charx) const
|
||||
class TReport_tree : public TObject_tree
|
||||
{
|
||||
TXVT_font* font = (TXVT_font*)_physical.objptr(charx);
|
||||
if (font == NULL)
|
||||
{
|
||||
const int quanteM = 8;
|
||||
const int target_width = quanteM * _size * charx / DEFAULT_FONT_SIZE;
|
||||
int mi = 4, me = 0, ma = 4*charx;
|
||||
int best = 0, best_error = 0;
|
||||
TXVT_font f;
|
||||
while (mi < ma)
|
||||
{
|
||||
me = (mi+ma)/2;
|
||||
f.create(XVT_FFN_FIXED, me, XVT_FS_NONE);
|
||||
xvt_dwin_set_font(win, f._fontid);
|
||||
const int width = xvt_dwin_get_text_width(win, "MMMMMMMM", quanteM);
|
||||
const int error = abs(width - target_width);
|
||||
if (best == 0 || error < best_error)
|
||||
{
|
||||
best = me;
|
||||
best_error = error;
|
||||
if (error == 0)
|
||||
break;
|
||||
}
|
||||
if (width > target_width)
|
||||
ma = me-1;
|
||||
else
|
||||
mi = me+1;
|
||||
}
|
||||
TReport& _report;
|
||||
|
||||
XVT_FONT_STYLE_MASK style = 0;
|
||||
if (_bold) style |= XVT_FS_BOLD;
|
||||
if (_italic) style |= XVT_FS_ITALIC;
|
||||
if (_underline) style |= XVT_FS_UNDERLINE;
|
||||
font = new TXVT_font;
|
||||
font->create(_name, best, style);
|
||||
((TArray&)_physical).add(font, charx);
|
||||
}
|
||||
return font->_fontid;
|
||||
}
|
||||
|
||||
TReport_font::TReport_font()
|
||||
: _name("Courier New"), _size(DEFAULT_FONT_SIZE),
|
||||
_bold(false), _italic(false), _underline(false)
|
||||
{ }
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
// TReport_section
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
class TReport_section : public TArray
|
||||
{
|
||||
const TReport_section* _father;
|
||||
|
||||
TString _str; // Description
|
||||
char _type; // Head,Body,Tail
|
||||
int _level; // 0,1,2,...
|
||||
|
||||
TReport_font* _font;
|
||||
protected:
|
||||
bool get_description(TString& str) const;
|
||||
TImage* image(bool selected) const;
|
||||
|
||||
public:
|
||||
const TString& description() const { return _str; }
|
||||
int image_id() const;
|
||||
TReport_section& curr_section() const { return ((TReport_tree_node*)curr_node())->section(); }
|
||||
|
||||
const TReport_font& font() const;
|
||||
void add_node(char t, int l = 0)
|
||||
{ add_son(new TReport_tree_node(_report.section(t, l))); }
|
||||
void add_rnode(char t, int l = 0)
|
||||
{ add_rbrother(new TReport_tree_node(_report.section(t, l))); }
|
||||
|
||||
TReport_section(const TReport_section* f, const char* s, char t, int l);
|
||||
virtual ~TReport_section();
|
||||
int image_height() const;
|
||||
TReport_tree(TReport& r) : _report(r) { }
|
||||
};
|
||||
|
||||
int TReport_section::image_id() const
|
||||
bool TReport_tree::get_description(TString& str) const
|
||||
{
|
||||
curr_section().description(str);
|
||||
str.insert(" ");
|
||||
return true;
|
||||
}
|
||||
|
||||
TImage* TReport_tree::image(bool selected) const
|
||||
{
|
||||
const TReport_section& rs = curr_section();
|
||||
|
||||
int id = 0;
|
||||
switch (_type)
|
||||
switch (rs.type())
|
||||
{
|
||||
case 'H': id = 1810; break;
|
||||
case 'B': id = 1811; break;
|
||||
case 'F': id = 1812; break;
|
||||
default : break;
|
||||
}
|
||||
return id;
|
||||
if (id > 0)
|
||||
return get_res_image(id);
|
||||
return TObject_tree::image(selected);
|
||||
}
|
||||
|
||||
const TReport_font& TReport_section::font() const
|
||||
int TReport_tree::image_height() const
|
||||
{
|
||||
const TReport_font* f = _font;
|
||||
if (f == NULL)
|
||||
{
|
||||
if (_father == NULL)
|
||||
{
|
||||
((TReport_section*)this)->_font = new TReport_font;
|
||||
f = _font;
|
||||
}
|
||||
else
|
||||
f = &_father->font();
|
||||
}
|
||||
return *f;
|
||||
}
|
||||
|
||||
TReport_section::TReport_section(const TReport_section* f, const char* s, char t, int l)
|
||||
: _father(f), _str(s), _type(t), _level(l), _font(NULL)
|
||||
{ }
|
||||
|
||||
TReport_section::~TReport_section()
|
||||
{
|
||||
if (_font)
|
||||
delete _font;
|
||||
const TImage* img = image(false);
|
||||
return img != NULL ? img->height() : 0;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
// TReport_window
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
const int REPORT_SCALE = 100;
|
||||
|
||||
class TReport_window : public TField_window
|
||||
{
|
||||
int _zoom; // [8,32]
|
||||
TReport* _report;
|
||||
PNT _dpi;
|
||||
|
||||
int _dragging;
|
||||
TPoint _pt_drag_start;
|
||||
@ -198,19 +96,24 @@ protected:
|
||||
virtual void handler(WINDOW win, EVENT* ep);
|
||||
virtual void update();
|
||||
|
||||
void draw_square(int x, int y, int dx, int dy);
|
||||
void draw_field(const TReport_field& f);
|
||||
void draw_grid();
|
||||
void draw_fields();
|
||||
void snap_drag(PNT& pnt) const;
|
||||
void draw_dragster();
|
||||
|
||||
int cpi() const;
|
||||
int lpi() const;
|
||||
|
||||
public:
|
||||
virtual PNT log2dev(long x, long y) const;
|
||||
virtual TPoint dev2log(const PNT& pt) const;
|
||||
void log2dev(const RCT& rctlog, RCT& rctdev) const;
|
||||
void dev2log(const RCT& rctdev, RCT& rctlog) const;
|
||||
void scaling(int& k, int& kx, int& ky) const { k = REPORT_SCALE; kx = _zoom; ky = _zoom*2; }
|
||||
TReport_section& curr_section() const;
|
||||
|
||||
bool get_selection_rect(RCT& rct) const;
|
||||
void draw_fields();
|
||||
bool pick(const PNT& p) const;
|
||||
void clear_selection();
|
||||
void select(const RCT& rct);
|
||||
@ -220,206 +123,63 @@ public:
|
||||
virtual ~TReport_window() { }
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
// TReport_field
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
class TReport_field : public TObject
|
||||
TReport_section& TReport_window::curr_section() const
|
||||
{
|
||||
TReport_section* _section;
|
||||
char _type; // Text, String, Numeric, Date, Line, Rectangle, Image
|
||||
short _x, _y; // Coordinate in centesimi
|
||||
short _width, _height; // Dimensioni in centesimi
|
||||
TString _picture, _field;
|
||||
|
||||
bool _selected;
|
||||
TReport_font* _font;
|
||||
|
||||
protected:
|
||||
const TReport_font& font() const;
|
||||
|
||||
public:
|
||||
void get_client_rect(const TWindow& win, RCT& r) const;
|
||||
|
||||
void set_pos(short x, short y);
|
||||
void set_size(short w, short h);
|
||||
void draw(TReport_window& win) const;
|
||||
|
||||
void get_rect(RCT& rct) const;
|
||||
|
||||
void select(bool ok = true) { _selected = ok; }
|
||||
bool selected() const { return _selected; }
|
||||
|
||||
void offset(const TPoint& pt);
|
||||
bool contains(const TPoint& pt) const;
|
||||
TReport_field(TReport_section* sec);
|
||||
};
|
||||
|
||||
void TReport_field::set_pos(short x, short y)
|
||||
{
|
||||
_x = x;
|
||||
_y = y;
|
||||
TMask& m = owner().mask();
|
||||
TTree_field& sections = m.tfield(F_SECTIONS);
|
||||
sections.goto_selected();
|
||||
TReport_tree& tree = *(TReport_tree*)sections.tree();
|
||||
return tree.curr_section();
|
||||
}
|
||||
|
||||
void TReport_field::set_size(short w, short h)
|
||||
void TReport_window::draw_square(int x, int y, int dx, int dy)
|
||||
{
|
||||
_width = w;
|
||||
_height = h;
|
||||
RCT rct; rct.left = x; rct.top = y; rct.right = x+dx; rct.bottom = y+dy;
|
||||
xvt_dwin_draw_rect(win(), &rct);
|
||||
}
|
||||
|
||||
void TReport_field::get_rect(RCT& r) const
|
||||
void TReport_window::draw_field(const TReport_field& f)
|
||||
{
|
||||
r.left = _x; r.top = _y;
|
||||
r.right = _x + _width; r.bottom = _y+_height;
|
||||
}
|
||||
set_pen(f.color());
|
||||
RCT r; f.get_rect(r);
|
||||
log2dev(r, r);
|
||||
|
||||
void TReport_field::get_client_rect(const TWindow& win, RCT& r) const
|
||||
{
|
||||
const PNT f = win.log2dev(_x,_y);
|
||||
const PNT t = win.log2dev(_x+_width,_y+_height);
|
||||
r.top = f.v; r.left = f.h;
|
||||
r.bottom = t.v; r.right = t.h;
|
||||
}
|
||||
if (f.type() != 'L')
|
||||
{
|
||||
set_brush(COLOR_WHITE, PAT_HOLLOW);
|
||||
xvt_dwin_draw_rect(win(), &r);
|
||||
}
|
||||
|
||||
void TReport_field::draw(TReport_window& win) const
|
||||
{
|
||||
win.set_pen(selected() ? COLOR_RED : COLOR_BLACK);
|
||||
RCT r; get_client_rect(win, r);
|
||||
|
||||
if (_type != 'L')
|
||||
xvt_dwin_draw_rect(win.win(), &r);
|
||||
|
||||
switch (_type)
|
||||
switch (f.type())
|
||||
{
|
||||
case 'L':
|
||||
{
|
||||
xvt_dwin_draw_set_pos(win.win(), win.log2dev(_x,_y));
|
||||
xvt_dwin_draw_line(win.win(), win.log2dev(_x+_width,_y+_height));
|
||||
}
|
||||
break;
|
||||
case 'D':
|
||||
case 'N':
|
||||
case 'S':
|
||||
case 'T':
|
||||
{
|
||||
int k, kx, ky; win.scaling(k, kx, ky);
|
||||
XVT_FNTID fid = font().get_xvt_font(win.win(), kx);
|
||||
xvt_dwin_set_font(win.win(), fid);
|
||||
set_color(f.color(), COLOR_WHITE);
|
||||
XVT_FNTID fid = f.font().get_xvt_font(win(), _dpi.h);
|
||||
xvt_dwin_set_font(win(), fid);
|
||||
const int delta = (r.bottom-r.top)/4;
|
||||
xvt_dwin_draw_text(win.win(), r.left, r.bottom-delta, _picture, -1);
|
||||
xvt_dwin_draw_text(win(), r.left, r.bottom-delta, f.picture(), -1);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool TReport_field::contains(const TPoint& pt) const
|
||||
{
|
||||
return pt.x >= _x && pt.y >= _y && pt.x < _x+_width && pt.y < _y+_height;
|
||||
}
|
||||
|
||||
void TReport_field::offset(const TPoint& pt)
|
||||
{
|
||||
_x += short(pt.x); _y += short(pt.y);
|
||||
}
|
||||
|
||||
const TReport_font& TReport_field::font() const
|
||||
{
|
||||
return _font != NULL ? *_font : _section->font();
|
||||
}
|
||||
|
||||
TReport_field::TReport_field(TReport_section* sec)
|
||||
: _section(sec), _type('T'), _selected(false), _font(NULL)
|
||||
{
|
||||
set_pos(0,0);
|
||||
set_size(1200,100);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
// TSection_tree
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
class TSection_tree : public TObject_tree
|
||||
{
|
||||
protected:
|
||||
bool get_description(TString& str) const;
|
||||
TImage* image(bool selected) const;
|
||||
|
||||
public:
|
||||
TReport_section& curr_section() const { return *(TReport_section*)curr_node(); }
|
||||
|
||||
void add_node(const char* d, char t = 0, int l = 0)
|
||||
{ add_son(new TReport_section(&curr_section(), d, t, l)); }
|
||||
void add_rnode(const char* d, char t = 0, int l = 0)
|
||||
{ add_rbrother(new TReport_section(&curr_section(), d, t, l)); }
|
||||
|
||||
int image_height() const;
|
||||
};
|
||||
|
||||
bool TSection_tree::get_description(TString& str) const
|
||||
{
|
||||
const TReport_section* rn = (const TReport_section*)curr_node();
|
||||
if (rn != NULL)
|
||||
if (f.type() != 'L' && f.selected())
|
||||
{
|
||||
str = rn->description();
|
||||
return true;
|
||||
set_pen(COLOR_BLACK);
|
||||
set_brush(COLOR_BLACK);
|
||||
const int s = 5;
|
||||
draw_square(r.left, r.top, s, s);
|
||||
draw_square(r.right-s, r.top, s, s);
|
||||
draw_square(r.right-s, r.bottom-s, s, s);
|
||||
draw_square(r.left, r.bottom-s, s, s);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
TImage* TSection_tree::image(bool selected) const
|
||||
{
|
||||
int id = 0;
|
||||
const TReport_section* rn = (const TReport_section*)curr_node();
|
||||
if (rn != NULL)
|
||||
{
|
||||
id = rn->image_id();
|
||||
if (id > 0)
|
||||
return get_res_image(id);
|
||||
}
|
||||
return TObject_tree::image(selected);
|
||||
}
|
||||
|
||||
int TSection_tree::image_height() const
|
||||
{
|
||||
const TImage* img = image(false);
|
||||
return img != NULL ? img->height() : 0;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
// TReport_mask
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
class TReport_mask : public TAutomask
|
||||
{
|
||||
TSection_tree _tree;
|
||||
|
||||
protected:
|
||||
virtual TMask_field* parse_field(TScanner& scanner);
|
||||
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
||||
|
||||
protected:
|
||||
bool select_query();
|
||||
bool select_report();
|
||||
void on_print();
|
||||
|
||||
public:
|
||||
TSection_tree& sections() { return _tree; }
|
||||
|
||||
TReport_mask();
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
// TReport_window
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
TReport_section& TReport_window::curr_section() const
|
||||
{
|
||||
TReport_mask& m = (TReport_mask&)owner().mask();
|
||||
TTree_field& sections = m.tfield(F_SECTIONS);
|
||||
sections.goto_selected();
|
||||
return m.sections().curr_section();
|
||||
}
|
||||
|
||||
void TReport_window::draw_fields()
|
||||
@ -428,7 +188,7 @@ void TReport_window::draw_fields()
|
||||
FOR_EACH_ARRAY_ITEM(rs, i, o)
|
||||
{
|
||||
const TReport_field& f = *(const TReport_field*)o;
|
||||
f.draw(*this);
|
||||
draw_field(f);
|
||||
}
|
||||
}
|
||||
|
||||
@ -436,15 +196,16 @@ bool TReport_window::pick(const PNT& p) const
|
||||
{
|
||||
TReport_section& rs = curr_section();
|
||||
RCT rct;
|
||||
|
||||
const TPoint ptlog = dev2log(p);
|
||||
const PNT pt = { short(ptlog.y), short(ptlog.x) };
|
||||
FOR_EACH_ARRAY_ITEM(rs, i, o)
|
||||
{
|
||||
TReport_field* f = (TReport_field*)o;
|
||||
f->get_client_rect(*this, rct);
|
||||
rct.left -= 2; rct.top -= 2;
|
||||
rct.right += 2; rct.bottom += 2;
|
||||
if (xvt_rect_has_point(&rct, p))
|
||||
TReport_field& f = *(TReport_field*)o;
|
||||
f.get_rect(rct);
|
||||
if (xvt_rect_has_point(&rct, pt))
|
||||
{
|
||||
f->select();
|
||||
f.select();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -521,6 +282,14 @@ void TReport_window::draw_dragster()
|
||||
set_mode(M_COPY);
|
||||
}
|
||||
|
||||
void TReport_window::snap_drag(PNT& pnt) const
|
||||
{
|
||||
const int kx = _dpi.h / cpi();
|
||||
const int ky = _dpi.v / lpi();
|
||||
pnt.h = (pnt.h / kx) * kx;
|
||||
pnt.v = (pnt.v / ky) * ky;
|
||||
}
|
||||
|
||||
void TReport_window::handler(WINDOW win, EVENT* ep)
|
||||
{
|
||||
switch (ep->type)
|
||||
@ -544,6 +313,8 @@ void TReport_window::handler(WINDOW win, EVENT* ep)
|
||||
_pt_drag_offset.h = ep->v.mouse.where.h - _rct_drag.left;
|
||||
_pt_drag_offset.v = ep->v.mouse.where.v - _rct_drag.top;
|
||||
_dragging = 2;
|
||||
XinCursor hand = xi_get_pref(XI_PREF_HAND_CURSOR_RID);
|
||||
xvt_win_set_cursor(win, (CURSOR)hand);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -555,15 +326,15 @@ void TReport_window::handler(WINDOW win, EVENT* ep)
|
||||
_pt_drag_start.y = rct.top;
|
||||
draw_dragster();
|
||||
xvt_win_trap_pointer(win);
|
||||
|
||||
}
|
||||
break;
|
||||
case E_MOUSE_MOVE:
|
||||
{
|
||||
int k, kx, ky; scaling(k, kx, ky);
|
||||
TMask& m = owner().mask();
|
||||
const TPoint p = dev2log(ep->v.mouse.where);
|
||||
m.set(F_X, p.x/k+1);
|
||||
m.set(F_Y, p.y/k+1);
|
||||
m.set(F_X, p.x/100);
|
||||
m.set(F_Y, p.y/100);
|
||||
if (_dragging != 0)
|
||||
{
|
||||
draw_dragster();
|
||||
@ -577,10 +348,7 @@ void TReport_window::handler(WINDOW win, EVENT* ep)
|
||||
case 2:
|
||||
pt.h -= _pt_drag_offset.h; pt.v -= _pt_drag_offset.v;
|
||||
if (!ep->v.mouse.shift)
|
||||
{
|
||||
pt.h = (pt.h / kx) * kx;
|
||||
pt.v = (pt.v / ky) * ky;
|
||||
}
|
||||
snap_drag(pt);
|
||||
xvt_rect_set_pos(&_rct_drag, pt);
|
||||
break;
|
||||
default:
|
||||
@ -609,12 +377,8 @@ void TReport_window::handler(WINDOW win, EVENT* ep)
|
||||
case 2:
|
||||
{
|
||||
pt.h -= _pt_drag_offset.h; pt.v -= _pt_drag_offset.v;
|
||||
int k, kx, ky; scaling(k, kx, ky);
|
||||
if (!ep->v.mouse.shift)
|
||||
{
|
||||
pt.h = (pt.h / kx) * kx;
|
||||
pt.v = (pt.v / ky) * ky;
|
||||
}
|
||||
snap_drag(pt);
|
||||
TPoint offset = dev2log(pt);
|
||||
offset.x -= _pt_drag_start.x;
|
||||
offset.y -= _pt_drag_start.y;
|
||||
@ -627,6 +391,7 @@ void TReport_window::handler(WINDOW win, EVENT* ep)
|
||||
force_update();
|
||||
_dragging = 0;
|
||||
xvt_win_release_pointer();
|
||||
xvt_win_set_cursor(win, CURSOR_ARROW);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -637,21 +402,21 @@ void TReport_window::handler(WINDOW win, EVENT* ep)
|
||||
|
||||
PNT TReport_window::log2dev(long x, long y) const
|
||||
{
|
||||
int k, kx, ky; scaling(k, kx, ky);
|
||||
x -= k*origin().x;
|
||||
y -= k*origin().y;
|
||||
x -= origin().x*100;
|
||||
y -= origin().y*100;
|
||||
PNT p;
|
||||
p.h = short(x * kx / k);
|
||||
p.v = short(y * ky / k);
|
||||
p.h = short((x * _dpi.h) / (cpi() * 100L));
|
||||
p.v = short((y * _dpi.v) / (lpi() * 100L));
|
||||
return p;
|
||||
}
|
||||
|
||||
TPoint TReport_window::dev2log(const PNT& pt) const
|
||||
{
|
||||
int k, kx, ky; scaling(k, kx, ky);
|
||||
TPoint p;
|
||||
p.x = pt.h * k / kx + k*origin().x;
|
||||
p.y = pt.v * k / ky + k*origin().y;
|
||||
p.x = pt.h * 100L * cpi() / _dpi.h;
|
||||
p.y = pt.v * 100L * lpi() / _dpi.v;
|
||||
p.x += origin().x * 100L;
|
||||
p.y += origin().y * 100L;
|
||||
return p;
|
||||
}
|
||||
|
||||
@ -675,19 +440,17 @@ void TReport_window::dev2log(const RCT& rctdev, RCT& rctlog) const
|
||||
|
||||
void TReport_window::draw_grid()
|
||||
{
|
||||
int k, kx, ky; scaling(k, kx, ky);
|
||||
// Draw grid
|
||||
clear(COLOR_WHITE);
|
||||
set_pen(MAKE_COLOR(232,232,232));
|
||||
|
||||
RCT rct; xvt_vobj_get_client_rect(win(), &rct);
|
||||
const int max = rct.right / kx;
|
||||
const int x = origin().x;
|
||||
const int y = origin().y;
|
||||
const int max = 192;
|
||||
const int kx = 100;
|
||||
const int ky = 100;
|
||||
for (int i = 1; i < max; i++)
|
||||
{
|
||||
line(x*k, (y+i)*k, (x+max)*k, (y+i)*k);
|
||||
line((x+i)*k, y*k, (x+i)*k, (y+max)*k);
|
||||
line(0, i*ky, max*kx, i*ky);
|
||||
line(i*kx, 0, i*kx, max*ky);
|
||||
}
|
||||
}
|
||||
|
||||
@ -697,9 +460,17 @@ void TReport_window::update()
|
||||
draw_fields();
|
||||
}
|
||||
|
||||
int TReport_window::cpi() const
|
||||
{ return _report ? _report->cpi() : 12; }
|
||||
|
||||
int TReport_window::lpi() const
|
||||
{ return _report ? _report->lpi() : 6; }
|
||||
|
||||
|
||||
TReport_window::TReport_window(int x, int y, int dx, int dy, WINDOW parent, TWindowed_field* owner)
|
||||
: TField_window(x, y, dx, dy, parent, owner), _zoom(10), _dragging(0)
|
||||
: TField_window(x, y, dx, dy, parent, owner), _dragging(0), _report(NULL)
|
||||
{
|
||||
_dpi.h = _dpi.v = 96;
|
||||
_pixmap = true;
|
||||
set_scroll_max(196,196);
|
||||
}
|
||||
@ -719,96 +490,29 @@ TField_window* TReport_drawer::create_window(int x, int y, int dx, int dy, WINDO
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
// TReport_printer
|
||||
// TReport_mask
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
class TReport_printer : public TObject
|
||||
class TReport_mask : public TAutomask
|
||||
{
|
||||
const TString& _name;
|
||||
const TString& _sql;
|
||||
TSection_tree& _tree;
|
||||
long _pw, _ph, _phr, _pvr; // Printer width, height, horizontal and vertical resolution
|
||||
TReport _report;
|
||||
TReport_tree _tree;
|
||||
|
||||
word _copies;
|
||||
word _pagefrom;
|
||||
word _pageto;
|
||||
bool _aborted;
|
||||
protected:
|
||||
virtual TMask_field* parse_field(TScanner& scanner);
|
||||
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
||||
|
||||
protected:
|
||||
bool select_query();
|
||||
bool select_report();
|
||||
void on_print();
|
||||
|
||||
public:
|
||||
bool print_copies(); // caallback do NOT use;
|
||||
bool aborted() const { return _aborted; }
|
||||
TReport_tree& sections() { return _tree; }
|
||||
|
||||
bool edit();
|
||||
bool print();
|
||||
|
||||
TReport_printer(const TString& name, const TString& sql, TSection_tree& t);
|
||||
virtual ~TReport_printer();
|
||||
TReport_mask();
|
||||
};
|
||||
|
||||
bool TReport_printer::edit()
|
||||
{
|
||||
_tree.goto_root();
|
||||
TReport_section& rs = _tree.curr_section();
|
||||
|
||||
TPrinter& p = printer();
|
||||
TMask msk("bagn003");
|
||||
msk.set(F_PRINTER, p.printername());
|
||||
msk.set(F_FORM, _name);
|
||||
msk.set(F_FONT, rs.font().name());
|
||||
msk.set(F_SIZE, rs.font().size());
|
||||
msk.set(F_ISGRAPHICS, p.isgraphics() ? "X" : "");
|
||||
msk.set(F_FROMPAGE, _pagefrom);
|
||||
msk.set(F_TOPAGE, _pageto);
|
||||
msk.set(F_COPIES, _copies);
|
||||
const bool ok = msk.run() == K_ENTER;
|
||||
if (ok)
|
||||
{
|
||||
_copies = msk.get_int(F_COPIES);
|
||||
_pagefrom = msk.get_int(F_FROMPAGE);
|
||||
_pageto = msk.get_int(F_TOPAGE);
|
||||
if (_pageto < _pagefrom)
|
||||
_pageto = 0;
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool TReport_printer::print_copies()
|
||||
{
|
||||
TSQL_query qry(_sql);
|
||||
const TRecnotype items = qry.items();
|
||||
bool ok = items > 0;
|
||||
for (int copia = 0; ok && copia < _copies; copia++)
|
||||
{
|
||||
xvt_print_open();
|
||||
xvt_app_escape(XVT_ESC_GET_PRINTER_INFO, printer().get_printrcd(), &_ph, &_pw, &_pvr, &_phr);
|
||||
|
||||
|
||||
xvt_print_close();
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
BOOLEAN print_callback(long jolly)
|
||||
{
|
||||
TReport_printer* rp = (TReport_printer*)jolly;
|
||||
return rp->print_copies();
|
||||
}
|
||||
|
||||
bool TReport_printer::print()
|
||||
{
|
||||
_aborted = false;
|
||||
xvt_print_start_thread(print_callback, (long)this);
|
||||
return !aborted();
|
||||
}
|
||||
|
||||
TReport_printer::TReport_printer(const TString& n, const TString& sql, TSection_tree& t)
|
||||
: _name(n), _sql(sql), _tree(t), _copies(1), _pagefrom(1), _pageto(0), _aborted(false)
|
||||
{
|
||||
}
|
||||
|
||||
TReport_printer::~TReport_printer()
|
||||
{
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
// TReport_mask
|
||||
@ -851,18 +555,8 @@ bool TReport_mask::select_query()
|
||||
return ok;
|
||||
}
|
||||
|
||||
static BOOLEAN print_page(long jolly)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void TReport_mask::on_print()
|
||||
{
|
||||
TReport_printer rp(get(F_CODICE), get(F_SQL), _tree);
|
||||
if (rp.edit())
|
||||
{
|
||||
xvt_print_start_thread(print_page, long(&rp));
|
||||
}
|
||||
}
|
||||
|
||||
bool TReport_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
||||
@ -916,7 +610,7 @@ bool TReport_mask::on_field_event(TOperable_field& o, TField_event e, long jolly
|
||||
return true;
|
||||
}
|
||||
|
||||
TReport_mask::TReport_mask()
|
||||
TReport_mask::TReport_mask() : _tree(_report)
|
||||
{
|
||||
read_mask("ba8300a", 0, -1);
|
||||
set_handlers();
|
||||
@ -931,25 +625,22 @@ TReport_mask::TReport_mask()
|
||||
field(F_REPORT).set_rect(rct_rep);
|
||||
|
||||
TString body_id, tail_id;
|
||||
_tree.add_node("Report");
|
||||
_tree.add_node('R', 0);
|
||||
|
||||
for (int i = 1; i <= 4; i++)
|
||||
{
|
||||
if (body_id.not_empty())
|
||||
_tree.goto_node(body_id);
|
||||
|
||||
const char* name[3] = { "Testa", "Corpo", "Coda" };
|
||||
TString16 bodyn;
|
||||
for (int j = 0; j < 3; j++)
|
||||
{
|
||||
bodyn.format(" %s %d", name[j], i);
|
||||
switch(j)
|
||||
{
|
||||
case 0:
|
||||
_tree.add_node(bodyn, 'H', i);
|
||||
_tree.add_node('H', i);
|
||||
break;
|
||||
case 1:
|
||||
_tree.add_rnode(bodyn, 'B', i);
|
||||
_tree.add_rnode('B', i);
|
||||
_tree.curr_id(body_id);
|
||||
if (i == 1)
|
||||
{
|
||||
@ -963,7 +654,7 @@ TReport_mask::TReport_mask()
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
_tree.add_rnode(bodyn, 'F', i);
|
||||
_tree.add_rnode('F', i);
|
||||
if (tail_id.empty())
|
||||
_tree.curr_id(tail_id);
|
||||
break;
|
||||
@ -974,10 +665,10 @@ TReport_mask::TReport_mask()
|
||||
}
|
||||
|
||||
_tree.goto_node(tail_id);
|
||||
_tree.add_rnode(" Pagina");
|
||||
_tree.add_node(" Testa", 'H', 0);
|
||||
_tree.add_rnode(" Corpo", 'B', 0);
|
||||
_tree.add_rnode(" Coda", 'F', 0);
|
||||
_tree.add_rnode('P', 0);
|
||||
_tree.add_node('H', 0);
|
||||
_tree.add_rnode('B', 0);
|
||||
_tree.add_rnode('F', 0);
|
||||
|
||||
const int ih = _tree.image_height();
|
||||
if (ih > CHARY)
|
||||
|
261
ba/ba8301.cpp
Executable file
261
ba/ba8301.cpp
Executable file
@ -0,0 +1,261 @@
|
||||
#include <diction.h>
|
||||
#include <mask.h>
|
||||
#include <printer.h>
|
||||
|
||||
#include "ba8301.h"
|
||||
#include <bagn003.h>
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
// TXVT_font
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
// boxing di un XVT_FNTID in un TObject per poterlo inserire in un TArray
|
||||
|
||||
class TXVT_font : public TObject
|
||||
{
|
||||
XVT_FNTID _fontid;
|
||||
|
||||
public:
|
||||
operator XVT_FNTID() const { return _fontid; }
|
||||
void create(const TString& name, int size, XVT_FONT_STYLE_MASK style);
|
||||
void destroy();
|
||||
|
||||
TXVT_font() : _fontid(NULL) { }
|
||||
virtual ~TXVT_font() { destroy(); }
|
||||
};
|
||||
|
||||
void TXVT_font::create(const TString& name, int size, XVT_FONT_STYLE_MASK style)
|
||||
{
|
||||
destroy();
|
||||
_fontid = xvt_font_create();
|
||||
xvt_font_set_family(_fontid, (char*)(const char*)name);
|
||||
xvt_font_set_size(_fontid, size);
|
||||
xvt_font_set_style(_fontid, style);
|
||||
}
|
||||
|
||||
void TXVT_font::destroy()
|
||||
{
|
||||
if (_fontid != NULL)
|
||||
{
|
||||
xvt_font_destroy(_fontid);
|
||||
_fontid = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
// TReport_font
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
XVT_FNTID TReport_font::get_xvt_font(WINDOW win, int ppi) const
|
||||
{
|
||||
TXVT_font* font = (TXVT_font*)_physical.objptr(ppi);
|
||||
if (font == NULL)
|
||||
{
|
||||
int mi = 0, me = 0, ma = ppi/4;
|
||||
int best = 0, best_error = 0;
|
||||
TXVT_font f;
|
||||
while (mi < ma)
|
||||
{
|
||||
me = (mi+ma)/2;
|
||||
f.create("Courier New", me, XVT_FS_NONE);
|
||||
xvt_dwin_set_font(win, f);
|
||||
const int width = xvt_dwin_get_text_width(win, "MMMMMMMMMMMMMMMMMMMMMMMM", _cpi);
|
||||
const int error = abs(width - ppi);
|
||||
if (best == 0 || error < best_error)
|
||||
{
|
||||
best = me;
|
||||
best_error = error;
|
||||
if (error == 0)
|
||||
break;
|
||||
}
|
||||
if (width > ppi)
|
||||
ma = me-1;
|
||||
else
|
||||
mi = me+1;
|
||||
}
|
||||
|
||||
XVT_FONT_STYLE_MASK style = 0;
|
||||
if (_bold) style |= XVT_FS_BOLD;
|
||||
if (_italic) style |= XVT_FS_ITALIC;
|
||||
if (_underline) style |= XVT_FS_UNDERLINE;
|
||||
font = new TXVT_font;
|
||||
font->create(_name, best, style);
|
||||
((TArray&)_physical).add(font, ppi);
|
||||
}
|
||||
return *font;
|
||||
}
|
||||
|
||||
TReport_font::TReport_font()
|
||||
: _name("Courier New"), _size(DEFAULT_FONT_SIZE),
|
||||
_bold(false), _italic(false), _underline(false)
|
||||
{
|
||||
_cpi = 120 / _size;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
// TReport_section
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
void TReport_section::description(TString& str) const
|
||||
{
|
||||
switch (_type)
|
||||
{
|
||||
case 'B': str = TR("Corpo"); break;
|
||||
case 'F': str = TR("Coda"); break;
|
||||
case 'H': str = TR("Testa"); break;
|
||||
case 'P': str = TR("Sfondo"); break; // Virtual section
|
||||
case 'R': str = TR("Report"); break; // Virtual section
|
||||
default : break;
|
||||
}
|
||||
if (_level > 0)
|
||||
str << ' ' << _level;
|
||||
}
|
||||
|
||||
const TReport_font& TReport_section::font() const
|
||||
{
|
||||
const TReport_font* f = _font;
|
||||
if (f == NULL)
|
||||
{
|
||||
if (_father == NULL)
|
||||
{
|
||||
(TReport_font*)_font = new TReport_font;
|
||||
f = _font;
|
||||
}
|
||||
else
|
||||
f = &_father->font();
|
||||
}
|
||||
return *f;
|
||||
}
|
||||
|
||||
TReport_section::TReport_section(const TReport_section* f, char t, int l)
|
||||
: _father(f), _type(t), _level(l), _font(NULL)
|
||||
{ }
|
||||
|
||||
TReport_section::~TReport_section()
|
||||
{
|
||||
if (_font)
|
||||
delete _font;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
// TReport_field
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
void TReport_field::set_pos(short x, short y)
|
||||
{
|
||||
_x = x;
|
||||
_y = y;
|
||||
}
|
||||
|
||||
void TReport_field::set_size(short w, short h)
|
||||
{
|
||||
_width = w;
|
||||
_height = h;
|
||||
}
|
||||
|
||||
void TReport_field::get_rect(RCT& r) const
|
||||
{
|
||||
r.left = _x; r.top = _y;
|
||||
r.right = _x + _width; r.bottom = _y+_height;
|
||||
}
|
||||
|
||||
void TReport_field::offset(const TPoint& pt)
|
||||
{
|
||||
_x += short(pt.x); _y += short(pt.y);
|
||||
}
|
||||
|
||||
const TReport_font& TReport_field::font() const
|
||||
{
|
||||
return _font != NULL ? *_font : _section->font();
|
||||
}
|
||||
|
||||
TReport_field::TReport_field(TReport_section* sec)
|
||||
: _section(sec), _type('T'), _selected(false), _font(NULL), _color(COLOR_BLACK)
|
||||
{
|
||||
set_pos(0,0);
|
||||
set_size(1200,100);
|
||||
_picture = "###.###.##@,@@";
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
// TReport
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
void TReport::build_section_key(char type, int level, TString& key) const
|
||||
{ key.format("%c%d", type, level); }
|
||||
|
||||
TReport_section* TReport::find_section(char type, int level) const
|
||||
{
|
||||
TString4 key; build_section_key(type, level, key);
|
||||
TReport_section* sec = (TReport_section*)_sections.objptr(key);
|
||||
return sec;
|
||||
}
|
||||
|
||||
TReport_section& TReport::section(char type, int level)
|
||||
{
|
||||
TReport_section* sec = find_section(type, level);
|
||||
if (sec == NULL)
|
||||
{
|
||||
TString4 key; build_section_key(type, level, key);
|
||||
TReport_section* father = NULL;
|
||||
if (level > 1)
|
||||
father = find_section('B', level-1);
|
||||
else
|
||||
{
|
||||
if (type != 'R')
|
||||
father = find_section('R', 0);
|
||||
}
|
||||
CHECK(type == 'R' || father != NULL, "Mater certa est...");
|
||||
sec = new TReport_section(father, type, level);
|
||||
_sections.add(key, sec);
|
||||
}
|
||||
return *sec;
|
||||
}
|
||||
|
||||
TReport::TReport() : _cpi(12), _lpi(6)
|
||||
{ }
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
// TPage_printer
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
const char* TPage_printer::form_name() const
|
||||
{
|
||||
return printer().get_form_name();
|
||||
}
|
||||
|
||||
const char* TPage_printer::font_name() const
|
||||
{
|
||||
return printer().fontname();
|
||||
}
|
||||
|
||||
int TPage_printer::font_size() const
|
||||
{
|
||||
return printer().get_char_size();
|
||||
}
|
||||
|
||||
bool TPage_printer::ask_pages()
|
||||
{
|
||||
const int last_page = pages();
|
||||
|
||||
TPrinter& p = printer();
|
||||
TMask msk("bagn003");
|
||||
msk.set(F_PRINTER, p.printername());
|
||||
msk.set(F_FORM, form_name());
|
||||
msk.set(F_FONT, font_name());
|
||||
msk.set(F_SIZE, font_size());
|
||||
msk.set(F_ISGRAPHICS, p.isgraphics() ? "X" : "");
|
||||
msk.set(F_FROMPAGE, _pagefrom);
|
||||
msk.set(F_TOPAGE, last_page);
|
||||
msk.set(F_COPIES, _copies);
|
||||
const bool ok = msk.run() == K_ENTER;
|
||||
if (ok)
|
||||
{
|
||||
_copies = msk.get_int(F_COPIES);
|
||||
_pagefrom = msk.get_int(F_FROMPAGE);
|
||||
_pageto = msk.get_int(F_TOPAGE);
|
||||
if (_pageto < _pagefrom || _pageto > last_page)
|
||||
_pageto = 0;
|
||||
}
|
||||
return ok;
|
||||
}
|
124
ba/ba8301.h
Executable file
124
ba/ba8301.h
Executable file
@ -0,0 +1,124 @@
|
||||
#ifndef __PAGEPRNT_H
|
||||
#define __PAGEPRNT_H
|
||||
|
||||
#ifndef __ASSOC_H
|
||||
#include <assoc.h>
|
||||
#endif
|
||||
|
||||
#ifndef __WINDOW_H
|
||||
#include <window.h>
|
||||
#endif
|
||||
|
||||
class TReport_font : public TObject
|
||||
{
|
||||
enum { DEFAULT_FONT_SIZE = 10 };
|
||||
|
||||
TString _name;
|
||||
int _size, _cpi;
|
||||
bool _bold, _italic, _underline;
|
||||
TArray _physical;
|
||||
|
||||
public:
|
||||
const TString& name() const { return _name; }
|
||||
int size() const { return _size; }
|
||||
XVT_FNTID get_xvt_font(WINDOW win, int size) const;
|
||||
|
||||
TReport_font();
|
||||
virtual ~TReport_font() { }
|
||||
};
|
||||
|
||||
class TReport_section : public TArray
|
||||
{
|
||||
const TReport_section* _father;
|
||||
|
||||
char _type; // Head,Body,Tail
|
||||
int _level; // 0,1,2,...
|
||||
|
||||
TReport_font* _font;
|
||||
|
||||
public:
|
||||
char type() const { return _type; }
|
||||
int level() const { return _level; }
|
||||
void description(TString& str) const;
|
||||
|
||||
const TReport_font& font() const;
|
||||
|
||||
TReport_section(const TReport_section* f, char t, int l);
|
||||
virtual ~TReport_section();
|
||||
};
|
||||
|
||||
class TReport_field : public TObject
|
||||
{
|
||||
TReport_section* _section;
|
||||
char _type; // Text, String, Numeric, Date, Line, Rectangle, Image
|
||||
short _x, _y; // Coordinate in centesimi
|
||||
short _width, _height; // Dimensioni in centesimi
|
||||
COLOR _color;
|
||||
TString _picture, _field;
|
||||
|
||||
TReport_font* _font;
|
||||
bool _selected;
|
||||
|
||||
public:
|
||||
char type() const { return _type; }
|
||||
const TReport_font& font() const;
|
||||
const TString& picture() const { return _picture; }
|
||||
|
||||
void set_pos(short x, short y);
|
||||
void set_size(short w, short h);
|
||||
void get_rect(RCT& rct) const;
|
||||
COLOR color() const { return _color; }
|
||||
|
||||
void select(bool ok = true) { _selected = ok; }
|
||||
bool selected() const { return _selected; }
|
||||
|
||||
void offset(const TPoint& pt);
|
||||
TReport_field(TReport_section* sec);
|
||||
};
|
||||
|
||||
class TReport : public TObject
|
||||
{
|
||||
TAssoc_array _sections;
|
||||
int _cpi, _lpi;
|
||||
|
||||
protected:
|
||||
void build_section_key(char type, int level, TString& key) const;
|
||||
|
||||
public:
|
||||
TReport_section* find_section(char type, int level) const;
|
||||
TReport_section& section(char type, int level);
|
||||
TReport_section& background_section(char type) { return section(type, 0); }
|
||||
|
||||
int cpi() const { return _cpi; }
|
||||
int lpi() const { return _lpi; }
|
||||
|
||||
TReport();
|
||||
};
|
||||
|
||||
class TPage_printer : public TWindow
|
||||
{
|
||||
protected:
|
||||
long _pw, _ph, _phr, _pvr; // Printer width, height, horizontal and vertical resolution
|
||||
|
||||
word _copies;
|
||||
word _pagefrom;
|
||||
word _pageto;
|
||||
bool _aborted;
|
||||
|
||||
|
||||
public:
|
||||
virtual int pages() const pure;
|
||||
virtual bool print_page(int p) pure;
|
||||
|
||||
virtual const char* form_name() const;
|
||||
virtual const char* font_name() const;
|
||||
virtual int font_size() const;
|
||||
virtual bool ask_pages();
|
||||
|
||||
virtual bool print();
|
||||
|
||||
TPage_printer();
|
||||
virtual ~TPage_printer();
|
||||
};
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user