Patch level : 2.1 nopatch
Files correlati : ba8.exe Ricompilazione Demo : [ ] Commento : Anteprima di stampa nuovi report git-svn-id: svn://10.65.10.50/trunk@11933 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
6011c75885
commit
1b1b938a7a
@ -689,7 +689,10 @@ bool TReport_mask::delete_report()
|
|||||||
void TReport_mask::on_print()
|
void TReport_mask::on_print()
|
||||||
{
|
{
|
||||||
TReport_printer rp(_report);
|
TReport_printer rp(_report);
|
||||||
rp.print();
|
if (printer().printtype() == screenvis)
|
||||||
|
rp.preview();
|
||||||
|
else
|
||||||
|
rp.print();
|
||||||
}
|
}
|
||||||
|
|
||||||
TReport_section& TReport_mask::curr_section()
|
TReport_section& TReport_mask::curr_section()
|
||||||
@ -1010,6 +1013,9 @@ TReport_mask::TReport_mask() : _tree(_report), _is_dirty(false)
|
|||||||
|
|
||||||
TReport_drawer& rd = (TReport_drawer&)field(F_REPORT);
|
TReport_drawer& rd = (TReport_drawer&)field(F_REPORT);
|
||||||
rd.set_report(&_report);
|
rd.set_report(&_report);
|
||||||
|
|
||||||
|
if (main_app().argc() >= 2)
|
||||||
|
set(F_REPORT, main_app().argv(2), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////
|
||||||
|
@ -732,7 +732,6 @@ void TReport_window::draw_grid()
|
|||||||
clear(COLOR_WHITE);
|
clear(COLOR_WHITE);
|
||||||
set_pen(MAKE_COLOR(232,232,232));
|
set_pen(MAKE_COLOR(232,232,232));
|
||||||
|
|
||||||
RCT rct; xvt_vobj_get_client_rect(win(), &rct);
|
|
||||||
const int max = 192;
|
const int max = 192;
|
||||||
const int k = 100;
|
const int k = 100;
|
||||||
for (int i = 1; i < max; i++)
|
for (int i = 1; i < max; i++)
|
||||||
|
170
ba/ba8302.cpp
170
ba/ba8302.cpp
@ -160,7 +160,7 @@ protected:
|
|||||||
bool is_numeric(const char* str) const;
|
bool is_numeric(const char* str) const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TReport_expr(TReport& rep, const char* exp, TFieldtypes ft);
|
TReport_expr(TReport& rep, const char* exp);
|
||||||
const TVariant& as_variant(TFieldtypes ft);
|
const TVariant& as_variant(TFieldtypes ft);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -206,9 +206,21 @@ const TVariant& TReport_expr::as_variant(TFieldtypes ft)
|
|||||||
return _var;
|
return _var;
|
||||||
}
|
}
|
||||||
|
|
||||||
TReport_expr::TReport_expr(TReport& rep, const char* exp, TFieldtypes ft)
|
TReport_expr::TReport_expr(TReport& rep, const char* exp)
|
||||||
: _report(rep)
|
: _report(rep)
|
||||||
{ set(exp, ft == _alfafld ? _strexpr : _numexpr); }
|
{
|
||||||
|
set(exp, _strexpr);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TObject* TExpression_cache::key2obj(const char* key)
|
||||||
|
{
|
||||||
|
return new TReport_expr(*_report, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
TReport_expr& TExpression_cache::operator[](const char* key)
|
||||||
|
{ return *(TReport_expr*)objptr(key); }
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////
|
||||||
// Utility
|
// Utility
|
||||||
@ -319,19 +331,22 @@ int TReport_section::add(TObject& obj)
|
|||||||
return TArray::add(obj);
|
return TArray::add(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
TReport_field* TReport_section::field(const TString& code)
|
int TReport_section::find_field_pos(int id)
|
||||||
{
|
{
|
||||||
const int id = atoi(code);
|
for (int i = items()-1; i >= 0; i--)
|
||||||
if (id > 0)
|
|
||||||
{
|
{
|
||||||
for (int i = 0; i < items(); i++)
|
if (field(i).id() == id)
|
||||||
{
|
break;
|
||||||
if (field(i).id() == id)
|
|
||||||
return &field(i);
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
return report().field(code);
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
TReport_field* TReport_section::find_field(int id)
|
||||||
|
{
|
||||||
|
const int pos = find_field_pos(id);
|
||||||
|
if (pos >= 0)
|
||||||
|
return &field(pos);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
TPoint TReport_section::compute_size() const
|
TPoint TReport_section::compute_size() const
|
||||||
@ -921,6 +936,76 @@ TReport_field::~TReport_field()
|
|||||||
delete _font;
|
delete _font;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////
|
||||||
|
// TReport_field_ref
|
||||||
|
///////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
struct TReport_field_ref : public TObject
|
||||||
|
{
|
||||||
|
char _sectype;
|
||||||
|
int _seclevel;
|
||||||
|
int _fldid; // -1 = section; 0 = curent field; >0 = normal field
|
||||||
|
int _fldpos; // array position
|
||||||
|
};
|
||||||
|
|
||||||
|
TObject* TField_cache::key2obj(const char* key)
|
||||||
|
{
|
||||||
|
const TFixed_string code(key);
|
||||||
|
|
||||||
|
TReport_field_ref* rf = new TReport_field_ref;
|
||||||
|
rf->_sectype = ' ';
|
||||||
|
rf->_seclevel = rf->_fldid = rf->_fldpos = -1;
|
||||||
|
|
||||||
|
const char* strid = "";
|
||||||
|
const int dot = code.find('.');
|
||||||
|
if (dot == 2)
|
||||||
|
{
|
||||||
|
rf->_sectype = code[0];
|
||||||
|
if (isdigit(code[1]))
|
||||||
|
rf->_seclevel = atoi((const char*)code + 1);
|
||||||
|
strid = (const char*)code+3;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
strid = code;
|
||||||
|
if (*strid > ' ')
|
||||||
|
{
|
||||||
|
rf->_fldid = atoi(strid);
|
||||||
|
TReport_section& sec = _report->section(rf->_sectype, rf->_seclevel);
|
||||||
|
rf->_fldpos = sec.find_field_pos(rf->_fldid);
|
||||||
|
}
|
||||||
|
|
||||||
|
return rf;
|
||||||
|
}
|
||||||
|
|
||||||
|
TReport_field* TField_cache::operator[](const char* key)
|
||||||
|
{
|
||||||
|
TReport_field_ref& ref = *(TReport_field_ref*)objptr(key);
|
||||||
|
|
||||||
|
if (ref._fldid <= 0)
|
||||||
|
return _report->curr_field();
|
||||||
|
|
||||||
|
char typ = ref._sectype;
|
||||||
|
int lev = ref._seclevel;
|
||||||
|
if (typ <= ' ' || lev < 0)
|
||||||
|
{
|
||||||
|
TReport_field* cf = _report->curr_field();
|
||||||
|
if (typ <= ' ') typ = cf->section().type();
|
||||||
|
if (lev < 0) lev = cf->section().level();
|
||||||
|
}
|
||||||
|
TReport_section& sec = _report->section(typ, lev);
|
||||||
|
TReport_field* fld = NULL;
|
||||||
|
if (ref._fldpos >= 0 && ref._fldpos < sec.items())
|
||||||
|
{
|
||||||
|
fld = &sec.field(ref._fldpos);
|
||||||
|
if (fld->id() == ref._fldid)
|
||||||
|
return fld;
|
||||||
|
}
|
||||||
|
ref._fldpos = sec.find_field_pos(ref._fldid);
|
||||||
|
fld = ref._fldpos >= 0 ? &sec.field(ref._fldpos) : NULL;
|
||||||
|
|
||||||
|
return fld;
|
||||||
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////
|
||||||
// TReport
|
// TReport
|
||||||
///////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////
|
||||||
@ -994,31 +1079,7 @@ TReport_section& TReport::section(char type, int level)
|
|||||||
|
|
||||||
TReport_field* TReport::field(const TString& code)
|
TReport_field* TReport::field(const TString& code)
|
||||||
{
|
{
|
||||||
char typ = ' ';
|
return _fields[code];
|
||||||
int lev = 0;
|
|
||||||
|
|
||||||
TReport_field* cf = curr_field();
|
|
||||||
if (cf != NULL)
|
|
||||||
{
|
|
||||||
typ = cf->section().type();
|
|
||||||
lev = cf->section().level();
|
|
||||||
}
|
|
||||||
|
|
||||||
TString8 strid;
|
|
||||||
const int dot = code.find('.');
|
|
||||||
if (dot == 2)
|
|
||||||
{
|
|
||||||
typ = code[0];
|
|
||||||
if (isdigit(code[1]))
|
|
||||||
lev = atoi((const char*)code + 1);
|
|
||||||
strid = (const char*)code+3;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
strid = code;
|
|
||||||
if (strid.blank() || strid == "THIS")
|
|
||||||
return cf;
|
|
||||||
|
|
||||||
return section(typ, lev).field(strid);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TReport::evaluate_atom(const char* atom, TVariant& var)
|
bool TReport::evaluate_atom(const char* atom, TVariant& var)
|
||||||
@ -1038,17 +1099,12 @@ bool TReport::evaluate_atom(const char* atom, TVariant& var)
|
|||||||
|
|
||||||
bool TReport::evaluate(const char* expr, TVariant& var, TFieldtypes force_type)
|
bool TReport::evaluate(const char* expr, TVariant& var, TFieldtypes force_type)
|
||||||
{
|
{
|
||||||
TReport_expr* e = (TReport_expr*)_expressions.objptr(expr);
|
TReport_expr& e = _expressions[expr];
|
||||||
if (e == NULL)
|
|
||||||
{
|
|
||||||
e = new TReport_expr(*this, expr, force_type);
|
|
||||||
_expressions.add(expr, e);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Caso semplice nonche' standard
|
// Caso semplice nonche' standard
|
||||||
if (e->numvar() == 1)
|
if (e.numvar() == 1)
|
||||||
{
|
{
|
||||||
const char* name = e->varname(0);
|
const char* name = e.varname(0);
|
||||||
if (*name == '#' && strcmp(name, expr) == 0)
|
if (*name == '#' && strcmp(name, expr) == 0)
|
||||||
{
|
{
|
||||||
const bool ok = evaluate_atom(name+1, var);
|
const bool ok = evaluate_atom(name+1, var);
|
||||||
@ -1058,16 +1114,16 @@ bool TReport::evaluate(const char* expr, TVariant& var, TFieldtypes force_type)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < e->numvar(); i++)
|
for (int i = 0; i < e.numvar(); i++)
|
||||||
{
|
{
|
||||||
const char* name = e->varname(i);
|
const char* name = e.varname(i);
|
||||||
if (name[0] == '#')
|
if (name[0] == '#')
|
||||||
{
|
{
|
||||||
evaluate_atom(name, var);
|
evaluate_atom(name, var);
|
||||||
if (var.type() == _alfafld)
|
if (var.type() == _alfafld)
|
||||||
e->setvar(i, var.as_string());
|
e.setvar(i, var.as_string());
|
||||||
else
|
else
|
||||||
e->setvar(i, var.as_real());
|
e.setvar(i, var.as_real());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -1075,17 +1131,17 @@ bool TReport::evaluate(const char* expr, TVariant& var, TFieldtypes force_type)
|
|||||||
{
|
{
|
||||||
const TVariant& var = _recordset->get(name);
|
const TVariant& var = _recordset->get(name);
|
||||||
if (var.type() == _realfld || var.type() == _longfld)
|
if (var.type() == _realfld || var.type() == _longfld)
|
||||||
e->setvar(i, var.as_real());
|
e.setvar(i, var.as_real());
|
||||||
else
|
else
|
||||||
e->setvar(i, var.as_string());
|
e.setvar(i, var.as_string());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
e->setvar(i, name);
|
e.setvar(i, name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const TFieldtypes ft = force_type != _nullfld ? force_type : var.type();
|
const TFieldtypes ft = force_type != _nullfld ? force_type : var.type();
|
||||||
var = e->as_variant(ft);
|
var = e.as_variant(ft);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -1224,7 +1280,11 @@ bool TReport::execute_usr_word(unsigned int opcode, TVariant_stack& stack)
|
|||||||
}
|
}
|
||||||
|
|
||||||
TReport::TReport() : _lpi(6), _recordset(NULL), _curr_field(NULL)
|
TReport::TReport() : _lpi(6), _recordset(NULL), _curr_field(NULL)
|
||||||
{ }
|
{
|
||||||
|
// Brutte inizializzazioni, ma inevitabili
|
||||||
|
_expressions.set_report(this);
|
||||||
|
_fields.set_report(this);
|
||||||
|
}
|
||||||
|
|
||||||
TReport::~TReport()
|
TReport::~TReport()
|
||||||
{
|
{
|
||||||
|
56
ba/ba8302.h
56
ba/ba8302.h
@ -64,7 +64,42 @@ public:
|
|||||||
class TReport;
|
class TReport;
|
||||||
class TReport_field;
|
class TReport_field;
|
||||||
|
|
||||||
enum TReport_draw_mode { rdm_edit, rdm_print, rdm_print_preview };
|
///////////////////////////////////////////////////////////
|
||||||
|
// Cache varie
|
||||||
|
///////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
class TReport_expr;
|
||||||
|
|
||||||
|
class TExpression_cache : public TCache
|
||||||
|
{
|
||||||
|
TReport* _report;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual TObject* key2obj(const char* key);
|
||||||
|
|
||||||
|
public:
|
||||||
|
TReport_expr& operator[](const char* key);
|
||||||
|
|
||||||
|
void set_report(TReport* rep) { _report = rep; }
|
||||||
|
TExpression_cache() : _report(NULL) { }
|
||||||
|
};
|
||||||
|
|
||||||
|
class TField_cache : public TCache
|
||||||
|
{
|
||||||
|
TReport* _report;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual TObject* key2obj(const char* key);
|
||||||
|
|
||||||
|
public:
|
||||||
|
TReport_field* operator[](const char* key);
|
||||||
|
void set_report(TReport* rep) { _report = rep; }
|
||||||
|
TField_cache() : _report(NULL) { }
|
||||||
|
};
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////
|
||||||
|
// TReport_script
|
||||||
|
///////////////////////////////////////////////////////////
|
||||||
|
|
||||||
class TReport_script : public TObject
|
class TReport_script : public TObject
|
||||||
{
|
{
|
||||||
@ -88,6 +123,12 @@ public:
|
|||||||
virtual ~TReport_script();
|
virtual ~TReport_script();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////
|
||||||
|
// TReport_section
|
||||||
|
///////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
enum TReport_draw_mode { rdm_edit, rdm_print, rdm_print_preview };
|
||||||
|
|
||||||
class TReport_section : public TArray
|
class TReport_section : public TArray
|
||||||
{
|
{
|
||||||
TReport& _report;
|
TReport& _report;
|
||||||
@ -109,7 +150,8 @@ public:
|
|||||||
virtual int add(TObject& obj);
|
virtual int add(TObject& obj);
|
||||||
TReport_field& field(int i) { return *(TReport_field*)objptr(i); }
|
TReport_field& field(int i) { return *(TReport_field*)objptr(i); }
|
||||||
const TReport_field& field(int i) const { return *(TReport_field*)objptr(i); }
|
const TReport_field& field(int i) const { return *(TReport_field*)objptr(i); }
|
||||||
TReport_field* field(const TString& code);
|
int find_field_pos(int id);
|
||||||
|
TReport_field* find_field(int id);
|
||||||
TReport& report() { return _report; }
|
TReport& report() { return _report; }
|
||||||
|
|
||||||
char type() const { return _type; }
|
char type() const { return _type; }
|
||||||
@ -266,9 +308,9 @@ class TReport : public TAlex_virtual_machine
|
|||||||
TReport_font _font;
|
TReport_font _font;
|
||||||
int _lpi; // Lines per inch
|
int _lpi; // Lines per inch
|
||||||
TRecordset* _recordset;
|
TRecordset* _recordset;
|
||||||
TAssoc_array _expressions;
|
TExpression_cache _expressions;
|
||||||
|
TField_cache _fields;
|
||||||
TString16 _curr_page;
|
word _curr_page;
|
||||||
TReport_field* _curr_field;
|
TReport_field* _curr_field;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@ -310,8 +352,8 @@ public:
|
|||||||
bool load(const char* fname);
|
bool load(const char* fname);
|
||||||
|
|
||||||
// Used by TReport_printer
|
// Used by TReport_printer
|
||||||
void set_curr_page(const char* str) { _curr_page = str; } // string 1-A
|
void set_curr_page(word p) { _curr_page = p; }
|
||||||
const TString& curr_page() const { return _curr_page; }
|
word curr_page() const { return _curr_page; }
|
||||||
void set_curr_field(TReport_field* fld) { _curr_field = fld; }
|
void set_curr_field(TReport_field* fld) { _curr_field = fld; }
|
||||||
TReport_field* curr_field() const { return _curr_field; }
|
TReport_field* curr_field() const { return _curr_field; }
|
||||||
|
|
||||||
|
386
ba/ba8303.cpp
386
ba/ba8303.cpp
@ -1,10 +1,260 @@
|
|||||||
#include <mask.h>
|
#include <automask.h>
|
||||||
|
#include <defmask.h>
|
||||||
|
#include <diction.h>
|
||||||
#include <printer.h>
|
#include <printer.h>
|
||||||
|
|
||||||
#include <bagn003.h>
|
#include <bagn003.h>
|
||||||
#include "ba8201.h"
|
#include "ba8201.h"
|
||||||
#include "ba8303.h"
|
#include "ba8303.h"
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////
|
||||||
|
// TPrint_preview_window
|
||||||
|
///////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
class TPrint_preview_window : public TField_window
|
||||||
|
{
|
||||||
|
TPage_printer* _printer;
|
||||||
|
word _page, _last;
|
||||||
|
int _zoom;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void popup_menu(EVENT* ep);
|
||||||
|
virtual void handler(WINDOW win, EVENT* ep);
|
||||||
|
virtual void update();
|
||||||
|
virtual bool on_key(KEY k);
|
||||||
|
|
||||||
|
public:
|
||||||
|
virtual PNT log2dev(long lx, long ly) const;
|
||||||
|
|
||||||
|
void set_printer(TPage_printer* printer) { _printer = printer; }
|
||||||
|
TPrint_preview_window(int x, int y, int dx, int dy, WINDOW parent,
|
||||||
|
TWindowed_field* owner, TPage_printer* printer);
|
||||||
|
};
|
||||||
|
|
||||||
|
PNT TPrint_preview_window::log2dev(long lx, long ly) const
|
||||||
|
{
|
||||||
|
PNT pnt;
|
||||||
|
pnt.h = short(lx * _zoom / 100);
|
||||||
|
pnt.v = short(ly * _zoom / 100);
|
||||||
|
return pnt;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TPrint_preview_window::update()
|
||||||
|
{
|
||||||
|
_printer->print_page(_page);
|
||||||
|
}
|
||||||
|
|
||||||
|
#define POPUP_FIRST 20883
|
||||||
|
#define POPUP_PREV 20884
|
||||||
|
#define POPUP_NEXT 20885
|
||||||
|
#define POPUP_LAST 20886
|
||||||
|
#define POPUP_ZOOMIN 20887
|
||||||
|
#define POPUP_ZOOMOUT 20888
|
||||||
|
|
||||||
|
void TPrint_preview_window::popup_menu(EVENT* ep)
|
||||||
|
{
|
||||||
|
MENU_ITEM menu[16]; // Stiamo larghi
|
||||||
|
memset(menu, 0, sizeof(menu));
|
||||||
|
menu[0].tag = POPUP_FIRST; menu[0].text = (char*)TR("Prima"); menu[0].enabled = true;
|
||||||
|
menu[1].tag = POPUP_PREV; menu[1].text = (char*)TR("Indietro"); menu[1].enabled = _page > 1;
|
||||||
|
menu[2].tag = POPUP_NEXT; menu[2].text = (char*)TR("Avanti"); menu[2].enabled = _last == 0 || _page < _last;
|
||||||
|
menu[3].tag = POPUP_LAST; menu[3].text = (char*)TR("Ultima"); menu[3].enabled = true;
|
||||||
|
menu[4].tag = -1; menu[4].separator = true;
|
||||||
|
menu[5].tag = POPUP_ZOOMIN; menu[5].text = (char*)TR("Zoom +"); menu[5].enabled = _zoom < 200;
|
||||||
|
menu[6].tag = POPUP_ZOOMOUT; menu[6].text = (char*)TR("Zoom -"); menu[6].enabled = _zoom > 75;
|
||||||
|
|
||||||
|
const PNT& p = ep->v.mouse.where;
|
||||||
|
xvt_menu_popup(menu, win(), p, XVT_POPUP_CENTER, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TPrint_preview_window::handler(WINDOW win, EVENT* ep)
|
||||||
|
{
|
||||||
|
switch (ep->type)
|
||||||
|
{
|
||||||
|
case E_MOUSE_DOWN:
|
||||||
|
if (ep->v.mouse.button != 0)
|
||||||
|
popup_menu(ep);
|
||||||
|
break;
|
||||||
|
case E_COMMAND:
|
||||||
|
{
|
||||||
|
bool processed = true;
|
||||||
|
switch(ep->v.cmd.tag)
|
||||||
|
{
|
||||||
|
case POPUP_FIRST : _page = 1; break;
|
||||||
|
case POPUP_PREV : if (_page > 1) _page--; break;
|
||||||
|
case POPUP_NEXT : if (_last == 0 || _page < _last) _page++; break;
|
||||||
|
case POPUP_LAST :
|
||||||
|
if (_last == 0)
|
||||||
|
{
|
||||||
|
_printer->print_page(9999);
|
||||||
|
_last = _printer->last_printed_page();
|
||||||
|
}
|
||||||
|
_page = _last;
|
||||||
|
break;
|
||||||
|
case POPUP_ZOOMIN : if (_zoom < 200) { _zoom += 25; } break;
|
||||||
|
case POPUP_ZOOMOUT: if (_zoom > 75) { _zoom -= 25; } break;
|
||||||
|
default:processed = false; break;
|
||||||
|
}
|
||||||
|
if (processed)
|
||||||
|
force_update();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
TField_window::handler(win, ep);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TPrint_preview_window::on_key(KEY k)
|
||||||
|
{
|
||||||
|
bool ok = true;
|
||||||
|
switch (k)
|
||||||
|
{
|
||||||
|
case '+' : dispatch_e_menu(win(), POPUP_ZOOMIN); break;
|
||||||
|
case '-' : dispatch_e_menu(win(), POPUP_ZOOMOUT); break;
|
||||||
|
case K_HOME :
|
||||||
|
case K_LHOME : dispatch_e_menu(win(), POPUP_FIRST); break;
|
||||||
|
case K_LEFT : dispatch_e_menu(win(), POPUP_PREV); break;
|
||||||
|
case K_RIGHT : dispatch_e_menu(win(), POPUP_NEXT); break;
|
||||||
|
case K_END:
|
||||||
|
case K_LEND : dispatch_e_menu(win(), POPUP_LAST); break;
|
||||||
|
default : ok = TField_window::on_key(k); break;
|
||||||
|
};
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
TPrint_preview_window::TPrint_preview_window(int x, int y, int dx, int dy, WINDOW parent,
|
||||||
|
TWindowed_field* owner, TPage_printer* printer)
|
||||||
|
: TField_window(x, y, dx, dy, parent, owner), _printer(printer), _page(1), _last(0), _zoom(100)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////
|
||||||
|
// TPrint_preview_field
|
||||||
|
///////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
class TPrint_preview_field : public TWindowed_field
|
||||||
|
{
|
||||||
|
TPage_printer* _printer;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual TField_window* create_window(int x, int y, int dx, int dy, WINDOW parent);
|
||||||
|
|
||||||
|
public:
|
||||||
|
TPrint_preview_field(TMask* m, TPage_printer* printer) : TWindowed_field(m), _printer(printer) { }
|
||||||
|
};
|
||||||
|
|
||||||
|
TField_window* TPrint_preview_field::create_window(int x, int y, int dx, int dy, WINDOW parent)
|
||||||
|
{
|
||||||
|
return new TPrint_preview_window(x, y, dx, dy, parent, this, _printer);
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////
|
||||||
|
// TPreview_mask
|
||||||
|
///////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
class TPreview_mask : public TAutomask
|
||||||
|
{
|
||||||
|
TPage_printer* _printer;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual bool on_key(KEY k);
|
||||||
|
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
||||||
|
virtual TMask_field* parse_field(TScanner& scanner);
|
||||||
|
|
||||||
|
public:
|
||||||
|
TPreview_mask(TPage_printer* printer);
|
||||||
|
};
|
||||||
|
|
||||||
|
bool TPreview_mask::on_key(KEY k)
|
||||||
|
{
|
||||||
|
switch (k)
|
||||||
|
{
|
||||||
|
case K_HOME :
|
||||||
|
case K_LHOME:
|
||||||
|
case K_LEFT :
|
||||||
|
case K_RIGHT:
|
||||||
|
case K_END :
|
||||||
|
case K_LEND :
|
||||||
|
dispatch_e_char(_printer->win(), k);
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return TAutomask::on_key(k);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TPreview_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
||||||
|
{
|
||||||
|
switch (o.dlg())
|
||||||
|
{
|
||||||
|
case DLG_FIRSTREC: dispatch_e_menu(_printer->win(), POPUP_FIRST); break;
|
||||||
|
case DLG_PREVREC : dispatch_e_menu(_printer->win(), POPUP_PREV); break;
|
||||||
|
case DLG_NEXTREC : dispatch_e_menu(_printer->win(), POPUP_NEXT); break;
|
||||||
|
case DLG_LASTREC : dispatch_e_menu(_printer->win(), POPUP_LAST); break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
TMask_field* TPreview_mask::parse_field(TScanner& scanner)
|
||||||
|
{
|
||||||
|
if (scanner.token().starts_with("PR"))
|
||||||
|
return new TPrint_preview_field(this, _printer);
|
||||||
|
return TAutomask::parse_field(scanner);
|
||||||
|
}
|
||||||
|
|
||||||
|
TPreview_mask::TPreview_mask(TPage_printer* printer)
|
||||||
|
: _printer(printer)
|
||||||
|
{
|
||||||
|
read_mask("ba8303", 0, -1);
|
||||||
|
set_handlers();
|
||||||
|
|
||||||
|
int pos = id2pos(DLG_FINDREC);
|
||||||
|
if (pos >= 0 && id2pos(DLG_FIRSTREC) >= 0) //se e' un bottone pentapartito...
|
||||||
|
{
|
||||||
|
TButton_field& f_find = (TButton_field &)fld(pos);
|
||||||
|
RCT rct_base; f_find.get_rect(rct_base);
|
||||||
|
const int bwidth = (rct_base.right - rct_base.left);
|
||||||
|
const int bheight = (rct_base.bottom - rct_base.top);
|
||||||
|
if (bwidth > 3*bheight/2) // Controllo se ho gia' ridimensionato i bottoni in precedenza
|
||||||
|
{
|
||||||
|
int bx = bwidth / 3;
|
||||||
|
int by = bheight / 2;
|
||||||
|
|
||||||
|
RCT r = rct_base; r.left += bx-2; r.right -= bx-2;
|
||||||
|
f_find.set_rect(r); // Ridimensiona il bottone centrale di ricerca
|
||||||
|
|
||||||
|
bx += 5; by += 3; // Aggiusta dimensioni bottoni sussidiari
|
||||||
|
|
||||||
|
pos = id2pos(DLG_FIRSTREC);
|
||||||
|
if (pos >= 0)
|
||||||
|
{
|
||||||
|
r = rct_base; r.top = r.bottom - by; r.right = r.left + bx;
|
||||||
|
fld(pos).set_rect(r);
|
||||||
|
}
|
||||||
|
pos = id2pos(DLG_PREVREC);
|
||||||
|
if (pos >= 0)
|
||||||
|
{
|
||||||
|
r = rct_base; r.bottom = r.top + by; r.right = r.left + bx;
|
||||||
|
fld(pos).set_rect(r);
|
||||||
|
}
|
||||||
|
pos = id2pos(DLG_NEXTREC);
|
||||||
|
if (pos >= 0)
|
||||||
|
{
|
||||||
|
r = rct_base; r.bottom = r.top + by; r.left = r.right - bx;
|
||||||
|
fld(pos).set_rect(r);
|
||||||
|
}
|
||||||
|
pos = id2pos(DLG_LASTREC);
|
||||||
|
if (pos >= 0)
|
||||||
|
{
|
||||||
|
r = rct_base; r.top = r.bottom - by; r.left = r.right - bx;
|
||||||
|
fld(pos).set_rect(r);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////
|
||||||
// TPage_printer
|
// TPage_printer
|
||||||
///////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////
|
||||||
@ -75,7 +325,7 @@ bool TPage_printer::main_loop()
|
|||||||
xvt_vobj_destroy(prwin);
|
xvt_vobj_destroy(prwin);
|
||||||
set_win(NULL_WIN);
|
set_win(NULL_WIN);
|
||||||
|
|
||||||
return !ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TPage_printer::page_in_range() const
|
bool TPage_printer::page_in_range() const
|
||||||
@ -85,14 +335,34 @@ bool TPage_printer::page_in_range() const
|
|||||||
return _pageto < _pagefrom || _page <= _pageto;
|
return _pageto < _pagefrom || _page <= _pageto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PNT TPage_printer::log2dev(long lx, long ly) const
|
||||||
|
{
|
||||||
|
if (preview_mode())
|
||||||
|
return _preview_window->log2dev(lx, ly);
|
||||||
|
const PNT p = { short(ly), short(lx) };
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
TPoint TPage_printer::dev2log(const PNT& pnt) const
|
||||||
|
{
|
||||||
|
CHECK(0, "dev2log: Pure virtual funtion call");
|
||||||
|
const TPoint p;
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
bool TPage_printer::open_page()
|
bool TPage_printer::open_page()
|
||||||
{
|
{
|
||||||
_page++;
|
_page++;
|
||||||
if (page_in_range())
|
if (page_in_range())
|
||||||
_page_is_open = xvt_print_open_page(_rcd) != 0;
|
{
|
||||||
|
if (print_mode())
|
||||||
|
_page_is_open = xvt_print_open_page(_rcd) != 0;
|
||||||
|
else
|
||||||
|
_page_is_open = true;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
_page_is_open = false;
|
_page_is_open = false;
|
||||||
|
|
||||||
return _page_is_open;
|
return _page_is_open;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,7 +371,9 @@ bool TPage_printer::close_page()
|
|||||||
const bool was_open = _page_is_open;
|
const bool was_open = _page_is_open;
|
||||||
if (was_open)
|
if (was_open)
|
||||||
{
|
{
|
||||||
xvt_print_close_page(_rcd);
|
if (print_mode())
|
||||||
|
xvt_print_close_page(_rcd);
|
||||||
|
|
||||||
_page_is_open = false;
|
_page_is_open = false;
|
||||||
}
|
}
|
||||||
return was_open;
|
return was_open;
|
||||||
@ -121,8 +393,62 @@ bool TPage_printer::print()
|
|||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
TPage_printer::TPage_printer() : _pagefrom(1), _pageto(0), _copies(1)
|
void TPage_printer::print_page(word page)
|
||||||
{ }
|
{
|
||||||
|
_pagefrom = _pageto = page;
|
||||||
|
_page = 0;
|
||||||
|
print_loop();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TPage_printer::preview()
|
||||||
|
{
|
||||||
|
_preview_mask = new TPreview_mask(this);
|
||||||
|
TPrint_preview_field& pf = (TPrint_preview_field&)_preview_mask->field(DLG_USER);
|
||||||
|
_preview_window = &pf.win();
|
||||||
|
|
||||||
|
TPrinter& p = printer();
|
||||||
|
_rcd = p.get_printrcd();
|
||||||
|
if (!xvt_print_is_valid(_rcd))
|
||||||
|
return error_box("Stampante non valida");
|
||||||
|
|
||||||
|
xvt_app_escape (XVT_ESC_GET_PRINTER_INFO, _rcd, &_ph, &_pw, &_pvr, &_phr);
|
||||||
|
if (_ph <= 0)
|
||||||
|
return error_box("Risoluzione stampante NULLA");
|
||||||
|
|
||||||
|
RCT rct; pf.get_rect(rct);
|
||||||
|
const long page_height = rct.bottom - rct.top;
|
||||||
|
const long page_width = rct.right - rct.left;
|
||||||
|
const long page_res = page_height * _pvr / _ph;
|
||||||
|
_ph = page_height;
|
||||||
|
_pw = page_width;
|
||||||
|
_pvr = _phr = page_res;
|
||||||
|
|
||||||
|
set_win(_preview_window->win());
|
||||||
|
_pagefrom = _pageto = _page = 1;
|
||||||
|
_preview_mask->run();
|
||||||
|
set_win(NULL_WIN);
|
||||||
|
|
||||||
|
delete _preview_mask;
|
||||||
|
_preview_mask = NULL;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
TPoint TPage_printer::page_size() const
|
||||||
|
{
|
||||||
|
return TPoint(_pw, _ph);
|
||||||
|
}
|
||||||
|
|
||||||
|
TPoint TPage_printer::page_res() const
|
||||||
|
{
|
||||||
|
TPoint pt(_phr, _pvr);
|
||||||
|
return pt;
|
||||||
|
}
|
||||||
|
|
||||||
|
TPage_printer::TPage_printer() : _pagefrom(1), _pageto(0), _copies(1), _preview_mask(NULL)
|
||||||
|
{
|
||||||
|
_pixmap = true; // Fondamentale!!!
|
||||||
|
}
|
||||||
|
|
||||||
TPage_printer::~TPage_printer()
|
TPage_printer::~TPage_printer()
|
||||||
{ }
|
{ }
|
||||||
@ -149,20 +475,13 @@ int TReport_printer::font_size() const
|
|||||||
|
|
||||||
PNT TReport_printer::log2dev(long lx, long ly) const
|
PNT TReport_printer::log2dev(long lx, long ly) const
|
||||||
{
|
{
|
||||||
const double cx = (double)_phr / (double)_report.cpi();
|
const TPoint res = page_res();
|
||||||
const double cy = (double)_pvr / (double)_report.lpi();
|
const double cx = (double)res.x / (double)_report.cpi();
|
||||||
|
const double cy = (double)res.y / (double)_report.lpi();
|
||||||
const short x = short((lx + _delta.x) * cx / 100.0);
|
const long x = long((lx + _delta.x) * cx / 100.0);
|
||||||
const short y = short((ly + _delta.y) * cy / 100.0);
|
const long y = long((ly + _delta.y) * cy / 100.0);
|
||||||
const PNT pnt = { y, x };
|
|
||||||
return pnt;
|
return TPage_printer::log2dev(x, y); // Useful for preview mode
|
||||||
}
|
|
||||||
|
|
||||||
TPoint TReport_printer::dev2log(const PNT& pnt) const
|
|
||||||
{
|
|
||||||
CHECK(0, "dev2log: Pure virtual funtion call");
|
|
||||||
const TPoint p;
|
|
||||||
return p;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
long TReport_printer::print_section(char type, int level)
|
long TReport_printer::print_section(char type, int level)
|
||||||
@ -178,11 +497,24 @@ bool TReport_printer::open_page()
|
|||||||
{
|
{
|
||||||
const bool ok = TPage_printer::open_page();
|
const bool ok = TPage_printer::open_page();
|
||||||
|
|
||||||
TString8 str; str << _page;
|
_report.set_curr_page(_page);
|
||||||
_report.set_curr_page(str);
|
|
||||||
|
|
||||||
_delta.x = _delta.y = 0;
|
_delta.x = _delta.y = 0;
|
||||||
_page_break_allowed = false;
|
_page_break_allowed = false;
|
||||||
|
|
||||||
|
if (ok && preview_mode()) // Clear page needed
|
||||||
|
{
|
||||||
|
clear(COLOR_WHITE);
|
||||||
|
set_pen(MAKE_COLOR(232,232,232));
|
||||||
|
const int max = 192;
|
||||||
|
const int k = 100;
|
||||||
|
for (int i = 1; i < max; i++)
|
||||||
|
{
|
||||||
|
line(0, i*k, max*k, i*k);
|
||||||
|
line(i*k, 0, i*k, max*k);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
print_section('B', 0);
|
print_section('B', 0);
|
||||||
if (_page == 1)
|
if (_page == 1)
|
||||||
_delta.y += print_section('H', 1);
|
_delta.y += print_section('H', 1);
|
||||||
@ -244,10 +576,9 @@ bool TReport_printer::print_loop()
|
|||||||
if (rex.items() <= 0)
|
if (rex.items() <= 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
_kx = double(_phr) / double(_report.cpi()*100.0);
|
const TPoint siz = page_size();
|
||||||
_ky = double(_pvr) / double(_report.lpi()*100.0);
|
const TPoint res = page_res();
|
||||||
|
const double pollici_pagina = (double)siz.y / (double)res.y;
|
||||||
const double pollici_pagina = (double)_ph / (double)_pvr;
|
|
||||||
const double righe_pagina = pollici_pagina * _report.lpi();
|
const double righe_pagina = pollici_pagina * _report.lpi();
|
||||||
_logical_page_height = long(righe_pagina*100.0);
|
_logical_page_height = long(righe_pagina*100.0);
|
||||||
const long logical_footer_height = _report.section('F',0).compute_size().y;
|
const long logical_footer_height = _report.section('F',0).compute_size().y;
|
||||||
@ -301,6 +632,7 @@ bool TReport_printer::print_loop()
|
|||||||
print_section('F', 1);
|
print_section('F', 1);
|
||||||
_is_last_page = true;
|
_is_last_page = true;
|
||||||
close_page();
|
close_page();
|
||||||
|
_lastprinted = _page;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
27
ba/ba8303.h
27
ba/ba8303.h
@ -7,16 +7,25 @@
|
|||||||
|
|
||||||
class TPage_printer : public TWindow
|
class TPage_printer : public TWindow
|
||||||
{
|
{
|
||||||
protected:
|
|
||||||
PRINT_RCD* _rcd;
|
PRINT_RCD* _rcd;
|
||||||
long _pw, _ph, _phr, _pvr; // Printer width, height, horizontal and vertical resolution
|
long _pw, _ph, _phr, _pvr; // Printer width, height, horizontal and vertical resolution
|
||||||
word _copies, _pagefrom, _pageto, _page;
|
|
||||||
|
protected:
|
||||||
|
word _copies, _pagefrom, _pageto, _page, _lastprinted;
|
||||||
bool _page_is_open;
|
bool _page_is_open;
|
||||||
|
|
||||||
|
TMask* _preview_mask; // owned object
|
||||||
|
TWindow* _preview_window; // referenced object
|
||||||
|
|
||||||
virtual word pages() const { return 0; }
|
virtual word pages() const { return 0; }
|
||||||
virtual bool print_loop() pure;
|
virtual bool print_loop() pure;
|
||||||
|
|
||||||
|
private:
|
||||||
|
virtual TPoint dev2log(const PNT& p) const; // Never use this!
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
virtual PNT log2dev(long lx, long ly) const; // Always override this!
|
||||||
|
|
||||||
virtual const char* form_name() const;
|
virtual const char* form_name() const;
|
||||||
virtual const char* font_name() const;
|
virtual const char* font_name() const;
|
||||||
virtual int font_size() const;
|
virtual int font_size() const;
|
||||||
@ -28,7 +37,17 @@ protected:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
bool main_loop(); // Internal use only
|
bool main_loop(); // Internal use only
|
||||||
virtual bool print(); // Use this
|
virtual bool print(); // Use this ...
|
||||||
|
virtual bool preview(); // ... and this
|
||||||
|
virtual void print_page(word page); // Inefficient default implementation
|
||||||
|
|
||||||
|
virtual TPoint page_size() const;
|
||||||
|
virtual TPoint page_res() const;
|
||||||
|
virtual word last_printed_page() { return _lastprinted; }
|
||||||
|
|
||||||
|
bool print_mode() const { return _preview_mask == NULL; }
|
||||||
|
bool preview_mode() const { return _preview_mask != NULL; }
|
||||||
|
|
||||||
TPage_printer();
|
TPage_printer();
|
||||||
virtual ~TPage_printer();
|
virtual ~TPage_printer();
|
||||||
};
|
};
|
||||||
@ -37,7 +56,6 @@ class TReport_printer : public TPage_printer
|
|||||||
{
|
{
|
||||||
TReport& _report;
|
TReport& _report;
|
||||||
TPoint _delta;
|
TPoint _delta;
|
||||||
double _kx, _ky;
|
|
||||||
long _logical_page_height;
|
long _logical_page_height;
|
||||||
long _logical_foot_pos;
|
long _logical_foot_pos;
|
||||||
bool _is_last_page, _page_break_allowed;
|
bool _is_last_page, _page_break_allowed;
|
||||||
@ -48,7 +66,6 @@ protected:
|
|||||||
virtual int font_size() const;
|
virtual int font_size() const;
|
||||||
|
|
||||||
virtual PNT log2dev(long x, long y) const;
|
virtual PNT log2dev(long x, long y) const;
|
||||||
virtual TPoint dev2log(const PNT& p) const;
|
|
||||||
virtual bool print_loop();
|
virtual bool print_loop();
|
||||||
|
|
||||||
virtual bool open_page();
|
virtual bool open_page();
|
||||||
|
51
ba/ba8303.uml
Executable file
51
ba/ba8303.uml
Executable file
@ -0,0 +1,51 @@
|
|||||||
|
TOOLBAR "Toolbar" 0 -2 0 2
|
||||||
|
|
||||||
|
BUTTON DLG_PREVREC 3
|
||||||
|
BEGIN
|
||||||
|
PROMPT -46 -2 ""
|
||||||
|
PICTURE 122
|
||||||
|
END
|
||||||
|
|
||||||
|
BUTTON DLG_FIRSTREC 3
|
||||||
|
BEGIN
|
||||||
|
PROMPT -46 -1 ""
|
||||||
|
PICTURE 121
|
||||||
|
END
|
||||||
|
|
||||||
|
BUTTON DLG_FINDREC 10 2
|
||||||
|
BEGIN
|
||||||
|
PROMPT -46 -1 ""
|
||||||
|
PICTURE 166
|
||||||
|
END
|
||||||
|
|
||||||
|
BUTTON DLG_NEXTREC 3
|
||||||
|
BEGIN
|
||||||
|
PROMPT -46 -2 ""
|
||||||
|
PICTURE 124
|
||||||
|
END
|
||||||
|
|
||||||
|
BUTTON DLG_LASTREC 3
|
||||||
|
BEGIN
|
||||||
|
PROMPT -46 -1 ""
|
||||||
|
PICTURE 125
|
||||||
|
END
|
||||||
|
|
||||||
|
BUTTON DLG_QUIT 10 2
|
||||||
|
BEGIN
|
||||||
|
PROMPT -66 -1 "~Fine"
|
||||||
|
PICTURE BMP_QUIT
|
||||||
|
END
|
||||||
|
|
||||||
|
ENDPAGE
|
||||||
|
|
||||||
|
PAGE "Anteprima" -1 -1 60 13
|
||||||
|
|
||||||
|
PREVIEW DLG_USER -3 -1
|
||||||
|
BEGIN
|
||||||
|
PROMPT 0 0 ""
|
||||||
|
END
|
||||||
|
|
||||||
|
ENDPAGE
|
||||||
|
|
||||||
|
ENDMASK
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user