Patch level : 2.1 nopatch
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
This commit is contained in:
parent
aa56dda073
commit
9c482237d8
@ -39,6 +39,8 @@ public: // Absolutely needed methods
|
||||
virtual bool move_prev() { return move_to(current_row()-1); }
|
||||
virtual bool move_next() { return move_to(current_row()+1); }
|
||||
virtual bool move_last() { return move_to(items()-1); }
|
||||
virtual bool bof() const { return current_row() <= 0; }
|
||||
virtual bool eof() const { return current_row() >= items(); }
|
||||
|
||||
virtual unsigned int columns() const pure;
|
||||
virtual const TRecordset_column_info& column_info(unsigned int column) const pure;
|
||||
|
@ -162,8 +162,8 @@ protected:
|
||||
virtual void update();
|
||||
|
||||
public:
|
||||
void set_num(short id, short n);
|
||||
short get_num(short id) const;
|
||||
void set_num(short id, long n);
|
||||
long get_num(short id) const;
|
||||
|
||||
void set_field(const TReport_field& rf);
|
||||
void get_field(TReport_field& rf) const;
|
||||
@ -171,12 +171,12 @@ public:
|
||||
TReport_field_mask() :TFont_button_mask("ba8300b") { }
|
||||
};
|
||||
|
||||
void TReport_field_mask::set_num(short id, short num)
|
||||
void TReport_field_mask::set_num(short id, long num)
|
||||
{
|
||||
set(id, num2str(num));
|
||||
}
|
||||
|
||||
short TReport_field_mask::get_num(short id) const
|
||||
long TReport_field_mask::get_num(short id) const
|
||||
{
|
||||
return str2num(get(id));
|
||||
}
|
||||
@ -236,11 +236,11 @@ void TReport_field_mask::set_field(const TReport_field& rf)
|
||||
char str[2] = { rf.type(), '\0' };
|
||||
set(F_TYPE, str);
|
||||
|
||||
RCT r; rf.get_rect(r);
|
||||
set_num(F_X, r.left);
|
||||
set_num(F_Y, r.top);
|
||||
set_num(F_DX, r.right-r.left);
|
||||
set_num(F_DY, r.bottom-r.top);
|
||||
const TRectangle& r = rf.get_rect();
|
||||
set_num(F_X, r.left());
|
||||
set_num(F_Y, r.top());
|
||||
set_num(F_DX, r.width());
|
||||
set_num(F_DY, r.height());
|
||||
str[0] = rf.horizontal_alignment();
|
||||
set(F_HALIGN, str);
|
||||
str[0] = rf.vertical_alignment();
|
||||
@ -291,14 +291,14 @@ public:
|
||||
void TReport_sheet::get_row(long r, TToken_string& row)
|
||||
{
|
||||
const TReport_field& rf = (const TReport_field&)_section[r];
|
||||
RCT rect; rf.get_rect(rect);
|
||||
const TRectangle& rect = rf.get_rect();
|
||||
row.cut(0);
|
||||
row.add(checked(r) ? "X" : " ");
|
||||
row.add(rf.type_name());
|
||||
row.add(num2str(rect.top));
|
||||
row.add(num2str(rect.left));
|
||||
row.add(num2str(rect.right-rect.left));
|
||||
row.add(num2str(rect.bottom-rect.top));
|
||||
row.add(num2str(rect.top()));
|
||||
row.add(num2str(rect.left()));
|
||||
row.add(num2str(rect.width()));
|
||||
row.add(num2str(rect.height()));
|
||||
row.add(rf.picture());
|
||||
row.add(rf.field());
|
||||
}
|
||||
|
@ -316,14 +316,12 @@ protected:
|
||||
public:
|
||||
virtual PNT log2dev(long x, long y) const;
|
||||
virtual TPoint dev2log(const PNT& pt) const;
|
||||
void log2dev(const RCT& rctlog, RCT& rctdev) const;
|
||||
void dev2log(const RCT& rctdev, RCT& rctlog) const;
|
||||
TReport_section& curr_section() const;
|
||||
|
||||
bool get_selection_rect(RCT& rct) const;
|
||||
bool get_selection_rect(TRectangle& rct) const;
|
||||
bool pick(const TPoint& ptlog) const;
|
||||
void clear_selection();
|
||||
void select(const RCT& rct);
|
||||
void select(const TRectangle& rct);
|
||||
void offset_selection(const TPoint& p);
|
||||
|
||||
void set_report(TReport* rep) { _report = rep; }
|
||||
@ -349,8 +347,7 @@ void TReport_window::draw_square(int x, int y, int s)
|
||||
|
||||
void TReport_window::draw_field(const TReport_field& f)
|
||||
{
|
||||
RCT r; f.get_rect(r);
|
||||
log2dev(r, r);
|
||||
RCT r; TWindow::log2dev(f.get_rect(), r);
|
||||
|
||||
switch (f.type())
|
||||
{
|
||||
@ -392,14 +389,12 @@ void TReport_window::draw_fields()
|
||||
bool TReport_window::pick(const TPoint& ptlog) const
|
||||
{
|
||||
TReport_section& rs = curr_section();
|
||||
RCT rct;
|
||||
|
||||
const PNT pt = { short(ptlog.y), short(ptlog.x) };
|
||||
FOR_EACH_ARRAY_ITEM(rs, i, o)
|
||||
{
|
||||
TReport_field& f = *(TReport_field*)o;
|
||||
f.get_rect(rct);
|
||||
if (xvt_rect_has_point(&rct, pt))
|
||||
const TRectangle& rct = f.get_rect();
|
||||
if (rct.contains(ptlog))
|
||||
{
|
||||
f.select();
|
||||
return true;
|
||||
@ -418,7 +413,7 @@ void TReport_window::clear_selection()
|
||||
}
|
||||
}
|
||||
|
||||
bool TReport_window::get_selection_rect(RCT& rct) const
|
||||
bool TReport_window::get_selection_rect(TRectangle& rct) const
|
||||
{
|
||||
TReport_section& rs = curr_section();
|
||||
bool full = false;
|
||||
@ -427,19 +422,14 @@ bool TReport_window::get_selection_rect(RCT& rct) const
|
||||
const TReport_field& f = *(const TReport_field*)o;
|
||||
if (f.selected())
|
||||
{
|
||||
const TRectangle& fr = f.get_rect();
|
||||
if (!full)
|
||||
{
|
||||
f.get_rect(rct);
|
||||
rct = fr;
|
||||
full = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
RCT r; f.get_rect(r);
|
||||
if (r.left < rct.left) rct.left = r.left;
|
||||
if (r.right > rct.right) rct.right = r.right;
|
||||
if (r.top < rct.top) rct.top = r.top;
|
||||
if (r.bottom > rct.bottom) rct.bottom = r.bottom;
|
||||
}
|
||||
rct.merge(fr);
|
||||
}
|
||||
}
|
||||
return full;
|
||||
@ -456,7 +446,7 @@ void TReport_window::offset_selection(const TPoint& p)
|
||||
}
|
||||
}
|
||||
|
||||
void TReport_window::select(const RCT& rct)
|
||||
void TReport_window::select(const TRectangle& rct)
|
||||
{
|
||||
clear_selection();
|
||||
|
||||
@ -464,8 +454,7 @@ void TReport_window::select(const RCT& rct)
|
||||
FOR_EACH_ARRAY_ITEM(rs, i, o)
|
||||
{
|
||||
TReport_field& f = *(TReport_field*)o;
|
||||
RCT r; f.get_rect(r);
|
||||
if (xvt_rect_intersect(NULL, (RCT*)&rct, &r))
|
||||
if (rct.intersects(f.get_rect()))
|
||||
f.select();
|
||||
}
|
||||
}
|
||||
@ -524,7 +513,7 @@ void TReport_window::popup_menu(EVENT* ep)
|
||||
MENU_ITEM menu[8];
|
||||
memset(menu, 0, sizeof(menu));
|
||||
|
||||
RCT rct;
|
||||
TRectangle rct;
|
||||
const bool sel = get_selection_rect(rct);
|
||||
const bool clp = _clipboard.items() > 0;
|
||||
|
||||
@ -573,18 +562,19 @@ void TReport_window::popup_paste()
|
||||
{
|
||||
if (_clipboard.items() > 0)
|
||||
{
|
||||
RCT rct;
|
||||
((TReport_field&)_clipboard[0]).get_rect(rct);
|
||||
const TPoint off(_pt_drag_start.x-rct.left, _pt_drag_start.y-rct.top);
|
||||
const TRectangle& rct = ((TReport_field&)_clipboard[0]).get_rect();
|
||||
const TPoint off(_pt_drag_start.x-rct.left(), _pt_drag_start.y-rct.top());
|
||||
clear_selection();
|
||||
TReport_section& rs = curr_section();
|
||||
FOR_EACH_ARRAY_ITEM(_clipboard, i, o)
|
||||
{
|
||||
TReport_field& f = *(TReport_field*)o;
|
||||
f.set_section(&rs);
|
||||
f.select();
|
||||
f.offset(off);
|
||||
rs.add(f);
|
||||
const TReport_field& oldf = *(TReport_field*)o;
|
||||
TReport_field* newf = new TReport_field(oldf);
|
||||
newf->set_section(&rs);
|
||||
newf->set_font(oldf.font()); // Font is section dependent!
|
||||
newf->select();
|
||||
newf->offset(off);
|
||||
rs.add(newf);
|
||||
}
|
||||
force_update();
|
||||
}
|
||||
@ -598,10 +588,9 @@ void TReport_window::handler(WINDOW win, EVENT* ep)
|
||||
if (ep->v.mouse.button == 0)
|
||||
{
|
||||
const TPoint pt = dev2log(ep->v.mouse.where);
|
||||
const PNT p = { short(pt.y), short(pt.x) };
|
||||
RCT rct;
|
||||
TRectangle rct;
|
||||
bool full = get_selection_rect(rct);
|
||||
if (!full || !xvt_rect_has_point(&rct, p))
|
||||
if (!full || !rct.contains(pt))
|
||||
{
|
||||
if (full)
|
||||
clear_selection();
|
||||
@ -610,7 +599,7 @@ void TReport_window::handler(WINDOW win, EVENT* ep)
|
||||
}
|
||||
if (full)
|
||||
{
|
||||
log2dev(rct, _rct_drag);
|
||||
TWindow::log2dev(rct, _rct_drag);
|
||||
_pt_drag_offset.h = ep->v.mouse.where.h - _rct_drag.left;
|
||||
_pt_drag_offset.v = ep->v.mouse.where.v - _rct_drag.top;
|
||||
_dragging = 2;
|
||||
@ -623,8 +612,8 @@ void TReport_window::handler(WINDOW win, EVENT* ep)
|
||||
xvt_rect_set(&_rct_drag, pnt.h, pnt.v, pnt.h, pnt.v);
|
||||
_dragging = 1;
|
||||
}
|
||||
_pt_drag_start.x = rct.left;
|
||||
_pt_drag_start.y = rct.top;
|
||||
_pt_drag_start.x = rct.left();
|
||||
_pt_drag_start.y = rct.top();
|
||||
draw_dragster();
|
||||
xvt_win_trap_pointer(win);
|
||||
}
|
||||
@ -674,7 +663,7 @@ void TReport_window::handler(WINDOW win, EVENT* ep)
|
||||
{
|
||||
_rct_drag.right = pt.h;
|
||||
_rct_drag.bottom = pt.v;
|
||||
RCT rct; dev2log(_rct_drag, rct);
|
||||
TRectangle rct; TWindow::dev2log(_rct_drag, rct);
|
||||
select(rct);
|
||||
}
|
||||
break;
|
||||
@ -758,24 +747,6 @@ TPoint TReport_window::dev2log(const PNT& pt) const
|
||||
return p;
|
||||
}
|
||||
|
||||
void TReport_window::log2dev(const RCT& rctlog, RCT& rctdev) const
|
||||
{
|
||||
const PNT f = log2dev(rctlog.left, rctlog.top);
|
||||
const PNT t = log2dev(rctlog.right, rctlog.bottom);
|
||||
rctdev.left = f.h; rctdev.top = f.v;
|
||||
rctdev.right = t.h; rctdev.bottom = t.v;
|
||||
}
|
||||
|
||||
void TReport_window::dev2log(const RCT& rctdev, RCT& rctlog) const
|
||||
{
|
||||
const PNT pf = { rctdev.top, rctdev.left };
|
||||
const PNT pt = { rctdev.bottom, rctdev.right };
|
||||
const TPoint f = dev2log(pf);
|
||||
const TPoint t = dev2log(pt);
|
||||
rctlog.left = short(f.x); rctlog.top = short(f.y);
|
||||
rctlog.right = short(t.x); rctlog.bottom = short(t.y);
|
||||
}
|
||||
|
||||
void TReport_window::draw_grid()
|
||||
{
|
||||
clear(COLOR_WHITE);
|
||||
|
327
ba/ba8302.cpp
327
ba/ba8302.cpp
@ -152,14 +152,6 @@ TReport_font::~TReport_font()
|
||||
// Utility
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
void rect_log2dev(TWindow& win, RCT& r)
|
||||
{
|
||||
const PNT f = win.log2dev(r.left, r.top);
|
||||
const PNT t = win.log2dev(r.right, r.bottom);
|
||||
r.left = f.h; r.top = f.v;
|
||||
r.right = t.h; r.bottom = t.v;
|
||||
}
|
||||
|
||||
void advanced_draw_rect(TWindow& win, const RCT& r, int border, COLOR fore, COLOR back)
|
||||
{
|
||||
const bool has_pen = border > 0;
|
||||
@ -259,21 +251,25 @@ int TReport_section::add(TObject& obj)
|
||||
return TArray::add(obj);
|
||||
}
|
||||
|
||||
bool TReport_section::get_rect(RCT& rct) const
|
||||
TPoint TReport_section::compute_size() const
|
||||
{
|
||||
rct.left = rct.top = 0;
|
||||
rct.right = _width;
|
||||
rct.bottom = _height;
|
||||
TPoint s = _size;
|
||||
for (int i = 0; i < items(); i++)
|
||||
{
|
||||
const TReport_field& rf = field(i);
|
||||
RCT r; rf.get_rect(r);
|
||||
if (r.right > rct.right)
|
||||
rct.right = r.right;
|
||||
if (r.bottom > rct.bottom)
|
||||
rct.bottom = r.bottom;
|
||||
const TRectangle& r = rf.get_rect();
|
||||
if (r.right() > s.x)
|
||||
s.x = r.right();
|
||||
if (r.bottom() > s.y)
|
||||
s.y = r.bottom();
|
||||
}
|
||||
return xvt_rect_is_empty(&rct) == FALSE;
|
||||
return s;
|
||||
}
|
||||
|
||||
bool TReport_section::compute_rect(TRectangle& rct) const
|
||||
{
|
||||
rct.set(TPoint(0, 0), compute_size());
|
||||
return !rct.is_empty();
|
||||
}
|
||||
|
||||
void TReport_section::draw(TWindow& win, TReport_draw_mode rdm) const
|
||||
@ -296,7 +292,7 @@ void TReport_section::compute_values()
|
||||
|
||||
TReport_section::TReport_section(TReport& r, char t, int l)
|
||||
: _report(r), _type(t), _level(l), _font(NULL),
|
||||
_width(0), _height(0), _hidden_if_needed(false)
|
||||
_size(0,0), _hidden_if_needed(false)
|
||||
{ }
|
||||
|
||||
TReport_section::~TReport_section()
|
||||
@ -309,27 +305,22 @@ TReport_section::~TReport_section()
|
||||
// TReport_field
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
void TReport_field::set_pos(short x, short y)
|
||||
void TReport_field::set_pos(long x, long y)
|
||||
{
|
||||
_x = x;
|
||||
_y = y;
|
||||
_rct.x = x;
|
||||
_rct.y = y;
|
||||
}
|
||||
|
||||
void TReport_field::set_size(short w, short h)
|
||||
void TReport_field::set_size(long w, long h)
|
||||
{
|
||||
_width = w;
|
||||
_height = h;
|
||||
}
|
||||
|
||||
void TReport_field::get_rect(RCT& r) const
|
||||
{
|
||||
r.left = _x; r.top = _y;
|
||||
r.right = _x + _width; r.bottom = _y + _height;
|
||||
_rct.set_width(w);
|
||||
_rct.set_height(h);
|
||||
}
|
||||
|
||||
void TReport_field::offset(const TPoint& pt)
|
||||
{
|
||||
_x += short(pt.x); _y += short(pt.y);
|
||||
_rct.x += pt.x;
|
||||
_rct.y += pt.y;
|
||||
}
|
||||
|
||||
const TReport_font& TReport_field::font() const
|
||||
@ -352,8 +343,7 @@ void TReport_field::copy(const TReport_field& rf)
|
||||
{
|
||||
_section = rf._section;
|
||||
_type = rf.type();
|
||||
_x = rf._x; _y = rf._y;
|
||||
_width = rf._width; _height = rf._height;
|
||||
_rct = rf._rct;
|
||||
_fgcolor = rf._fgcolor; _bgcolor = rf._bgcolor;
|
||||
_border = rf._border;
|
||||
_halign = rf._halign; _valign = rf._valign;
|
||||
@ -392,15 +382,13 @@ bool TReport_field::compute_value()
|
||||
|
||||
void TReport_field::draw_rect(TWindow& win) const
|
||||
{
|
||||
RCT r; get_rect(r);
|
||||
rect_log2dev(win, r);
|
||||
RCT r; win.log2dev(get_rect(), r);
|
||||
advanced_draw_rect(win, r, border(), fore_color(), back_color());
|
||||
}
|
||||
|
||||
void TReport_field::draw_text(TWindow& win, const char* text) const
|
||||
{
|
||||
RCT r; get_rect(r);
|
||||
rect_log2dev(win, r);
|
||||
RCT r; win.log2dev(get_rect(), r);
|
||||
advanced_draw_rect(win, r, border(), fore_color(), back_color());
|
||||
|
||||
xvt_dwin_set_font(win.win(), font().get_xvt_font(win));
|
||||
@ -418,29 +406,28 @@ void TReport_field::draw(TWindow& win, TReport_draw_mode rdm) const
|
||||
const bool has_brush = color_distance(back_color(), COLOR_WHITE) != 0;
|
||||
win.set_pen(fore_color(), border(), has_pen ? PAT_SOLID : PAT_HOLLOW);
|
||||
win.set_brush(back_color(), has_brush ? PAT_SOLID : PAT_HOLLOW);
|
||||
RCT r; get_rect(r);
|
||||
rect_log2dev(win, r);
|
||||
RCT r; win.log2dev(get_rect(), r);
|
||||
xvt_dwin_draw_oval(win.win(), &r);
|
||||
}
|
||||
break;
|
||||
case 'L':
|
||||
{
|
||||
win.set_pen(fore_color(), border());
|
||||
RCT r; get_rect(r);
|
||||
win.line(r.left, r.top, r.right, r.bottom);
|
||||
const TRectangle& r = get_rect();
|
||||
win.line((short)r.left(), (short)r.top(), (short)r.right(), (short)r.bottom());
|
||||
}
|
||||
break;
|
||||
case 'R': draw_rect(win); break;
|
||||
case 'T': draw_text(win, _picture); break;
|
||||
default : draw_text(win, rdm == rdm_edit ? _source : _value); break;
|
||||
default : draw_text(win, rdm == rdm_edit ? _field : _value); break;
|
||||
}
|
||||
}
|
||||
|
||||
static void set_num_attr(TXmlItem& item, const char* attr, short num, short def = 0)
|
||||
static void set_num_attr(TXmlItem& item, const char* attr, long num, short def = 0)
|
||||
{
|
||||
if (num != def)
|
||||
{
|
||||
const real n = (num / 100.0);
|
||||
const real n = num / CENTO;
|
||||
item.SetAttr(attr, n.string());
|
||||
}
|
||||
}
|
||||
@ -460,11 +447,11 @@ void TReport_field::save(TXmlItem& root) const
|
||||
TXmlItem& fld = root.AddChild("field");
|
||||
fld.SetAttr("type", type_name());
|
||||
|
||||
RCT rct; get_rect(rct);
|
||||
set_num_attr(fld, "x", rct.left);
|
||||
set_num_attr(fld, "y", rct.top);
|
||||
set_num_attr(fld, "width", rct.right - rct.left);
|
||||
set_num_attr(fld, "height", rct.bottom - rct.top, 100);
|
||||
const TRectangle& rct = get_rect();
|
||||
set_num_attr(fld, "x", rct.left());
|
||||
set_num_attr(fld, "y", rct.top());
|
||||
set_num_attr(fld, "width", rct.width());
|
||||
set_num_attr(fld, "height", rct.height(), 100);
|
||||
set_col_attr(fld, "bg_color", back_color(), COLOR_WHITE);
|
||||
set_col_attr(fld, "fg_color", fore_color(), COLOR_BLACK);
|
||||
if (has_font())
|
||||
@ -648,7 +635,7 @@ void TReport::load_sections(const TXmlItem& xml)
|
||||
|
||||
TReport_font font;
|
||||
if (font.load(sec))
|
||||
set_font(font);
|
||||
rs.set_font(font);
|
||||
|
||||
if (level > 1)
|
||||
{
|
||||
@ -706,8 +693,9 @@ bool TReport::load(const char* fname)
|
||||
return ok;
|
||||
}
|
||||
|
||||
void TReport::save_section(const TReport_section& rs, TXmlItem& item) const
|
||||
void TReport::save_section(const TReport_section& rs, TXmlItem& xml) const
|
||||
{
|
||||
TXmlItem& item = xml.AddChild("section");
|
||||
char* tipo = NULL;
|
||||
switch (rs.type())
|
||||
{
|
||||
@ -718,7 +706,8 @@ void TReport::save_section(const TReport_section& rs, TXmlItem& item) const
|
||||
item.SetAttr("type", tipo);
|
||||
item.SetAttr("level", rs.level());
|
||||
item.SetAttr("hidden_if_needed", rs.hidden_if_needed());
|
||||
item.AddChild("groupby") << rs.grouped_by();
|
||||
if (rs.grouped_by().not_empty())
|
||||
item.AddChild("groupby") << rs.grouped_by();
|
||||
if (rs.has_font())
|
||||
rs.font().save(item);
|
||||
|
||||
@ -751,10 +740,7 @@ bool TReport::save(const char* fname) const
|
||||
{
|
||||
TReport_section* rs = find_section(sectype[j], i);
|
||||
if (rs != NULL && (rs->height() > 0 || rs->items() > 0))
|
||||
{
|
||||
TXmlItem& sec = xml.AddChild("section");
|
||||
save_section(*rs, sec);
|
||||
}
|
||||
save_section(*rs, xml);
|
||||
}
|
||||
}
|
||||
|
||||
@ -794,7 +780,8 @@ int TPage_printer::font_size() const
|
||||
|
||||
bool TPage_printer::ask_pages()
|
||||
{
|
||||
const int last_page = pages();
|
||||
if (_pageto <= 0)
|
||||
_pageto = pages();
|
||||
|
||||
TPrinter& p = printer();
|
||||
TMask msk("bagn003");
|
||||
@ -804,7 +791,7 @@ bool TPage_printer::ask_pages()
|
||||
msk.set(F_SIZE, font_size());
|
||||
msk.set(F_ISGRAPHICS, p.isgraphics() ? "X" : "");
|
||||
msk.set(F_FROMPAGE, _pagefrom);
|
||||
msk.set(F_TOPAGE, last_page);
|
||||
msk.set(F_TOPAGE, _pageto);
|
||||
msk.set(F_COPIES, _copies);
|
||||
const bool ok = msk.run() == K_ENTER;
|
||||
if (ok)
|
||||
@ -812,76 +799,78 @@ bool TPage_printer::ask_pages()
|
||||
_copies = msk.get_int(F_COPIES);
|
||||
_pagefrom = msk.get_int(F_FROMPAGE);
|
||||
_pageto = msk.get_int(F_TOPAGE);
|
||||
if (_pageto < _pagefrom || _pageto > last_page)
|
||||
if (_pageto < _pagefrom)
|
||||
_pageto = 0;
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool TPage_printer::print_band(word page, const RCT& rct)
|
||||
{
|
||||
return print_page(page);
|
||||
}
|
||||
|
||||
bool TPage_printer::print_loop()
|
||||
bool TPage_printer::main_loop()
|
||||
{
|
||||
TPrinter& p = printer();
|
||||
PRINT_RCD* rcd = p.get_printrcd();
|
||||
if (!xvt_print_is_valid(rcd))
|
||||
_rcd = p.get_printrcd();
|
||||
if (!xvt_print_is_valid(_rcd))
|
||||
return TRUE; // aborted
|
||||
|
||||
WINDOW prwin = xvt_print_create_win(rcd, (char*)(const char*)form_name());
|
||||
WINDOW prwin = xvt_print_create_win(_rcd, (char*)(const char*)form_name());
|
||||
if (prwin == NULL_WIN)
|
||||
return TRUE; // aborted
|
||||
set_win(prwin);
|
||||
|
||||
xvt_app_escape (XVT_ESC_GET_PRINTER_INFO, rcd, &_ph, &_pw, &_pvr, &_phr);
|
||||
xvt_app_escape (XVT_ESC_GET_PRINTER_INFO, _rcd, &_ph, &_pw, &_pvr, &_phr);
|
||||
|
||||
bool aborted = false;
|
||||
for (word c = 0; c < _copies && !aborted; c++)
|
||||
bool ok = true;
|
||||
for (word c = 0; c < _copies && ok; c++)
|
||||
{
|
||||
bool finished = false;
|
||||
for (word page = _pagefrom-1; !finished && !aborted; page++)
|
||||
{
|
||||
if (_pageto >= _pagefrom && page >= _pageto)
|
||||
break;
|
||||
|
||||
aborted = xvt_print_open_page(rcd) == 0;
|
||||
if (!aborted)
|
||||
{
|
||||
for (const RCT* rct = xvt_print_get_next_band(); rct != NULL; rct = xvt_print_get_next_band())
|
||||
{
|
||||
if (!print_band(page, *rct))
|
||||
{
|
||||
finished = TRUE;
|
||||
while (xvt_print_get_next_band()); // Esce dalla lista delle bande
|
||||
break;
|
||||
}
|
||||
}
|
||||
aborted = xvt_print_close_page(rcd) == 0;
|
||||
}
|
||||
}
|
||||
_page = 0;
|
||||
ok = print_loop();
|
||||
}
|
||||
|
||||
xvt_vobj_destroy(prwin);
|
||||
set_win(NULL_WIN);
|
||||
|
||||
return aborted;
|
||||
return !ok;
|
||||
}
|
||||
|
||||
static BOOLEAN print_loop_callback(long jolly)
|
||||
bool TPage_printer::page_in_range() const
|
||||
{
|
||||
if (_page < _pagefrom)
|
||||
return false;
|
||||
return _pageto < _pagefrom || _page <= _pageto;
|
||||
}
|
||||
|
||||
bool TPage_printer::open_page()
|
||||
{
|
||||
_page++;
|
||||
if (page_in_range())
|
||||
_page_is_open = xvt_print_open_page(_rcd) != 0;
|
||||
else
|
||||
_page_is_open = false;
|
||||
return _page_is_open;
|
||||
}
|
||||
|
||||
bool TPage_printer::close_page()
|
||||
{
|
||||
const bool was_open = _page_is_open;
|
||||
if (was_open)
|
||||
{
|
||||
xvt_print_close_page(_rcd);
|
||||
_page_is_open = false;
|
||||
}
|
||||
return was_open;
|
||||
}
|
||||
|
||||
static BOOLEAN main_loop_callback(long jolly)
|
||||
{
|
||||
TPage_printer* pp = (TPage_printer*)jolly;
|
||||
return pp->print_loop();
|
||||
return pp->main_loop();
|
||||
}
|
||||
|
||||
bool TPage_printer::print()
|
||||
{
|
||||
bool ok = ask_pages();
|
||||
if (ok)
|
||||
{
|
||||
ok = xvt_print_start_thread(print_loop_callback, long(this)) == FALSE;
|
||||
}
|
||||
ok = xvt_print_start_thread(main_loop_callback, long(this)) == FALSE;
|
||||
return ok;
|
||||
}
|
||||
|
||||
@ -929,86 +918,90 @@ TPoint TReport_printer::dev2log(const PNT& pnt) const
|
||||
return p;
|
||||
}
|
||||
|
||||
word TReport_printer::pages() const
|
||||
long TReport_printer::print_section(char type, int level)
|
||||
{
|
||||
return 1;
|
||||
long h = 0;
|
||||
TReport_section* rs = _report.find_section(type, level);
|
||||
if (rs != NULL)
|
||||
h = print_section(*rs);
|
||||
return h;
|
||||
}
|
||||
|
||||
bool TReport_printer::print_page(word page)
|
||||
bool TReport_printer::open_page()
|
||||
{
|
||||
if (_report.recordset() == NULL)
|
||||
return true;
|
||||
|
||||
TRecordset& rex = *_report.recordset();
|
||||
if (page == 0)
|
||||
{
|
||||
if (!rex.move_to(0))
|
||||
return true;
|
||||
}
|
||||
const bool ok = TPage_printer::open_page();
|
||||
|
||||
_delta.x = _delta.y = 0;
|
||||
print_section('B', 0);
|
||||
if (_page == 1)
|
||||
_delta.y += print_section('H', 1);
|
||||
|
||||
TReport_section* page_head = _report.find_section('H', 0);
|
||||
if (page_head != NULL && (_page > 1 || !page_head->hidden_if_needed()))
|
||||
_delta.y += print_section(*page_head);
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool TReport_printer::close_page()
|
||||
{
|
||||
if (_page_is_open)
|
||||
{
|
||||
TReport_section* page_foot = _report.find_section('F', 0);
|
||||
if (page_foot != NULL && (!_is_last_page || !page_foot->hidden_if_needed()))
|
||||
{
|
||||
_delta.x = 0;
|
||||
_delta.y = _logical_foot_pos;
|
||||
print_section(*page_foot);
|
||||
}
|
||||
}
|
||||
return TPage_printer::close_page();
|
||||
}
|
||||
|
||||
long TReport_printer::print_section(TReport_section& rs)
|
||||
{
|
||||
const long height = rs.compute_size().y;
|
||||
if (_delta.y + height > _logical_foot_pos && rs.level() > 0) // Avoid recursion
|
||||
{
|
||||
close_page();
|
||||
open_page();
|
||||
}
|
||||
rs.compute_values();
|
||||
if (_page_is_open)
|
||||
rs.draw(*this, rdm_print);
|
||||
|
||||
return height;
|
||||
}
|
||||
|
||||
bool TReport_printer::print_loop()
|
||||
{
|
||||
if (_report.recordset() == NULL)
|
||||
return false;
|
||||
TRecordset& rex = *_report.recordset();
|
||||
if (rex.items() <= 0)
|
||||
return false;
|
||||
|
||||
_kx = double(_phr) / double(_report.cpi()*100.0);
|
||||
_ky = double(_pvr) / double(_report.lpi()*100.0);
|
||||
|
||||
RCT rct;
|
||||
TReport_section* page_head = _report.find_section('H', 0);
|
||||
if (page_head != NULL && (page > 0 || !page_head->hidden_if_needed()))
|
||||
{
|
||||
page_head->draw(*this, rdm_print);
|
||||
page_head->get_rect(rct);
|
||||
_delta.y += rct.bottom;
|
||||
}
|
||||
|
||||
TReport_section* page_body = _report.find_section('B', 0);
|
||||
if (page_body != NULL)
|
||||
page_body->draw(*this, rdm_print);
|
||||
|
||||
const double pollici_pagina = (double)_ph / (double)_pvr;
|
||||
const double righe_pagina = pollici_pagina * _report.lpi();
|
||||
TPoint foot_delta;
|
||||
foot_delta.x = 0;
|
||||
foot_delta.y = long(righe_pagina * 100.0);
|
||||
|
||||
TReport_section* page_foot = _report.find_section('F', 0);
|
||||
if (page_foot != NULL)
|
||||
_logical_page_height = long(righe_pagina*100.0);
|
||||
const long logical_footer_height = _report.section('F',0).compute_size().y;
|
||||
_logical_foot_pos = _logical_page_height - logical_footer_height;
|
||||
|
||||
_is_last_page = false;
|
||||
open_page();
|
||||
for (bool ok = rex.move_to(0); ok; ok = rex.move_next())
|
||||
{
|
||||
page_foot->get_rect(rct);
|
||||
foot_delta.y -= rct.bottom;
|
||||
if (_pageto >= _pagefrom && _page > _pageto) // out of range
|
||||
break;
|
||||
_delta.y += print_section('B', 1);
|
||||
}
|
||||
if (rex.eof())
|
||||
print_section('F', 1);
|
||||
_is_last_page = true;
|
||||
close_page();
|
||||
|
||||
if (page == 0)
|
||||
{
|
||||
TReport_section* report_head = _report.find_section('H', 1);
|
||||
if (report_head != NULL)
|
||||
{
|
||||
report_head->draw(*this, rdm_print);
|
||||
report_head->get_rect(rct);
|
||||
_delta.y += rct.bottom;
|
||||
}
|
||||
}
|
||||
|
||||
if (rex.current_row() < rex.items())
|
||||
{
|
||||
TReport_section* body = _report.find_section('B', 1);
|
||||
if (body != NULL)
|
||||
{
|
||||
body->get_rect(rct);
|
||||
while (_delta.y + rct.bottom <= foot_delta.y)
|
||||
{
|
||||
body->compute_values();
|
||||
body->draw(*this, rdm_print);
|
||||
_delta.y += rct.bottom;
|
||||
if (!rex.move_next())
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (page_foot != NULL)
|
||||
{
|
||||
_delta = foot_delta;
|
||||
page_foot->draw(*this, rdm_print);
|
||||
}
|
||||
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
62
ba/ba8302.h
62
ba/ba8302.h
@ -64,7 +64,7 @@ class TReport_section : public TArray
|
||||
|
||||
char _type; // Head,Body,Tail
|
||||
int _level; // 0,1,2,...
|
||||
short _width, _height; // In centesimi
|
||||
TPoint _size; // In centesimi
|
||||
TString _groupby;
|
||||
bool _hidden_if_needed;
|
||||
|
||||
@ -83,11 +83,13 @@ public:
|
||||
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;
|
||||
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; }
|
||||
@ -110,8 +112,7 @@ 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
|
||||
TRectangle _rct; // In centesimi
|
||||
COLOR _fgcolor, _bgcolor;
|
||||
short _border;
|
||||
char _halign, _valign;
|
||||
@ -146,13 +147,13 @@ public:
|
||||
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_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; }
|
||||
@ -231,10 +232,13 @@ public:
|
||||
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;
|
||||
word _copies, _pagefrom, _pageto, _page;
|
||||
bool _page_is_open;
|
||||
|
||||
bool print_band(word page, const RCT& rct);
|
||||
virtual word pages() const { return 0; }
|
||||
virtual bool print_loop() pure;
|
||||
|
||||
protected:
|
||||
virtual const char* form_name() const;
|
||||
@ -242,13 +246,13 @@ protected:
|
||||
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
|
||||
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();
|
||||
};
|
||||
@ -258,6 +262,9 @@ 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;
|
||||
@ -266,11 +273,14 @@ protected:
|
||||
|
||||
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:
|
||||
virtual word pages() const;
|
||||
virtual bool print_page(word p);
|
||||
|
||||
TReport_printer(TReport& r) : _report(r) { }
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user