Patch level : 2.1 48

Files correlati     :
Ricompilazione Demo : [ ]
Commento            :

Nuovi metodi per report


git-svn-id: svn://10.65.10.50/trunk@12111 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
guy 2004-05-24 12:51:22 +00:00
parent 7e9576ecef
commit 9963ab9ec0
4 changed files with 330 additions and 132 deletions

View File

@ -247,11 +247,12 @@ TReport_image_cache::TReport_image_cache() : TCache(7)
// Utility
///////////////////////////////////////////////////////////
void advanced_draw_rect(TWindow& win, const RCT& r, int border, COLOR fore, COLOR back)
bool advanced_set_draw_tools(TWindow& win, int border, COLOR fore, COLOR back)
{
const bool has_pen = border > 0;
const bool has_brush = (back & 0xFFFFFF) != (COLOR_WHITE & 0xFFFFFF);
if (has_pen || has_brush)
const bool visible = has_pen || has_brush;
if (visible)
{
if (has_pen)
win.set_pen(fore, border, PAT_SOLID);
@ -261,8 +262,14 @@ void advanced_draw_rect(TWindow& win, const RCT& r, int border, COLOR fore, COLO
win.set_brush(back, PAT_SOLID);
else
win.hide_brush();
xvt_dwin_draw_rect(win.win(), (RCT*)&r);
}
return visible;
}
void advanced_draw_rect(TWindow& win, const RCT& r, int border, COLOR fore, COLOR back)
{
if (advanced_set_draw_tools(win, border, fore, back))
xvt_dwin_draw_rect(win.win(), (RCT*)&r);
}
void advanced_draw_justified_text(TWindow& win, const char* text, short x, short y, short dx)
@ -515,7 +522,7 @@ bool TReport_section::compute_rect(TRectangle& rct) const
void TReport_section::draw(TWindow& win, TReport_draw_mode rdm) const
{
if (shown() || rdm == rdm_edit)
if (shown() && active())
{
for (int i = 0; i < items(); i++)
{
@ -898,38 +905,26 @@ void TReport_field::set_draw_size(long w, long h)
_draw_rct.set_height(h);
}
void TReport_field::compute_draw_rect() const
const TRectangle& TReport_field::get_draw_rect() const
{
TRectangle& rct = ((TReport_field*)this)->_draw_rct;
rct = _rct;
if (type() == 'S')
if (dynamic_height())
{
if (rct.width() <= 0)
{
TString text = formatted_text(); text.rtrim();
TToken_string str(text, '\n');
int maxlen = 1;
FOR_EACH_TOKEN(str, line)
{
const int len = strlen(line);
if (len > maxlen)
maxlen = len;
}
rct.set_width(maxlen * 100);
}
if (rct.height() <= 0)
{
if (rct.width() >= 100)
{
TString text = formatted_text(); text.rtrim();
TParagraph_string str(text, rct.width()/100);
rct.set_height(str.items() * 100);
}
if (rct.height() <= 0)
rct.set_height(100);
}
TRectangle& rct = ((TReport_field*)this)->_draw_rct;
rct = _rct;
int h = 100;
TParagraph_string str(formatted_text(), rct.width()/100);
str.rtrim();
h = str.items() * 100;
if (h <= 0)
h = 100;
if (h > _rct.height())
h = _rct.height();
rct.set_height(h);
return rct;
}
return _rct;
}
const TReport_font& TReport_field::font() const
@ -1097,7 +1092,6 @@ bool TReport_field::execute_prescript()
if (item != NULL)
ok = item->_script.execute(*this);
}
compute_draw_rect();
}
return ok;
}
@ -1124,7 +1118,7 @@ void TReport_field::draw_text(TWindow& win, const char* text, TReport_draw_mode
RCT r; win.log2dev(rct, r);
advanced_draw_rect(win, r, border(), fore_color(), back_color());
if (rdm == rdm_print_preview && link().not_empty())
if (rdm == rdm_preview && link().not_empty())
{
XVT_FNTID lnkfont = xvt_font_create();
xvt_font_copy(lnkfont, font().get_xvt_font(win), XVT_FA_ALL);
@ -1251,7 +1245,7 @@ const TString& TReport_field::formatted_text() const
{
TCurrency cur; get_currency(cur);
TString& tmp = get_tmp_string();
const bool dotted = _picture.find('.' > 0);
const bool dotted = _picture.find('.') > 0;
tmp = cur.string(dotted);
return tmp;
}
@ -1273,100 +1267,41 @@ const TString& TReport_field::formatted_text() const
void TReport_field::draw(TWindow& win, TReport_draw_mode rdm) const
{
PAT_STYLE back_pattern = PAT_HOLLOW;
if (draw_hidden() || draw_deactivated())
return;
if (rdm == rdm_edit)
{
compute_draw_rect();
if (hidden() || deactivated())
{
if (hidden() && deactivated())
back_pattern = PAT_DIAGCROSS;
else
back_pattern = hidden() ? PAT_FDIAG : PAT_BDIAG;
}
}
else
{
if (draw_hidden() || draw_deactivated())
return;
}
RCT r; win.log2dev(get_draw_rect(), r);
switch (_type)
{
case 'E':
{
const bool has_pen = border() > 0;
const bool has_brush = color_distance(back_color(), COLOR_WHITE) != 0;
if (has_pen)
win.set_pen(fore_color(), border(), PAT_SOLID);
else
win.hide_pen();
if (has_brush)
win.set_brush(back_color(), PAT_SOLID);
else
win.hide_brush();
RCT r; win.log2dev(get_rect(), r);
xvt_dwin_draw_oval(win.win(), &r);
if (rdm == rdm_edit && back_pattern != PAT_HOLLOW)
{
win.set_brush(COLOR_GRAY, back_pattern);
xvt_dwin_draw_oval(win.win(), &r);
back_pattern = PAT_HOLLOW;
}
}
if (advanced_set_draw_tools(win, border(), fore_color(), back_color()))
xvt_dwin_draw_oval(win.win(), &r);
break;
case 'I':
{
RCT r; win.log2dev(get_rect(), r);
TReport& rep = section().report();
if (rdm == rdm_edit)
{
TVariant var;
section().report().evaluate(_field, var, _alfafld);
const TString& name = var.as_string();
const TImage* img = rep.image(name);
if (img != NULL && img->ok())
img->draw(win.win(), r);
}
else
{
const TString& name = get().as_string();
const TImage* img = rep.image(name);
if (img != NULL && img->ok())
img->draw(win.win(), r);
}
const TString& name = get().as_string();
const TImage* img = rep.image(name);
if (img != NULL && img->ok())
img->draw(win.win(), r);
draw_rect(win);
}
break;
case 'L':
{
win.set_pen(fore_color(), border());
const TRectangle& r = get_rect();
win.line((short)r.left(), (short)r.top(), (short)r.right(), (short)r.bottom());
back_pattern = PAT_HOLLOW;
advanced_set_draw_tools(win, border(), fore_color(), back_color());
const PNT f = { r.top, r.left };
xvt_dwin_draw_set_pos(win.win(), f);
const PNT t = { r.bottom, r.right };
xvt_dwin_draw_line(win.win(), t);
}
break;
case 'R': draw_rect(win); break;
case 'R':
advanced_draw_rect(win, r, border(), fore_color(), back_color());
break;
case 'T': draw_text(win, _picture, rdm); break;
default :
if (rdm == rdm_edit)
{
if (border() <= 0) // Rendi piu' visibile il bordo dei campi che non ce l'hanno
{
RCT r; win.log2dev(get_draw_rect(), r);
advanced_draw_rect(win, r, 1, COLOR_LTGRAY, COLOR_WHITE);
}
if (id() > 0)
{
TString16 str; str << id();
draw_text(win, str, rdm);
}
else
draw_text(win, _field, rdm);
}
else // Real printing
{
const TString& str = formatted_text();
if (!str.blank())
@ -1374,24 +1309,64 @@ void TReport_field::draw(TWindow& win, TReport_draw_mode rdm) const
}
break;
}
}
if (rdm == rdm_edit)
void TReport_field::print(TBook& book) const
{
if (draw_hidden() || draw_deactivated())
return;
switch (_type)
{
RCT r; win.log2dev(get_rect(), r);
if (back_pattern != PAT_HOLLOW)
case 'E':
book.set_pen(fore_color(), border());
book.set_brush(back_color());
book.draw_ellipse(get_draw_rect());
break;
case 'I':
{
win.set_pen(COLOR_LTGRAY);
win.set_brush(COLOR_LTGRAY, back_pattern);
xvt_dwin_draw_rect(win.win(), &r);
const TString& name = get().as_string();
book.draw_image(get_draw_rect(), name);
if (border() > 0)
{
book.set_pen(fore_color(), border());
book.set_brush(COLOR_WHITE);
book.draw_rectangle(get_draw_rect());
}
}
if (selected())
break;
case 'L':
book.set_pen(fore_color(), border());
book.draw_line(get_draw_rect());
break;
case 'R':
book.set_pen(fore_color(), border());
book.set_brush(back_color());
book.draw_rectangle(get_draw_rect());
break;
case 'T':
if (!_picture.blank())
{
const int k = 4;
RCT s = r; s.right = s.left+k; s.bottom = s.top+k;
advanced_draw_rect(win, s, 0, COLOR_WHITE, COLOR_LTGRAY);
s = r; s.left = s.right-k; s.top = s.bottom-k;
advanced_draw_rect(win, s, 0, COLOR_WHITE, COLOR_LTGRAY);
book.set_font(font());
book.set_text_align(horizontal_alignment(), vertical_alignment());
book.draw_text(get_draw_rect(), _picture);
}
break;
default :
{
book.set_pen(fore_color(), border());
book.set_brush(back_color());
book.draw_rectangle(get_draw_rect());
const TString& str = formatted_text();
if (!str.blank())
{
book.set_font(font());
book.set_text_align(horizontal_alignment(), vertical_alignment());
book.draw_text(get_draw_rect(), str);
}
}
break;
}
}
@ -1426,6 +1401,7 @@ void TReport_field::save(TXmlItem& root) const
set_num_attr(fld, "y", rct.top());
set_num_attr(fld, "width", rct.width());
set_num_attr(fld, "height", rct.height(), 100);
fld.SetAttr("dynamic_height", dynamic_height());
fld.SetAttr("hidden", _hidden);
fld.SetAttr("deactivated", _deactivated);
fld.SetAttr("hide_zero", _hide_zeroes);
@ -1485,6 +1461,7 @@ bool TReport_field::load(const TXmlItem& fld)
set_row(get_num_attr(fld, "y"));
set_width(get_num_attr(fld, "width"));
set_height(get_num_attr(fld, "height", 100));
set_dynamic_height(fld.GetBoolAttr("dynamic_height"));
_draw_rct = _rct;
show(!fld.GetBoolAttr("hidden"));
activate(!fld.GetBoolAttr("deactivated"));
@ -1577,7 +1554,7 @@ int TReport_field::compare(const TSortable& s) const
TReport_field::TReport_field(TReport_section* sec)
: _section(sec), _id(0), _type('T'),
_font(NULL), _halign('L'), _valign('T'),
_font(NULL), _halign('L'), _valign('T'),_dynamic_height(false),
_selected(false), _hidden(false), _deactivated(false), _hide_zeroes(false),
_border(0), _fgcolor(COLOR_BLACK), _bgcolor(COLOR_WHITE), _rct(0,0,1000,100)
{ }

View File

@ -63,6 +63,45 @@ public:
virtual ~TReport_font();
};
class TBook : public TObject
{
size_t _pages;
TPointer_array _index;
TFilename _file;
ofstream* _out;
TPoint _delta;
DRAW_CTOOLS _tools;
TReport_font _font;
TRectangle _rect;
protected:
void define_frame(const TRectangle& rect);
void do_text(const TString& str);
public:
void start_page();
void close_page();
void set_pen(COLOR color, int width = 0, int style = P_SOLID);
void set_brush(COLOR color, int pattern = PAT_SOLID);
void set_font(const TReport_font& font);
void set_text_color(COLOR color);
void set_text_align(char halign ='L', char valign = 'T');
void draw_rectangle(const TRectangle& rect);
void draw_ellipse(const TRectangle& rect);
void draw_line(const TRectangle& rect);
void draw_image(const TRectangle& rect, const char* filename);
void draw_text(const TRectangle& rect, const char* text);
void draw_link(const TRectangle& rect, const char* text, const char* link);
size_t pages() const { return _pages; }
bool draw_page(TWindow& win, size_t page);
TBook(const char* name);
virtual ~TBook();
};
class TReport;
class TReport_field;
@ -133,7 +172,7 @@ public:
// TReport_section
///////////////////////////////////////////////////////////
enum TReport_draw_mode { rdm_edit, rdm_print, rdm_print_preview, rdm_spooler, rdm_textonly };
enum TReport_draw_mode { rdm_print, rdm_preview };
class TReport_section : public TArray
{
@ -231,6 +270,7 @@ class TReport_field : public TSortable
COLOR _fgcolor, _bgcolor;
short _border;
char _halign, _valign;
bool _dynamic_height;
TBit_array _groups;
TString _picture, _codval, _link;
TString _field, _alt_field;
@ -251,7 +291,6 @@ protected:
TFieldtypes var_type() const;
const TString& formatted_text() const;
void get_currency(TCurrency& cur) const;
void compute_draw_rect() const;
TReport_array_item* get_array_item() const;
public:
@ -299,6 +338,9 @@ public:
void set_height(long dy) { _rct.set_height(dy); }
const TRectangle& get_rect() const { return _rct; }
void set_dynamic_height(bool dh) { _dynamic_height = dh; }
bool dynamic_height() const { return _dynamic_height; }
bool hidden() const { return _hidden; }
bool shown() const { return !hidden(); }
void show(bool on) { _hidden = !on; }
@ -317,7 +359,7 @@ public:
void set_draw_pos(long x, long y);
void set_draw_size(long x, long y);
const TRectangle& get_draw_rect() const { return _draw_rct; }
const TRectangle& get_draw_rect() const;
void set_groups(const TString& groups);
const TString& groups() const;
@ -350,7 +392,9 @@ public:
virtual void draw_rect(TWindow& win) const;
virtual void draw_text(TWindow& win, const char* text, TReport_draw_mode mode) const;
virtual void draw(TWindow& win, TReport_draw_mode mode) const;
virtual void print(TBook& book) const;
void save(TXmlItem& root) const;
bool load(const TXmlItem& root);
@ -482,6 +526,7 @@ public:
virtual ~TReport();
};
bool advanced_set_draw_tools(TWindow& win, int border, COLOR fore, COLOR back);
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);

