#ifndef __REPORT_H #define __REPORT_H #ifndef __ASSOC_H #include #endif #ifndef __WINDOW_H #include #endif #ifndef __XML_H #include #endif #ifndef __RECORDSET_H #include "ba8201.h" #endif #ifndef __ALEX_H #include "ba8304.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; 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 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 TReport; class TReport_field; /////////////////////////////////////////////////////////// // 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 { TBytecode* _bc; // Chesire's cat class TString _src; protected: void destroy(); public: virtual bool ok() const { return !_src.blank(); } void set(const char* source); const TString& get() const { return _src; } bool execute(TReport& report, TString& output); bool execute(TReport_field& rf); void save(TXmlItem& root, const char* tag) const; bool load(const TXmlItem& root, const char* tag); TReport_script(); virtual ~TReport_script(); }; /////////////////////////////////////////////////////////// // TReport_section /////////////////////////////////////////////////////////// enum TReport_draw_mode { rdm_edit, rdm_print, rdm_print_preview }; class TReport_section : public TArray { TReport& _report; char _type; // Head,Body,Tail int _level; // 0,1,2,... TPoint _size; // In centesimi TString _groupby; bool _page_break, _hidden_if_needed, _hidden, _deactivated; TReport_script _prescript, _postscript; TReport_font* _font; protected: TReport_section* father_section() 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; bool page_break() const { return _page_break; } void force_page_break(bool pb) { _page_break = pb; } 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 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 { return _prescript.get(); } void set_prescript(const char* src) { _prescript.set(src); } const TString& postscript() const { return _postscript.get(); } void set_postscript(const char* src) { _postscript.set(src); } bool has_font() const { return _font != NULL; } const TReport_font& font() const; void set_font(const TReport_font& f); bool execute_prescript(); bool execute_postscript(); void draw(TWindow& win, TReport_draw_mode mode) const; void save(TXmlItem& report) const; void load(const TXmlItem& sec); TReport_section(TReport& r, char t, int l); virtual ~TReport_section(); }; class TReport_field : public TObject { TReport_section* _section; int _id; char _type; // Text, String, Numeric, Date, Line, Rectangle, Image TRectangle _rct; // In centesimi COLOR _fgcolor, _bgcolor; short _border; char _halign, _valign; TString _picture, _field; TVariant _var; TReport_script _prescript, _postscript; TReport_font* _font; bool _hidden, _deactivated, _selected; protected: void copy(const TReport_field& rf); TFieldtypes var_type() 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() { return *_section; } void set_section(TReport_section* sec) { _section = sec; } bool has_font() const { return _font != NULL; } const TReport_font& font() const; void set_font(const TReport_font& f); 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 TVariant& get() const { return _var; } void set(const char* str); void set(const TVariant& var); bool execute_prescript(); bool execute_postscript(); 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; } 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); } 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(short b) { _border = b; } short border() const { return _border; } 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 { return _prescript.get(); } void set_prescript(const char* src) { _prescript.set(src); } const TString& postscript() const { return _postscript.get(); } void set_postscript(const char* src) { _postscript.set(src); } void select(bool ok = true) { _selected = ok; } bool selected() const { return _selected; } void offset(const TPoint& pt); virtual void draw_rect(TWindow& win) const; virtual void draw_text(TWindow& win, const char* text) const; virtual void draw(TWindow& win, TReport_draw_mode mode) 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 : public TAlex_virtual_machine { TAssoc_array _sections; TFilename _path; TString _description; TReport_font _font; int _lpi; // Lines per inch TRecordset* _recordset; TExpression_cache _expressions; TField_cache _fields; word _curr_page; TReport_field* _curr_field; protected: virtual unsigned int compile_usr_word(const TString& name) 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); 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; 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; const TReport_font& font() const { return _font; } void set_font(const TReport_font& f) { _font = f; } int cpi() const { return _font.cpi(); } int lpi() const { return _lpi; } void set_lpi(int lpi) { _lpi= lpi; } 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); 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_curr_page(word p) { _curr_page = p; } word curr_page() const { return _curr_page; } void set_curr_field(TReport_field* fld) { _curr_field = fld; } TReport_field* curr_field() const { return _curr_field; } TReport_field* field(const TString& code); void destroy(); TReport(); virtual ~TReport(); }; void advanced_draw_rect(TWindow& win, const RCT& r, int border, COLOR fore, COLOR back); void advanced_draw_text(TWindow& win, const char* text, const RCT& r, char halign, char valign); #endif