campo-sirio/include/report.h

542 lines
17 KiB
C
Raw Normal View History

#ifndef __REPORT_H
#define __REPORT_H
#ifndef __IMAGE_H
#include <image.h>
#endif
#ifndef __WINDOW_H
#include <window.h>
#endif
#ifndef __XML_H
#include <xml.h>
#endif
#ifndef __RECORDSET_H
#include <recset.h>
#endif
#ifndef __ALEX_H
#include <alex.h>
#endif
///////////////////////////////////////////////////////////
// TReport_font
///////////////////////////////////////////////////////////
class TReport_font : public TSortable
{
enum { DEFAULT_FONT_SIZE = 10 };
TString _name;
int _size, _cpi;
XVT_FONT_STYLE_MASK _style;
WINDOW _win_mapped;
XVT_FNTID _fontid;
int _leading, _ascent, _descent;
protected:
virtual int compare(const TSortable& s) const;
void copy(const TReport_font& f);
public:
const TString& name() const { return _name; }
int size() const { return _size; }
XVT_FONT_STYLE_MASK style() const { return _style; }
int cpi() const { return _cpi; }
XVT_FNTID get_xvt_font(const TWindow& win) const;
XVT_FNTID get_preview_font(const TWindow& win, const TPoint& res) const;
void unmap();
int leading() const { return _leading; }
int ascent() const { return _ascent; }
int descent() const { return _descent; }
void save(TXmlItem& root) const;
bool load(const TXmlItem& root);
void adapt(const TReport_font& oldfont, const TReport_font& newfont);
void create(const char* name, int size, XVT_FONT_STYLE_MASK style);
TReport_font& operator=(const TReport_font& f) { copy(f); return *this; }
TReport_font();
TReport_font(const TReport_font& f);
virtual ~TReport_font();
};
class TBook;
class TReport;
class TReport_field;
///////////////////////////////////////////////////////////
// Cache varie
///////////////////////////////////////////////////////////
class TReport_expr;
class TReport_expr_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; }
TReport_expr_cache() : _report(NULL) { }
};
class TReport_image_cache : public TCache
{
protected:
virtual TObject* key2obj(const char* key);
public:
TImage* image(const TString& name);
TReport_image_cache();
};
///////////////////////////////////////////////////////////
// TReport_script
///////////////////////////////////////////////////////////
class TReport_script : public TObject
{
TBytecode* _bc; // Chesire's cat class
TString _src, _desc;
protected:
void destroy();
TString& translate_message(TReport& report) const;
void copy(const TReport_script& rs);
public:
virtual bool ok() const { return !_src.blank(); }
void set(const char* source);
const TString& get() const { return _src; }
void set_description(const char* d) { _desc = d; }
bool compile(TReport& report);
bool execute(TReport& report);
bool execute(TReport_field& rf);
void save(TXmlItem& root, const char* tag) const;
bool load(const TXmlItem& root, const char* tag);
TReport_script& operator =(const TReport_script& rs) { copy(rs); return *this; }
TReport_script();
TReport_script(const TReport_script& rs) { copy(rs); }
virtual ~TReport_script();
};
///////////////////////////////////////////////////////////
// TReport_section
///////////////////////////////////////////////////////////
enum TReport_draw_mode { rdm_print, rdm_preview };
class TReport_section : public TArray
{
TReport& _report;
char _type; // Head,Body,Tail
int _level; // 0,1,2,...
TPoint _pos; // Posizione assoluta in centesimi, default (0,0)
TPoint _size; // Dimensioni in centesimi, default (0,0)
TString _condition, _groupby;
bool _page_break, _hidden_if_needed, _can_break, _keep_with_next, _repeat;
bool _hidden, _deactivated;
COLOR _fgcolor, _bgcolor;
int _border, _radius;
PAT_STYLE _pattern;
TReport_script _prescript, _postscript;
TReport_font *_font, *_print_font;
TRecordset* _recordset;
protected:
virtual const char* class_name() const { return "ReportSection"; }
TReport_section* father_section() const;
bool print_tools(TBook& book) const;
public:
virtual int add(TObject* obj);
virtual int add(TObject& obj);
TReport_field& field(int i) { return *(TReport_field*)objptr(i); }
const TReport_field& field(int i) const { return *(TReport_field*)objptr(i); }
int find_field_pos(int id);
TReport_field* find_field(int id);
TReport& report() { return _report; }
char type() const { return _type; }
int level() const { return _level; }
int width() const { return _size.x; }
int height() const { return _size.y; }
void set_width(short w) { _size.x = w; }
void set_height(short h) { _size.y = h; }
const TPoint& size() const { return _size; }
TPoint compute_size() const;
bool compute_rect(TRectangle& rct) const;
const TPoint& pos() const { return _pos; }
void set_pos(const TPoint& p) { _pos = p; }
void set_fore_color(COLOR c) { _fgcolor = c; }
COLOR fore_color() const { return _fgcolor; }
void set_back_color(COLOR c) { _bgcolor = c; }
COLOR back_color() const { return _bgcolor; }
void set_border(int b) { _border = b; }
short border() const { return _border; }
void set_pattern(PAT_STYLE p) { _pattern = p; }
PAT_STYLE pattern() const { return _pattern; }
void set_radius(int r) { _radius = r; }
short radius() const { return _radius; }
bool page_break() const { return _page_break; }
void force_page_break(bool pb) { _page_break = pb; }
void set_repeat_on_page(bool r) { _repeat = r; }
bool repeat_on_page() const { return _repeat; }
const TString& condition() const { return _condition; }
void set_condition(const char* str) { _condition = str; }
const TString& grouped_by() const { return _groupby; }
void group_by(const char* gb) { _groupby = gb; }
bool hidden_if_needed() const { return _hidden_if_needed; }
void hide_if_needed(bool h) { _hidden_if_needed = h; }
bool can_be_broken() const;
void can_break(bool k) { _can_break = k; }
bool keep_with_next() const;
void keep_with_next(bool k) { _keep_with_next = k; }
bool hidden() const { return _hidden; }
bool shown() const { return !hidden(); }
void show(bool on) { _hidden = !on; }
void hide() { show(false); }
bool deactivated() const { return _deactivated; }
bool active() const { return !deactivated(); }
void activate(bool on) { _deactivated = !on; }
void deactivate() { activate(false); }
const TString& prescript() const;
void set_prescript(const char* src);
const TString& postscript() const;
void set_postscript(const char* src);
void update_recordset_parent(); // Internal use only
bool set_recordset(TRecordset* rs);
bool set_recordset(const TString& sql);
TRecordset* recordset() const { return _recordset; }
bool get_record_field(const char* name, TVariant& var) const;
bool has_font() const { return _font != NULL; }
const TReport_font& font() const;
const TReport_font& print_font() const;
void set_font(const TReport_font& f);
void unmap_font();
void compute_print_font(const TReport_font& oldfont, const TReport_font& newfont);
bool load_fields();
bool execute_prescript();
bool execute_postscript();
void print(TBook& book) const;
void print_clipped(TBook& book, long top, long bottom) const;
void save(TXmlItem& report) const;
void load(const TXmlItem& sec);
TReport_section(TReport& r, char t, int l);
virtual ~TReport_section();
};
struct TReport_array_item;
class TReport_field : public TSortable
{
TReport_section* _section;
int _id;
char _type; // Text, String, Numeric, Price, Valuta, Date, Line, Rectangle, Image
TRectangle _rct; // In centesimi
COLOR _fgcolor, _bgcolor;
int _border, _radius, _shade_offset;
PAT_STYLE _pattern;
char _halign, _valign;
bool _dynamic_height;
TBit_array _groups;
TString _picture, _codval, _link;
TString _field, _alt_field;
TVariant _var;
TReport_script _prescript, _postscript;
TArray _list; // Elementi di un campo lista
TReport_font *_font, *_print_font;
bool _hidden, _deactivated, _hide_zeroes, _selected;
TRectangle _draw_rct; // In centesimi
bool _draw_hidden, _draw_deactivated;
protected:
virtual const char* class_name() const { return "ReportField"; }
virtual int compare(const TSortable& s) const;
void copy(const TReport_field& rf);
TFieldtypes var_type() const;
const TString& formatted_text() const;
void get_currency(TCurrency& cur) const;
TReport_array_item* get_array_item() const;
public:
virtual TObject* dup() const { return new TReport_field(*this); }
TReport_field& operator=(const TReport_field& rf) { copy(rf); return *this; }
TReport_section& section() const { return *_section; }
void set_section(TReport_section* sec) { _section = sec; }
bool has_font() const { return _font != NULL; }
const TReport_font& font() const;
const TReport_font& print_font() const;
void set_font(const TReport_font& f);
void unmap_font();
void compute_print_font(const TReport_font& oldfont, const TReport_font& newfont);
const TString& picture() const { return _picture; }
void set_picture(const char* str) { _picture = str; }
const TString& field() const { return _field; }
void set_field(const char* str) { _field = str; }
const TString& alternate_field() const { return _alt_field; }
void set_alternate_field(const char* str) { _alt_field = str; }
const TVariant& get() const { return _var; }
void set(const char* str);
void set(const TVariant& var);
bool load_field();
bool execute_prescript();
bool execute_postscript();
void get_list(TString_array& list) const;
void set_list(const TString_array& list);
int id() const { return _id; }
void set_id(int id) { _id = id; }
char type() const { return _type; }
const char* type_name() const;
void set_type(char t) { _type = t; }
void set_pos(long x, long y);
void set_row(long y) { _rct.y = y; }
void set_column(long x) { _rct.x = x; }
void set_size(long w, long h);
void set_width(long dx) { _rct.set_width(dx); }
void set_height(long dy) { _rct.set_height(dy); }
const TRectangle& get_rect() const { return _rct; }
void set_dynamic_height(bool dh);
bool dynamic_height() const;
bool hidden() const { return _hidden; }
bool shown() const { return !hidden(); }
void show(bool on) { _hidden = !on; }
void hide() { show(false); }
bool deactivated() const { return _deactivated; }
bool active() const { return !deactivated(); }
void activate(bool on) { _deactivated = !on; }
void deactivate() { activate(false); }
bool zeroes_hidden() const;
void hide_zeroes(bool hz) { _hide_zeroes = hz; }
bool draw_hidden() const { return _draw_hidden; }
bool draw_deactivated() const { return _draw_deactivated; }
void set_draw_hidden(bool h) { _draw_hidden = h; }
void set_draw_deactivated(bool d) { _draw_deactivated = d; }
void set_draw_pos(long x, long y);
void set_draw_size(long x, long y);
const TRectangle& get_draw_rect() const;
void set_groups(const TString& groups);
const TString& groups() const;
bool in_group(int group) const;
void set_codval(const char* cod) { _codval = cod; }
const TString& codval() const { return _codval; }
void set_link(const char* l) { _link = l; }
const TString& link() const { return _link; } // TABLE.FIELD
void set_fore_color(COLOR c) { _fgcolor = c; }
COLOR fore_color() const { return _fgcolor; }
void set_back_color(COLOR c) { _bgcolor = c; }
COLOR back_color() const { return _bgcolor; }
COLOR link_color() const;
void set_border(int b) { _border = b; }
short border() const { return _border; }
void set_pattern(PAT_STYLE p) { _pattern = p; }
PAT_STYLE pattern() const { return _pattern; }
void set_radius(int r) { _radius = r; }
short radius() const { return _radius; }
void set_shade_offset(int s) { _shade_offset = s; }
short shade_offset() const { return _shade_offset; }
void set_horizontal_alignment(char a) { _halign = a; }
char horizontal_alignment() const { return _halign; }
void set_vertical_alignment(char a) { _valign = a; }
char vertical_alignment() const { return _valign; }
const TString& prescript() const;
void set_prescript(const char* src);
const TString& postscript() const;
void set_postscript(const char* src);
void select(bool ok = true) { _selected = ok; }
bool selected() const { return _selected; }
void offset(const TPoint& pt);
virtual bool print_tools(TBook& book) const;
virtual void print_rect(TBook& book) const;
virtual void print(TBook& book) const;
void save(TXmlItem& root) const;
bool load(const TXmlItem& root);
TReport_field(TReport_section* sec);
TReport_field(const TReport_field& rf);
virtual ~TReport_field();
};
class TReport_link : public TSortable
{
TString _table;
TAssoc_array _fields;
RCT _rct;
protected:
virtual int compare(const TSortable& s) const;
public:
const TString& table() const { return _table; }
void set(const char* field, const TString& value);
const TString& get(const char* field) const;
void add_rect(const RCT& rct); // Aggiunge un rettangolo al link
int hit_test(const PNT& p) const;
TAssoc_array& fields() const { return (TAssoc_array&)_fields; }
TReport_link(const char* table);
virtual ~TReport_link() { }
};
// Internal usage only
typedef void (*FLDMSG_FUNC)(TReport_field& rf, void* jolly);
class TReport : public TAlex_virtual_machine
{
TAssoc_array _sections;
TFilename _path;
TString _description;
TReport_font _font, _print_font; // Font
int _lpi; // Lines per inch
TToken_string _include;
TReport_script _prescript, _postscript;
TString_array _params;
TRecordset* _recordset;
TReport_expr_cache _expressions;
word _rep_page, _book_page;
bool _use_printer_font;
TReport_field* _curr_field;
protected:
virtual const char* class_name() const { return "Report"; }
virtual size_t get_usr_words(TString_array& words) const;
virtual bool execute_usr_word(unsigned int opcode, TVariant_stack& stack);
virtual bool get_usr_val(const TString& name, TVariant& var) const;
virtual bool set_usr_val(const TString& name, const TVariant& var);
KEY run_form(const TString& msk);
bool do_message(const TVariant& var, FLDMSG_FUNC msg, void* jolly);
void do_isam_read_output(const TRectype& rec, TToken_string& out);
void msg_isam_read(TVariant_stack& stack);
void msg_table_read(TVariant_stack& stack);
void build_section_key(char type, int level, TString& key) const;
short get_num_attr(const TXmlItem& item, const char* attr, short def = 0) const;
COLOR get_col_attr(const TXmlItem& item, const char* attr, COLOR defcol = COLOR_BLACK) const;
void load_sections(const TXmlItem& xml);
void save_section(const TReport_section& rs, TXmlItem& item) const;
void update_recordset_parent(); // Internal use only
bool get_report_field(const TString& name, TVariant& var) const;
bool get_record_field(const TString& name, TVariant& var) const;
public:
TReport_section* find_section(char type, int level) const;
TReport_section& section(char type, int level);
bool kill_section(char type, int level);
int find_max_level(char type) const;
virtual bool on_link(const TReport_link& link);
const TReport_font& font() const { return _font; }
const TReport_font& print_font() const;
void set_use_printer_font(bool on) { _use_printer_font = on; }
bool use_printer_font() const { return _use_printer_font; }
void set_font(const TReport_font& f) { _font = f; }
void unmap_font();
void load_printer_font();
int cpi() const;
int lpi() const;
void set_lpi(int lpi) { _lpi = lpi; }
int print_cpi() const;
int print_lpi() const;
bool set_recordset(const TString& sql);
bool set_recordset(TRecordset* sql);
TRecordset* recordset() const { return _recordset; }
bool evaluate_atom(const char* atom, TVariant& var);
bool evaluate(const char* expr, TVariant& var, TFieldtypes force_type);
const TString& prescript() const;
void set_prescript(const char* src);
const TString& postscript() const;
void set_postscript(const char* src);
virtual bool execute_prescript();
virtual bool execute_postscript();
const TString_array& params() const { return _params; }
void set_params(const TString_array& p) { _params = p; }
void set_libraries(const char* inc) { _include = inc; }
TToken_string& get_libraries() { return _include; }
virtual void include_libraries(bool reload = false);
void set_description(const char* d) { _description = d; }
const TString& description() const { return _description; }
const TFilename& filename() const { return _path; }
bool save(const char* fname) const;
bool load(const char* fname);
// Used by TReport_printer
void set_page(word r, word p) { _rep_page = r; _book_page = p; }
void set_curr_field(TReport_field* fld) { _curr_field = fld; }
TReport_field* curr_field() const { return _curr_field; }
int parse_field(const char* code, char& type, int& level, int& id) const;
TReport_field* field(const char* code);
void destroy();
TReport();
virtual ~TReport();
};
#endif