View File

@ -761,9 +761,9 @@ long TReport_printer::print_section(TReport_section& rs)
open_page();
}
if (_page_is_open)
rs.draw(*this, preview_mode() ? rdm_print_preview : rdm_print);
rs.draw(*this, preview_mode() ? rdm_preview : rdm_print);
if (rs.level() > 0) // Ho stampa qualcosa che non sia lo sfondo!
if (rs.level() > 0) // Ho stampato qualcosa che non sia lo sfondo!
_page_break_allowed = true;
}
@ -949,3 +949,174 @@ void lock_preview_update(bool yes)
void abort_printing()
{ _print_aborted = true; }
///////////////////////////////////////////////////////////
// TBook
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
// Writing a page
///////////////////////////////////////////////////////////
void TBook::start_page()
{
if (_out == NULL)
_out = new ofstream(_file);
_index.add_long(_out->tellp(), _pages);
*_out << "<page num=" << (_pages+1) << '>' << endl;
memset(&_tools, -1, sizeof(_tools));
_font.create("", 0, XVT_FA_ALL);
_delta.x = _delta.y = 0;
}
void TBook::close_page()
{
_pages++;
*_out << "</page num=" << _pages << '>' << endl;
}
void TBook::set_font(const TReport_font& f)
{
if (f != _font)
{
_font = f;
*_out << "<font"
<< " name=\"" << f.name() << '"'
<< " size=" << f.size()
<< " style=" << f.style()
<< " />" << endl;
}
}
void TBook::define_frame(const TRectangle& r)
{
if (r != _rect)
{
_rect = r;
*_out << "<frame"
<< " x=" << r.x << " y=" << r.y
<< " dx=" << r.width() << " dy=" << r.height()
<< " />" << endl;
}
}
void TBook::draw_text(const TRectangle& r, const char* txt)
{
define_frame(r);
*_out << "<text>" << endl << text << endl << "</text>" << endl;
}
void TBook::set_pen(COLOR color, int width, int style)
{
}
void TBook::set_brush(COLOR color, int pattern)
{
}
void TBook::set_text_color(COLOR color)
{
}
void TBook::set_text_align(char halign, char valign)
{
}
void TBook::draw_rectangle(const TRectangle& r)
{
define_frame(r);
*_out << "<rectangle />" << endl;
}
void TBook::draw_ellipse(const TRectangle& r)
{
define_frame(r);
*_out << "<ellipse />" << endl;
}
void TBook::draw_line(const TRectangle& r)
{
define_frame(r);
*_out << "<line />" << endl;
}
void TBook::draw_link(const TRectangle& rect, const char* text, const char* link)
{
draw_text(rect, text);
}
void TBook::draw_image(const TRectangle& rect, const char* name)
{
draw_rectangle(rect);
}
///////////////////////////////////////////////////////////
// Reading a page
///////////////////////////////////////////////////////////
void TBook::do_text(const TString& str)
{
}
bool TBook::draw_page(TWindow& win, size_t page)
{
if (page >= _pages)
return false;
TString str(1024);
char* buffer = str.get_buffer();
const streampos pos = _index.get_long(page);
ifstream ifs(_file);
ifs.seekg(pos);
while (!ifs.eof())
{
ifs.getline(buffer, str.size());
if (str.starts_with("</page"))
break;
if (str.starts_with("<frame"))
{
long x, y, dx, dy;
sscanf(str, "<frame x=%ld y=%ld dx=%ld dy=%ld />", &x, &y, &dx, &dy);
_rect.set(x, y, dx, dy);
continue;
}
if (str == "<text>")
{
TString stringona;
while (!ifs.eof())
{
ifs.getline(buffer, str.size());
if (str != "</text>")
stringona << str;
}
do_text(stringona);
continue;
}
}
return true;
}
TBook::TBook(const char* name) : _out(NULL)
{
_file = name;
if (_file.blank())
_file.temp("rep");
}
TBook::~TBook()
{
if (_out != NULL)
{
_out->close();
delete _out;
}
}

