Files correlati : ba8.exe Ricompilazione Demo : [ ] Commento : Corretto salvataggio report. Questa versione e' in grado di stampare veramente! git-svn-id: svn://10.65.10.50/trunk@11920 c028cbd2-c16b-5b4b-a496-9718f37d4682
292 lines
8.1 KiB
C++
Executable File
292 lines
8.1 KiB
C++
Executable File
#ifndef __REPORT_H
|
|
#define __REPORT_H
|
|
|
|
#ifndef __ASSOC_H
|
|
#include <assoc.h>
|
|
#endif
|
|
|
|
#ifndef __WINDOW_H
|
|
#include <window.h>
|
|
#endif
|
|
|
|
#ifndef __XML_H
|
|
#include <xml.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;
|
|
|
|
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 _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; }
|
|
|
|
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 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
|
|
TRectangle _rct; // 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(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_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:
|
|
PRINT_RCD* _rcd;
|
|
long _pw, _ph, _phr, _pvr; // Printer width, height, horizontal and vertical resolution
|
|
word _copies, _pagefrom, _pageto, _page;
|
|
bool _page_is_open;
|
|
|
|
virtual word pages() const { return 0; }
|
|
virtual bool print_loop() pure;
|
|
|
|
protected:
|
|
virtual const char* form_name() const;
|
|
virtual const char* font_name() const;
|
|
virtual int font_size() const;
|
|
virtual bool ask_pages();
|
|
|
|
virtual bool open_page();
|
|
virtual bool close_page();
|
|
bool page_in_range() const;
|
|
|
|
public:
|
|
bool main_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;
|
|
long _logical_page_height;
|
|
long _logical_foot_pos;
|
|
bool _is_last_page;
|
|
|
|
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;
|
|
virtual bool print_loop();
|
|
|
|
virtual bool open_page();
|
|
virtual bool close_page();
|
|
long print_section(TReport_section& rs);
|
|
long print_section(char type, int level);
|
|
|
|
public:
|
|
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
|