#ifndef __REPORT_H #define __REPORT_H #ifndef __ASSOC_H #include #endif #ifndef __WINDOW_H #include #endif #ifndef __XML_H #include #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; 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,... short _width, _height; // In centesimi TString _groupby; bool _hidden_if_needed; 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); } TReport& report() { return _report; } char type() const { return _type; } int level() const { return _level; } short width() const { return _width; } short height() const { return _height; } void set_width(short w) { _width = w; } void set_height(short h) { _height = h; } bool get_rect(RCT& rct) const; 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 has_font() const { return _font != NULL; } const TReport_font& font() const; void set_font(const TReport_font& f); void compute_values(); void draw(TWindow& win, TReport_draw_mode mode) const; TReport_section(TReport& r, 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 _fgcolor, _bgcolor; short _border; char _halign, _valign; TString _picture, _field; TString _value; TReport_font* _font; bool _selected; protected: void copy(const TReport_field& rf); 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; } char type() const { return _type; } const char* type_name() const; 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; } bool compute_value(); void set_type(char t) { _type = t; } void set_pos(short x, short y); void set_row(short y) { _y = y; } void set_column(short x) { _x = x; } void set_size(short w, short h); void set_width(short dx) { _width = dx; } void set_height(short dy) { _height = dy; } void get_rect(RCT& rct) const; 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; } 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 TRecordset; class TReport : public TObject { TAssoc_array _sections; TFilename _path; TString _description; TReport_font _font; int _lpi; // Lines per inch TRecordset* _recordset; protected: 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; } 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); void destroy(); TReport(); virtual ~TReport(); }; class TPage_printer : public TWindow { protected: long _pw, _ph, _phr, _pvr; // Printer width, height, horizontal and vertical resolution word _copies, _pagefrom, _pageto; bool print_band(word page, const RCT& rct); protected: virtual const char* form_name() const; virtual const char* font_name() const; virtual int font_size() const; virtual bool ask_pages(); public: virtual word pages() const pure; virtual bool print_page(word p) pure; virtual bool print_loop(); // Internal use only virtual bool print(); // Use this TPage_printer(); virtual ~TPage_printer(); }; class TReport_printer : public TPage_printer { TReport& _report; TPoint _delta; double _kx, _ky; protected: virtual const char* form_name() const; virtual const char* font_name() const; virtual int font_size() const; virtual PNT log2dev(long x, long y) const; virtual TPoint dev2log(const PNT& p) const; public: virtual word pages() const; virtual bool print_page(word p); TReport_printer(TReport& r) : _report(r) { } }; 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