View File

@ -27,9 +27,9 @@ struct TPoint
// @cmember Operatore di assegnamento tra punti
TPoint& operator =(const TPoint& pnt) { x = pnt.x; y = pnt.y; return *this; }
// @cmember Confronta se due punti sono uguali (TRUE se uguali)
bool operator ==(const TPoint& p) { return p.x == x && p.y == y; }
bool operator ==(const TPoint& p) const { return p.x == x && p.y == y; }
// @cmember Confronta se due punti sono diversi (TRUE se diversi)
bool operator !=(const TPoint& p) { return p.x != x || p.y != y; }
bool operator !=(const TPoint& p) const { return p.x != x || p.y != y; }
TPoint& operator +=(const TPoint& pnt) { x += pnt.x; y += pnt.y; return *this; }
void reset() { x = y = 0; }
@ -68,6 +68,11 @@ public:
void merge(const TRectangle& r);
bool is_empty() const { return _size.x == 0 || _size.y == 0; }
// @cmember Confronta se due rettangoli sono uguali (TRUE se uguali)
bool operator ==(const TRectangle& p) const { return TPoint::operator ==(p) && _size == p._size; }
// @cmember Confronta se due rettangoli sono diversi (TRUE se diversi)
bool operator !=(const TRectangle& p) const { return TPoint::operator !=(p) || _size != p._size; }
TRectangle& operator=(const TRectangle& r) { copy(r); return *this; }
TRectangle() : TPoint(0,0), _size(0,0) { }
TRectangle(const TPoint& p, const TPoint& s) : TPoint(p), _size(s) { }