2004-05-07 10:25:51 +00:00
|
|
|
#include <automask.h>
|
2004-05-27 10:55:07 +00:00
|
|
|
#include <colors.h>
|
2004-05-07 10:25:51 +00:00
|
|
|
#include <defmask.h>
|
|
|
|
#include <diction.h>
|
|
|
|
#include <printer.h>
|
2004-05-27 10:55:07 +00:00
|
|
|
#include <progind.h>
|
2004-05-07 10:25:51 +00:00
|
|
|
#include <reprint.h>
|
|
|
|
#include <statbar.h>
|
|
|
|
|
|
|
|
#include <bagn003.h>
|
|
|
|
|
|
|
|
static bool _print_aborted = false;
|
|
|
|
|
2004-05-27 10:55:07 +00:00
|
|
|
/*
|
|
|
|
const TReport_link* TPage_printer::find_link(const PNT& pnt) const
|
|
|
|
{
|
|
|
|
if (!_links_sorted)
|
|
|
|
{
|
|
|
|
TPage_printer* myself = (TPage_printer*)this;
|
|
|
|
myself->_links.sort();
|
|
|
|
myself->_links_sorted = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
int primo = 0, ultimo = _links.last();
|
|
|
|
while (primo <= ultimo)
|
|
|
|
{
|
|
|
|
const int in_mezzo = (primo+ultimo)/2;
|
|
|
|
const TReport_link* lnk = (const TReport_link*)_links.objptr(in_mezzo);
|
|
|
|
const int cmp = lnk->hit_test(pnt);
|
|
|
|
if (cmp == 0)
|
|
|
|
return lnk;
|
|
|
|
if (cmp < 0)
|
|
|
|
ultimo = in_mezzo-1;
|
|
|
|
else
|
|
|
|
primo = in_mezzo+1;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2004-05-07 10:25:51 +00:00
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// TPrint_preview_window
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
class TPrint_preview_window : public TField_window
|
|
|
|
{
|
2004-05-27 10:55:07 +00:00
|
|
|
TBook* _book;
|
|
|
|
word _page;
|
2004-05-07 10:25:51 +00:00
|
|
|
int _zoom;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void page_select();
|
|
|
|
void popup_menu(EVENT* ep);
|
|
|
|
virtual void handler(WINDOW win, EVENT* ep);
|
|
|
|
virtual void update();
|
|
|
|
virtual bool on_key(KEY k);
|
|
|
|
|
|
|
|
public:
|
|
|
|
virtual PNT log2dev(long lx, long ly) const;
|
|
|
|
|
|
|
|
TPrint_preview_window(int x, int y, int dx, int dy, WINDOW parent,
|
2004-05-27 10:55:07 +00:00
|
|
|
TWindowed_field* owner, TBook* book);
|
2004-05-07 10:25:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
PNT TPrint_preview_window::log2dev(long lx, long ly) const
|
|
|
|
{
|
2004-05-27 10:55:07 +00:00
|
|
|
const TPoint res = _book->page_res();
|
|
|
|
|
2004-05-07 10:25:51 +00:00
|
|
|
PNT pnt;
|
2004-05-27 10:55:07 +00:00
|
|
|
pnt.h = short(lx * _zoom / res.x);
|
|
|
|
pnt.v = short(ly * _zoom / res.y);
|
2004-05-07 10:25:51 +00:00
|
|
|
|
|
|
|
const TPoint orig = origin();
|
|
|
|
pnt.h -= short(orig.x*10);
|
|
|
|
pnt.v -= short(orig.y*10);
|
|
|
|
|
|
|
|
return pnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TPrint_preview_window::update()
|
|
|
|
{
|
2004-05-27 10:55:07 +00:00
|
|
|
clear(MASK_BACK_COLOR);
|
|
|
|
RCT rct; xvt_vobj_get_client_rect(win(), &rct);
|
|
|
|
|
|
|
|
const TPoint size = _book->page_size();
|
|
|
|
const PNT pag = log2dev(size.x, size.y);
|
|
|
|
if (pag.h < rct.right) rct.right = pag.h;
|
|
|
|
if (pag.v < rct.bottom) rct.bottom = pag.v;
|
|
|
|
hide_pen();
|
|
|
|
set_brush(COLOR_WHITE);
|
|
|
|
xvt_dwin_draw_rect(win(), &rct);
|
|
|
|
|
|
|
|
_book->print_page(*this, _page);
|
|
|
|
|
|
|
|
TString80 str; str.format(FR("Pagina %u di %u"), _page, _book->pages());
|
|
|
|
statbar_set_title(TASK_WIN, str);
|
2004-05-07 10:25:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define POPUP_FIRST 20883
|
|
|
|
#define POPUP_PREV 20884
|
|
|
|
#define POPUP_NEXT 20885
|
|
|
|
#define POPUP_SEARCH 20886
|
|
|
|
#define POPUP_LAST 20887
|
|
|
|
#define POPUP_ZOOMIN 20888
|
|
|
|
#define POPUP_ZOOMOUT 20889
|
|
|
|
#define POPUP_GRID 20890
|
|
|
|
|
|
|
|
void TPrint_preview_window::popup_menu(EVENT* ep)
|
|
|
|
{
|
|
|
|
MENU_ITEM menu[16]; // Stiamo larghi
|
|
|
|
memset(menu, 0, sizeof(menu));
|
|
|
|
menu[0].tag = POPUP_FIRST; menu[0].text = (char*)TR("Prima"); menu[0].enabled = true;
|
|
|
|
menu[1].tag = POPUP_PREV; menu[1].text = (char*)TR("Indietro"); menu[1].enabled = _page > 1;
|
2004-05-27 10:55:07 +00:00
|
|
|
menu[2].tag = POPUP_NEXT; menu[2].text = (char*)TR("Avanti"); menu[2].enabled = _page < _book->pages();
|
2004-05-07 10:25:51 +00:00
|
|
|
menu[3].tag = POPUP_LAST; menu[3].text = (char*)TR("Ultima"); menu[3].enabled = true;
|
|
|
|
menu[4].tag = -1; menu[4].separator = true;
|
|
|
|
menu[5].tag = POPUP_ZOOMIN; menu[5].text = (char*)TR("Zoom +"); menu[5].enabled = _zoom < 300;
|
2004-05-27 10:55:07 +00:00
|
|
|
menu[6].tag = POPUP_ZOOMOUT; menu[6].text = (char*)TR("Zoom -"); menu[6].enabled = _zoom > 50;
|
2004-05-07 10:25:51 +00:00
|
|
|
menu[7].tag = -1; menu[7].separator = true;
|
|
|
|
menu[8].tag = POPUP_GRID; menu[8].text = (char*)TR("Griglia"); menu[8].enabled = true;
|
2004-05-27 10:55:07 +00:00
|
|
|
menu[8].checkable = true; menu[8].checked = false;
|
2004-05-07 10:25:51 +00:00
|
|
|
|
|
|
|
const PNT& p = ep->v.mouse.where;
|
|
|
|
xvt_menu_popup(menu, win(), p, XVT_POPUP_CENTER, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TPrint_preview_window::page_select()
|
|
|
|
{
|
|
|
|
TMask m("Ricerca", 1, 28, 4);
|
|
|
|
m.add_number(101, 0, "Pagina ", 1, 1, 4, "U").check_type(CHECK_REQUIRED);
|
|
|
|
m.add_button(DLG_OK, 0, "", -12, -1, 10, 2);
|
|
|
|
m.add_button(DLG_CANCEL, 0, "", -22, -1, 10, 2);
|
|
|
|
if (m.run())
|
|
|
|
_page = m.get_int(101);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TPrint_preview_window::handler(WINDOW win, EVENT* ep)
|
|
|
|
{
|
|
|
|
switch (ep->type)
|
|
|
|
{
|
2004-05-27 10:55:07 +00:00
|
|
|
/*
|
2004-05-07 10:25:51 +00:00
|
|
|
case E_MOUSE_MOVE:
|
|
|
|
if (_printer->find_link(ep->v.mouse.where) != NULL)
|
|
|
|
xvt_win_set_cursor(win, CURSOR_CROSS);
|
|
|
|
else
|
|
|
|
xvt_win_set_cursor(win, CURSOR_ARROW);
|
|
|
|
break;
|
|
|
|
case E_MOUSE_DOWN:
|
|
|
|
if (ep->v.mouse.button == 0)
|
|
|
|
{
|
|
|
|
const TReport_link* lnk = _printer->find_link(ep->v.mouse.where);
|
|
|
|
if (lnk != NULL)
|
|
|
|
_printer->on_link(*lnk);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
popup_menu(ep);
|
|
|
|
break;
|
2004-05-27 10:55:07 +00:00
|
|
|
*/
|
2004-05-07 10:25:51 +00:00
|
|
|
case E_COMMAND:
|
|
|
|
{
|
|
|
|
bool processed = true;
|
|
|
|
switch(ep->v.cmd.tag)
|
|
|
|
{
|
|
|
|
case POPUP_FIRST : _page = 1; break;
|
|
|
|
case POPUP_PREV : if (_page > 1) _page--; break;
|
|
|
|
case POPUP_SEARCH : page_select(); break;
|
2004-05-27 10:55:07 +00:00
|
|
|
case POPUP_NEXT : if (_page < _book->pages()) _page++; break;
|
|
|
|
case POPUP_LAST : _page = _book->pages(); break;
|
2004-05-07 10:25:51 +00:00
|
|
|
case POPUP_ZOOMIN : if (_zoom < 300) { _zoom += 25; } break;
|
2004-05-27 10:55:07 +00:00
|
|
|
case POPUP_ZOOMOUT: if (_zoom > 50) { _zoom -= 25; } break;
|
|
|
|
case POPUP_GRID : break;
|
2004-05-07 10:25:51 +00:00
|
|
|
default:processed = false; break;
|
|
|
|
}
|
|
|
|
if (processed)
|
|
|
|
{
|
|
|
|
_print_aborted = false;
|
|
|
|
force_update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
TField_window::handler(win, ep);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TPrint_preview_window::on_key(KEY k)
|
|
|
|
{
|
|
|
|
bool ok = true;
|
|
|
|
switch (k)
|
|
|
|
{
|
|
|
|
case '+' : dispatch_e_menu(win(), POPUP_ZOOMIN); break;
|
|
|
|
case '-' : dispatch_e_menu(win(), POPUP_ZOOMOUT); break;
|
|
|
|
case K_HOME :
|
|
|
|
case K_LHOME : dispatch_e_menu(win(), POPUP_FIRST); break;
|
|
|
|
case K_LEFT : dispatch_e_menu(win(), POPUP_PREV); break;
|
|
|
|
case K_RIGHT : dispatch_e_menu(win(), POPUP_NEXT); break;
|
|
|
|
case K_END:
|
|
|
|
case K_LEND : dispatch_e_menu(win(), POPUP_LAST); break;
|
|
|
|
case 'G' :
|
|
|
|
case 'g' : dispatch_e_menu(win(), POPUP_GRID); break;
|
|
|
|
default : ok = TField_window::on_key(k); break;
|
|
|
|
};
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
TPrint_preview_window::TPrint_preview_window(int x, int y, int dx, int dy, WINDOW parent,
|
2004-05-27 10:55:07 +00:00
|
|
|
TWindowed_field* owner, TBook* book)
|
|
|
|
: TField_window(x, y, dx, dy, parent, owner), _book(book), _page(1), _zoom(100)
|
2004-05-07 10:25:51 +00:00
|
|
|
{
|
|
|
|
RCT rct; xvt_vobj_get_client_rect(win(), &rct);
|
|
|
|
set_scroll_max(rct.right, rct.bottom);
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// TPrint_preview_field
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
class TPrint_preview_field : public TWindowed_field
|
|
|
|
{
|
2004-05-27 10:55:07 +00:00
|
|
|
TBook* _book;
|
2004-05-07 10:25:51 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual TField_window* create_window(int x, int y, int dx, int dy, WINDOW parent);
|
|
|
|
|
|
|
|
public:
|
2004-05-27 10:55:07 +00:00
|
|
|
TPrint_preview_field(TMask* m, TBook* book) : TWindowed_field(m), _book(book) { }
|
2004-05-07 10:25:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
TField_window* TPrint_preview_field::create_window(int x, int y, int dx, int dy, WINDOW parent)
|
|
|
|
{
|
2004-05-27 10:55:07 +00:00
|
|
|
return new TPrint_preview_window(x, y, dx, dy, parent, this, _book);
|
2004-05-07 10:25:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// TPreview_mask
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
class TPreview_mask : public TAutomask
|
|
|
|
{
|
2004-05-27 10:55:07 +00:00
|
|
|
TBook* _book;
|
|
|
|
TPrint_preview_field* _pvf;
|
2004-05-07 10:25:51 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual bool on_key(KEY k);
|
|
|
|
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
|
|
|
virtual TMask_field* parse_field(TScanner& scanner);
|
|
|
|
|
|
|
|
public:
|
2004-05-27 10:55:07 +00:00
|
|
|
TPreview_mask(TBook* book);
|
2004-05-07 10:25:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
bool TPreview_mask::on_key(KEY k)
|
|
|
|
{
|
|
|
|
switch (k)
|
|
|
|
{
|
|
|
|
case '+' :
|
|
|
|
case '-' :
|
|
|
|
case K_HOME :
|
|
|
|
case K_LHOME:
|
|
|
|
case K_LEFT :
|
|
|
|
case K_RIGHT:
|
|
|
|
case K_END :
|
|
|
|
case K_LEND :
|
|
|
|
case 'G' :
|
|
|
|
case 'g' :
|
2004-05-27 10:55:07 +00:00
|
|
|
dispatch_e_char(_pvf->win().win(), k);
|
2004-05-07 10:25:51 +00:00
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return TAutomask::on_key(k);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TPreview_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
|
|
|
{
|
|
|
|
if (e == fe_button)
|
|
|
|
{
|
|
|
|
switch (o.dlg())
|
|
|
|
{
|
2004-05-27 10:55:07 +00:00
|
|
|
case DLG_FIRSTREC: dispatch_e_menu(_pvf->win().win(), POPUP_FIRST); break;
|
|
|
|
case DLG_PREVREC : dispatch_e_menu(_pvf->win().win(), POPUP_PREV); break;
|
|
|
|
case DLG_FINDREC : dispatch_e_menu(_pvf->win().win(), POPUP_SEARCH);break;
|
|
|
|
case DLG_NEXTREC : dispatch_e_menu(_pvf->win().win(), POPUP_NEXT); break;
|
|
|
|
case DLG_LASTREC : dispatch_e_menu(_pvf->win().win(), POPUP_LAST); break;
|
2004-05-07 10:25:51 +00:00
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
TMask_field* TPreview_mask::parse_field(TScanner& scanner)
|
|
|
|
{
|
|
|
|
if (scanner.token().starts_with("PR"))
|
2004-05-27 10:55:07 +00:00
|
|
|
{
|
|
|
|
_pvf = new TPrint_preview_field(this, _book);
|
|
|
|
return _pvf;
|
|
|
|
}
|
2004-05-07 10:25:51 +00:00
|
|
|
return TAutomask::parse_field(scanner);
|
|
|
|
}
|
|
|
|
|
2004-05-27 10:55:07 +00:00
|
|
|
TPreview_mask::TPreview_mask(TBook* book) : _book(book)
|
2004-05-07 10:25:51 +00:00
|
|
|
{
|
|
|
|
read_mask("ba8303", 0, -1);
|
|
|
|
set_handlers();
|
|
|
|
|
|
|
|
int pos = id2pos(DLG_FINDREC);
|
|
|
|
if (pos >= 0 && id2pos(DLG_FIRSTREC) >= 0) //se e' un bottone pentapartito...
|
|
|
|
{
|
|
|
|
TButton_field& f_find = (TButton_field &)fld(pos);
|
|
|
|
RCT rct_base; f_find.get_rect(rct_base);
|
|
|
|
const int bwidth = (rct_base.right - rct_base.left);
|
|
|
|
const int bheight = (rct_base.bottom - rct_base.top);
|
|
|
|
if (bwidth > 3*bheight/2) // Controllo se ho gia' ridimensionato i bottoni in precedenza
|
|
|
|
{
|
|
|
|
int bx = bwidth / 3;
|
|
|
|
int by = bheight / 2;
|
|
|
|
|
|
|
|
RCT r = rct_base; r.left += bx-2; r.right -= bx-2;
|
|
|
|
f_find.set_rect(r); // Ridimensiona il bottone centrale di ricerca
|
|
|
|
|
|
|
|
bx += 5; by += 3; // Aggiusta dimensioni bottoni sussidiari
|
|
|
|
|
|
|
|
pos = id2pos(DLG_FIRSTREC);
|
|
|
|
if (pos >= 0)
|
|
|
|
{
|
|
|
|
r = rct_base; r.top = r.bottom - by; r.right = r.left + bx;
|
|
|
|
fld(pos).set_rect(r);
|
|
|
|
}
|
|
|
|
pos = id2pos(DLG_PREVREC);
|
|
|
|
if (pos >= 0)
|
|
|
|
{
|
|
|
|
r = rct_base; r.bottom = r.top + by; r.right = r.left + bx;
|
|
|
|
fld(pos).set_rect(r);
|
2004-05-27 10:55:07 +00:00
|
|
|
}
|
2004-05-07 10:25:51 +00:00
|
|
|
pos = id2pos(DLG_NEXTREC);
|
|
|
|
if (pos >= 0)
|
|
|
|
{
|
|
|
|
r = rct_base; r.bottom = r.top + by; r.left = r.right - bx;
|
|
|
|
fld(pos).set_rect(r);
|
|
|
|
}
|
|
|
|
pos = id2pos(DLG_LASTREC);
|
|
|
|
if (pos >= 0)
|
|
|
|
{
|
|
|
|
r = rct_base; r.top = r.bottom - by; r.left = r.right - bx;
|
|
|
|
fld(pos).set_rect(r);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
2004-05-27 10:55:07 +00:00
|
|
|
// TWindow_printer
|
2004-05-07 10:25:51 +00:00
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
2004-05-27 10:55:07 +00:00
|
|
|
class TWindow_printer : public TWindow
|
2004-05-07 10:25:51 +00:00
|
|
|
{
|
2004-05-27 10:55:07 +00:00
|
|
|
public:
|
|
|
|
TWindow_printer(PRINT_RCD* rcd);
|
|
|
|
~TWindow_printer();
|
|
|
|
};
|
2004-05-07 10:25:51 +00:00
|
|
|
|
2004-05-27 10:55:07 +00:00
|
|
|
TWindow_printer::TWindow_printer(PRINT_RCD* rcd)
|
2004-05-07 10:25:51 +00:00
|
|
|
{
|
2004-05-27 10:55:07 +00:00
|
|
|
WINDOW prwin = xvt_print_create_win(rcd, (char*)(const char*)"Printing");
|
|
|
|
set_win(prwin);
|
|
|
|
_pixmap = true;
|
2004-05-07 10:25:51 +00:00
|
|
|
}
|
|
|
|
|
2004-05-27 10:55:07 +00:00
|
|
|
TWindow_printer::~TWindow_printer()
|
2004-05-07 10:25:51 +00:00
|
|
|
{
|
2004-05-27 10:55:07 +00:00
|
|
|
if (win() != NULL_WIN)
|
|
|
|
{
|
|
|
|
xvt_vobj_destroy(win());
|
|
|
|
set_win(NULL_WIN);
|
|
|
|
}
|
2004-05-07 10:25:51 +00:00
|
|
|
}
|
|
|
|
|
2004-05-27 10:55:07 +00:00
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// Writing a page
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
TPoint TBook::page_size() const
|
2004-05-07 10:25:51 +00:00
|
|
|
{
|
2004-05-27 10:55:07 +00:00
|
|
|
return TPoint(_pw, _ph);
|
|
|
|
}
|
2004-05-07 10:25:51 +00:00
|
|
|
|
2004-05-27 10:55:07 +00:00
|
|
|
TPoint TBook::page_res() const
|
|
|
|
{
|
|
|
|
return TPoint(_phr, _pvr);
|
2004-05-07 10:25:51 +00:00
|
|
|
}
|
|
|
|
|
2004-05-27 10:55:07 +00:00
|
|
|
bool TBook::open_page()
|
2004-05-07 10:25:51 +00:00
|
|
|
{
|
2004-05-27 10:55:07 +00:00
|
|
|
if (_out == NULL)
|
|
|
|
_out = new ofstream(_file);
|
2004-05-07 10:25:51 +00:00
|
|
|
|
2004-05-27 10:55:07 +00:00
|
|
|
_page++;
|
|
|
|
_index.add_long(_out->tellp(), page()); // Scrive alla posizione 1 l'inizio di pagina 1
|
|
|
|
|
|
|
|
*_out << "<page number=" << page() << '>' << endl;
|
2004-05-07 10:25:51 +00:00
|
|
|
|
2004-05-27 10:55:07 +00:00
|
|
|
memset(&_tools, -1, sizeof(_tools));
|
|
|
|
_font.create("", 12, XVT_FA_ALL);
|
|
|
|
_horizontal_alignment = 'L';
|
|
|
|
_vertical_alignment = 'T';
|
|
|
|
_rect.reset();
|
2004-05-07 10:25:51 +00:00
|
|
|
|
|
|
|
_print_aborted = false;
|
2004-05-27 10:55:07 +00:00
|
|
|
_page_is_open = true;
|
|
|
|
return _page_is_open;
|
2004-05-07 10:25:51 +00:00
|
|
|
}
|
|
|
|
|
2004-05-27 10:55:07 +00:00
|
|
|
bool TBook::close_page()
|
2004-05-07 10:25:51 +00:00
|
|
|
{
|
2004-05-27 10:55:07 +00:00
|
|
|
if (!_page_is_open)
|
2004-05-07 10:25:51 +00:00
|
|
|
return false;
|
|
|
|
|
2004-05-27 10:55:07 +00:00
|
|
|
*_out << "</page number=" << page() << '>' << endl;
|
|
|
|
|
|
|
|
_pages++;
|
2004-05-07 10:25:51 +00:00
|
|
|
|
2004-05-27 10:55:07 +00:00
|
|
|
_page_is_open = false;
|
|
|
|
return true;
|
2004-05-07 10:25:51 +00:00
|
|
|
}
|
|
|
|
|
2004-05-27 10:55:07 +00:00
|
|
|
void TBook::set_font(const TReport_font& f)
|
2004-05-07 10:25:51 +00:00
|
|
|
{
|
2004-05-27 10:55:07 +00:00
|
|
|
if (f != _font)
|
2004-05-07 10:25:51 +00:00
|
|
|
{
|
2004-05-27 10:55:07 +00:00
|
|
|
_font = f;
|
|
|
|
*_out << "<font"
|
|
|
|
<< " name=\"" << f.name() << '"'
|
|
|
|
<< " size=" << f.size()
|
|
|
|
<< " style=" << f.style()
|
|
|
|
<< " />" << endl;
|
2004-05-07 10:25:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-05-27 10:55:07 +00:00
|
|
|
void TBook::define_frame(const TRectangle& rect)
|
2004-05-07 10:25:51 +00:00
|
|
|
{
|
2004-05-27 10:55:07 +00:00
|
|
|
if (rect != _rect)
|
2004-05-07 10:25:51 +00:00
|
|
|
{
|
2004-05-27 10:55:07 +00:00
|
|
|
_rect = rect;
|
|
|
|
*_out << "<frame"
|
|
|
|
<< " x=" << _rect.x << " y=" << _rect.y
|
|
|
|
<< " dx=" << _rect.width() << " dy=" << _rect.height()
|
|
|
|
<< " />" << endl;
|
2004-05-07 10:25:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-05-27 10:55:07 +00:00
|
|
|
void TBook::draw_text(const TRectangle& r, const char* txt)
|
2004-05-07 10:25:51 +00:00
|
|
|
{
|
2004-05-27 10:55:07 +00:00
|
|
|
const TFixed_string str(txt);
|
|
|
|
if (!str.blank())
|
|
|
|
{
|
|
|
|
define_frame(r);
|
|
|
|
*_out << "<text>" << endl << str << endl << "</text>" << endl;
|
|
|
|
}
|
2004-05-07 10:25:51 +00:00
|
|
|
}
|
|
|
|
|
2004-05-27 10:55:07 +00:00
|
|
|
void TBook::set_pen(COLOR color, int width, PEN_STYLE style)
|
2004-05-07 10:25:51 +00:00
|
|
|
{
|
2004-05-27 10:55:07 +00:00
|
|
|
if (_tools.pen.color != color || _tools.pen.width != width || _tools.pen.style != style)
|
|
|
|
{
|
|
|
|
_tools.pen.color = color;
|
|
|
|
_tools.pen.width = width;
|
|
|
|
_tools.pen.style = style;
|
|
|
|
*_out << "<pen color=" << color << " width=" << width << " style=" << style << " />" << endl;
|
|
|
|
}
|
2004-05-07 10:25:51 +00:00
|
|
|
}
|
|
|
|
|
2004-05-27 10:55:07 +00:00
|
|
|
void TBook::set_brush(COLOR color, PAT_STYLE pattern)
|
2004-05-07 10:25:51 +00:00
|
|
|
{
|
2004-05-27 10:55:07 +00:00
|
|
|
if (_tools.brush.color != color || _tools.brush.pat != pattern)
|
|
|
|
{
|
|
|
|
_tools.brush.color = color;
|
|
|
|
_tools.brush.pat = pattern;
|
|
|
|
*_out << "<brush color=" << color << " pattern=" << pattern << " />" << endl;
|
|
|
|
}
|
2004-05-07 10:25:51 +00:00
|
|
|
}
|
|
|
|
|
2004-05-27 10:55:07 +00:00
|
|
|
void TBook::set_text_color(COLOR fore, COLOR back, bool opaque)
|
2004-05-07 10:25:51 +00:00
|
|
|
{
|
2004-05-27 10:55:07 +00:00
|
|
|
*_out << "<text_color fore=" << fore << " back=" << back << " opaque=" << opaque << " />" << endl;
|
2004-05-07 10:25:51 +00:00
|
|
|
}
|
|
|
|
|
2004-05-27 10:55:07 +00:00
|
|
|
void TBook::set_text_align(char halign, char valign)
|
2004-05-07 10:25:51 +00:00
|
|
|
{
|
2004-05-27 10:55:07 +00:00
|
|
|
if (_horizontal_alignment != halign || _vertical_alignment != valign)
|
2004-05-07 10:25:51 +00:00
|
|
|
{
|
2004-05-27 10:55:07 +00:00
|
|
|
_horizontal_alignment = halign;
|
|
|
|
_vertical_alignment = valign;
|
|
|
|
*_out << "<text_align horizontal=" << halign << " vertical=" << valign << " />" << endl;
|
2004-05-07 10:25:51 +00:00
|
|
|
}
|
|
|
|
}
|
2004-05-27 10:55:07 +00:00
|
|
|
|
|
|
|
void TBook::draw_rectangle(const TRectangle& r)
|
2004-05-07 10:25:51 +00:00
|
|
|
{
|
2004-05-27 10:55:07 +00:00
|
|
|
define_frame(r);
|
|
|
|
*_out << "<rectangle/>" << endl;
|
2004-05-07 10:25:51 +00:00
|
|
|
}
|
|
|
|
|
2004-05-27 10:55:07 +00:00
|
|
|
void TBook::draw_ellipse(const TRectangle& r)
|
2004-05-07 10:25:51 +00:00
|
|
|
{
|
2004-05-27 10:55:07 +00:00
|
|
|
define_frame(r);
|
|
|
|
*_out << "<ellipse/>" << endl;
|
2004-05-07 10:25:51 +00:00
|
|
|
}
|
|
|
|
|
2004-05-27 10:55:07 +00:00
|
|
|
void TBook::draw_line(const TRectangle& r)
|
2004-05-07 10:25:51 +00:00
|
|
|
{
|
2004-05-27 10:55:07 +00:00
|
|
|
define_frame(r);
|
|
|
|
*_out << "<line/>" << endl;
|
2004-05-07 10:25:51 +00:00
|
|
|
}
|
|
|
|
|
2004-05-27 10:55:07 +00:00
|
|
|
void TBook::draw_link(const TRectangle& rect, const char* text, const char* link)
|
2004-05-07 10:25:51 +00:00
|
|
|
{
|
2004-05-27 10:55:07 +00:00
|
|
|
draw_text(rect, text);
|
2004-05-07 10:25:51 +00:00
|
|
|
}
|
|
|
|
|
2004-05-27 10:55:07 +00:00
|
|
|
void TBook::draw_image(const TRectangle& rect, const char* name)
|
|
|
|
{
|
2004-05-27 16:00:36 +00:00
|
|
|
define_frame(rect);
|
|
|
|
*_out << "<image src=\"" << name << "\" />" << endl;
|
2004-05-07 10:25:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
2004-05-27 10:55:07 +00:00
|
|
|
// Reading a page
|
2004-05-07 10:25:51 +00:00
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
2004-05-27 10:55:07 +00:00
|
|
|
bool get_xml_string(const TString& line, const char* attr, TString& value)
|
2004-05-07 10:25:51 +00:00
|
|
|
{
|
2004-05-27 10:55:07 +00:00
|
|
|
TString80 str; str << ' ' << attr << '=';
|
|
|
|
const int pos = line.find(str);
|
|
|
|
if (pos >= 0)
|
2004-05-07 10:25:51 +00:00
|
|
|
{
|
2004-05-27 10:55:07 +00:00
|
|
|
const int apicia = pos + strlen(attr) + 2;
|
|
|
|
if (line[apicia] == '"')
|
|
|
|
{
|
|
|
|
const int apicic = line.find('"', apicia+1);
|
|
|
|
if (apicic > apicia)
|
|
|
|
{
|
|
|
|
value = line.sub(apicia+1, apicic);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2004-05-07 10:25:51 +00:00
|
|
|
{
|
2004-05-27 10:55:07 +00:00
|
|
|
const int space = line.find(' ', apicia);
|
|
|
|
if (space > 0)
|
|
|
|
{
|
|
|
|
value = line.sub(apicia, space);
|
|
|
|
return true;
|
|
|
|
}
|
2004-05-07 10:25:51 +00:00
|
|
|
}
|
|
|
|
}
|
2004-05-27 10:55:07 +00:00
|
|
|
return false;
|
2004-05-07 10:25:51 +00:00
|
|
|
}
|
|
|
|
|
2004-05-27 10:55:07 +00:00
|
|
|
int get_xml_int(const TString& line, const char* attr, int def)
|
2004-05-07 10:25:51 +00:00
|
|
|
{
|
2004-05-27 10:55:07 +00:00
|
|
|
TString16 str;
|
|
|
|
if (get_xml_string(line, attr, str))
|
|
|
|
def = atoi(str);
|
|
|
|
return def;
|
|
|
|
}
|
2004-05-07 10:25:51 +00:00
|
|
|
|
2004-05-27 10:55:07 +00:00
|
|
|
bool TBook::print_page(TWindow& win, size_t page)
|
|
|
|
{
|
|
|
|
if (page <= 0 || page > pages())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
TString str(1024);
|
|
|
|
char* buffer = str.get_buffer();
|
2004-05-07 10:25:51 +00:00
|
|
|
|
2004-05-27 10:55:07 +00:00
|
|
|
const streampos pos = _index.get_long(page);
|
|
|
|
ifstream ifs(_file);
|
|
|
|
ifs.seekg(pos);
|
2004-05-07 10:25:51 +00:00
|
|
|
|
2004-05-27 16:00:36 +00:00
|
|
|
RCT rct;
|
|
|
|
|
2004-05-27 10:55:07 +00:00
|
|
|
while (!ifs.eof())
|
2004-05-07 10:25:51 +00:00
|
|
|
{
|
2004-05-27 10:55:07 +00:00
|
|
|
ifs.getline(buffer, str.size());
|
|
|
|
if (str.starts_with("</page"))
|
|
|
|
break;
|
2004-05-07 10:25:51 +00:00
|
|
|
|
2004-05-27 10:55:07 +00:00
|
|
|
if (str.starts_with("<brush"))
|
2004-05-07 10:25:51 +00:00
|
|
|
{
|
2004-05-27 10:55:07 +00:00
|
|
|
COLOR col = COLOR_BLACK;
|
|
|
|
PAT_STYLE pat = PAT_SOLID;
|
|
|
|
sscanf(str, "<brush color=%u pattern=%u />", &col, &pat);
|
|
|
|
if (pat == PAT_HOLLOW)
|
|
|
|
win.hide_brush();
|
|
|
|
else
|
|
|
|
win.set_brush(col, pat);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (str == "<ellipse/>")
|
|
|
|
{
|
|
|
|
xvt_dwin_draw_oval(win.win(), &rct);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
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);
|
2004-05-27 16:00:36 +00:00
|
|
|
win.log2dev(_rect, rct);
|
2004-05-27 10:55:07 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (str.starts_with("<font"))
|
|
|
|
{
|
|
|
|
TString name = XVT_FFN_COURIER; get_xml_string(str, "name", name);
|
|
|
|
const int size = get_xml_int(str, "size", 12);
|
|
|
|
const XVT_FONT_STYLE_MASK style = get_xml_int(str, "style", 0);
|
|
|
|
TReport_font font; font.create(name, size, style);
|
|
|
|
if (win.win() == 883)
|
|
|
|
xvt_dwin_set_font(win.win(), font.get_xvt_font(win));
|
|
|
|
else
|
|
|
|
xvt_dwin_set_font(win.win(), font.get_preview_font(win, page_res()));
|
|
|
|
continue;
|
|
|
|
}
|
2004-05-27 16:00:36 +00:00
|
|
|
if (str.starts_with("<image"))
|
|
|
|
{
|
|
|
|
TString name; get_xml_string(str, "src", name);
|
|
|
|
TImage* img = _images.image(name);
|
|
|
|
if (img != NULL)
|
|
|
|
img->draw(win.win(), rct);
|
|
|
|
}
|
2004-05-27 10:55:07 +00:00
|
|
|
if (str.starts_with("<line/>"))
|
|
|
|
{
|
|
|
|
PNT fr = { rct.top, rct.left };
|
|
|
|
PNT to = { rct.bottom, rct.right };
|
|
|
|
xvt_dwin_draw_set_pos(win.win(), fr);
|
|
|
|
xvt_dwin_draw_line(win.win(), to);
|
|
|
|
}
|
|
|
|
if (str.starts_with("<pen"))
|
|
|
|
{
|
|
|
|
COLOR col = COLOR_BLACK;
|
|
|
|
int width = 0;
|
|
|
|
PEN_STYLE style = P_SOLID;
|
|
|
|
sscanf(str, "<pen color=%u width=%d style=%u />", &col, &width, &style);
|
|
|
|
if (width < 0)
|
|
|
|
win.hide_pen();
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (win.win() == 883)
|
|
|
|
win.set_pen(col, width * _phr / 72); // Converte width in 72' di pollice
|
|
|
|
else
|
|
|
|
win.set_pen(col, width);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (str == "<rectangle/>")
|
|
|
|
{
|
|
|
|
xvt_dwin_draw_rect(win.win(), &rct);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (str == "<text>")
|
|
|
|
{
|
|
|
|
TString stringona;
|
|
|
|
while (!ifs.eof())
|
|
|
|
{
|
|
|
|
ifs.getline(buffer, str.size());
|
|
|
|
if (str == "</text>")
|
|
|
|
break;
|
|
|
|
stringona << str;
|
|
|
|
}
|
|
|
|
advanced_draw_text(win, stringona, rct, _horizontal_alignment, _vertical_alignment);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (str.starts_with("<text_align"))
|
|
|
|
{
|
|
|
|
sscanf(str, "<text_align horizontal=%c vertical=%c />",
|
|
|
|
&_horizontal_alignment, &_vertical_alignment);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (str.starts_with("<text_color"))
|
|
|
|
{
|
|
|
|
COLOR fore, back;
|
|
|
|
int opaque;
|
|
|
|
sscanf(str, "<text_color fore=%u back=%u opaque=%d />", &fore, &back, &opaque);
|
|
|
|
win.set_color(fore, back);
|
|
|
|
win.set_opaque_text(opaque != 0);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TBook::init()
|
|
|
|
{
|
|
|
|
_rcd = printer().get_printrcd();
|
|
|
|
if (!xvt_print_is_valid(_rcd))
|
|
|
|
return error_box(TR("Stampante non valida"));
|
|
|
|
|
|
|
|
xvt_app_escape (XVT_ESC_GET_PRINTER_INFO, _rcd, &_ph, &_pw, &_pvr, &_phr);
|
|
|
|
|
|
|
|
if (_pw <= 0 || _ph <= 0)
|
|
|
|
return error_box(TR("Dimensioni pagina NULLE"));
|
|
|
|
|
|
|
|
bool ok = true;
|
|
|
|
if (_pvr < 150 || _phr < 150)
|
|
|
|
{
|
|
|
|
ok = yesno_box(TR("Stampante obsoleta o non adeguatamente configurata:\n"
|
|
|
|
"Risoluzione %ldx%ld. Continuare ugualmente?"), _phr, _pvr);
|
|
|
|
}
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TBook::main_loop()
|
|
|
|
{
|
|
|
|
_print_aborted = true;
|
|
|
|
if (!init())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
TWindow_printer win(_rcd);
|
|
|
|
if (!win.ok())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (_pageto < _pagefrom)
|
|
|
|
_pageto = pages();
|
|
|
|
|
|
|
|
_print_aborted = false;
|
|
|
|
for (size_t c = 0; c < _copies && !_print_aborted; c++)
|
|
|
|
{
|
|
|
|
for (size_t page = _pagefrom; page <= _pageto; page++)
|
|
|
|
{
|
|
|
|
if (xvt_print_open_page(_rcd))
|
|
|
|
{
|
|
|
|
print_page(win, page);
|
|
|
|
xvt_print_close_page(_rcd);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_print_aborted = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return !_print_aborted;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOLEAN main_loop_callback(long jolly)
|
|
|
|
{
|
|
|
|
TBook* pp = (TBook*)jolly;
|
|
|
|
return pp->main_loop();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TBook::print(size_t pagefrom, size_t pageto, size_t copies)
|
|
|
|
{
|
|
|
|
if (pages() <= 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (pagefrom == 0)
|
|
|
|
{
|
|
|
|
TPrinter& p = printer();
|
|
|
|
TMask msk("bagn003");
|
|
|
|
msk.set(F_PRINTER, p.printername());
|
|
|
|
msk.set(F_FORM, p.get_form_name());
|
|
|
|
msk.set(F_FONT, p.fontname());
|
|
|
|
msk.set(F_SIZE, p.get_char_size());
|
|
|
|
|
|
|
|
msk.set(F_ISGRAPHICS, p.isgraphics() ? "X" : "");
|
|
|
|
msk.set(F_FROMPAGE, 1);
|
|
|
|
msk.set(F_TOPAGE, pages());
|
|
|
|
msk.set(F_COPIES, 1);
|
|
|
|
if (msk.run() == K_ENTER)
|
|
|
|
{
|
|
|
|
_copies = msk.get_int(F_COPIES);
|
|
|
|
_pagefrom = msk.get_int(F_FROMPAGE);
|
|
|
|
_pageto = msk.get_int(F_TOPAGE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_pagefrom = pagefrom;
|
|
|
|
_pageto = pageto;
|
|
|
|
_copies = copies;
|
|
|
|
}
|
|
|
|
|
|
|
|
xvt_print_start_thread(main_loop_callback, (long)this);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TBook::preview()
|
|
|
|
{
|
|
|
|
TPreview_mask msk(this);
|
|
|
|
const KEY k = msk.run();
|
|
|
|
if (k == ' ')
|
|
|
|
print();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TBook::print_or_preview()
|
|
|
|
{
|
|
|
|
bool ok = true;
|
|
|
|
if (printer().printtype() == screenvis)
|
|
|
|
ok = preview();
|
|
|
|
else
|
|
|
|
ok = print();
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
TBook::TBook(const char* name)
|
|
|
|
: _out(NULL), _is_temporary(false),
|
|
|
|
_pw(0), _ph(0), _pvr(0), _phr(0),
|
|
|
|
_pages(0), _page(0)
|
|
|
|
{
|
|
|
|
_file = name;
|
|
|
|
if (_file.blank())
|
|
|
|
{
|
|
|
|
_file.temp("rep");
|
|
|
|
_is_temporary = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TBook::~TBook()
|
|
|
|
{
|
|
|
|
if (_out != NULL)
|
|
|
|
{
|
|
|
|
_out->close();
|
|
|
|
delete _out;
|
|
|
|
if (_is_temporary)
|
|
|
|
xvt_fsys_removefile(_file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// TReport_book
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// Converte da coordinate logiche (1/100 caratteri) a coordinate fisiche
|
|
|
|
TPoint TReport_book::log2dev(const TPoint& ptlog) const
|
|
|
|
{
|
|
|
|
TPoint ptdev;
|
|
|
|
ptdev.x = (ptlog.x * _phr) / (100 * _report->cpi());
|
|
|
|
ptdev.y = (ptlog.y * _pvr) / (100 * _report->lpi());
|
|
|
|
|
|
|
|
return ptdev;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TReport_book::define_frame(const TRectangle& r)
|
|
|
|
{
|
|
|
|
TPoint ptlog = r; ptlog += _delta;
|
|
|
|
TPoint szlog = r.size();
|
|
|
|
|
|
|
|
const TRectangle rect(log2dev(ptlog), log2dev(szlog));
|
|
|
|
TBook::define_frame(rect);
|
|
|
|
}
|
|
|
|
|
|
|
|
long TReport_book::print_section(char type, int level)
|
|
|
|
{
|
|
|
|
long h = 0;
|
|
|
|
TReport_section* rs = _report->find_section(type, level);
|
|
|
|
if (rs != NULL)
|
|
|
|
h = print_section(*rs);
|
|
|
|
return h;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TReport_book::open_page()
|
|
|
|
{
|
|
|
|
if (!TBook::open_page())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
_report->set_curr_page(page());
|
|
|
|
|
|
|
|
_page_break_allowed = false;
|
|
|
|
_delta.reset();
|
|
|
|
|
|
|
|
TReport_section* page_background = _report->find_section('B', 0);
|
|
|
|
if (page_background != NULL)
|
|
|
|
{
|
|
|
|
_delta = page_background->pos();
|
|
|
|
print_section(*page_background);
|
|
|
|
_delta.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
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 += page_head->pos();
|
|
|
|
_delta.y += print_section(*page_head);
|
|
|
|
_delta.x = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TReport_book::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 = page_foot->pos().x;
|
|
|
|
_delta.y = _logical_foot_pos;
|
2004-05-07 10:25:51 +00:00
|
|
|
print_section(*page_foot);
|
|
|
|
}
|
|
|
|
}
|
2004-05-27 10:55:07 +00:00
|
|
|
return TBook::close_page();
|
2004-05-07 10:25:51 +00:00
|
|
|
}
|
|
|
|
|
2004-05-27 10:55:07 +00:00
|
|
|
void TReport_book::create_links(const TReport_section& rs)
|
2004-05-07 10:25:51 +00:00
|
|
|
{
|
2004-05-27 10:55:07 +00:00
|
|
|
/*
|
2004-05-07 10:25:51 +00:00
|
|
|
TAssoc_array* links = NULL;
|
|
|
|
for (int i = 0; i < rs.items(); i++)
|
|
|
|
{
|
|
|
|
const TReport_field& rf = rs.field(i);
|
|
|
|
if (rf.link().not_empty())
|
|
|
|
{
|
|
|
|
if (links == NULL)
|
|
|
|
links = new TAssoc_array;
|
|
|
|
TToken_string tok(rf.link(), '.');
|
|
|
|
TString table, field;
|
|
|
|
tok.get(0, table); tok.get(1, field);
|
|
|
|
TReport_link* rl = (TReport_link*)links->objptr(table);
|
|
|
|
if (rl == NULL)
|
|
|
|
{
|
|
|
|
rl = new TReport_link(table);
|
|
|
|
links->add(table, rl);
|
|
|
|
}
|
2004-05-27 10:55:07 +00:00
|
|
|
rl->add_rect(rf.get_draw_rect());
|
2004-05-07 10:25:51 +00:00
|
|
|
rl->set(field, rf.get());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (links != NULL)
|
|
|
|
{
|
|
|
|
FOR_EACH_ASSOC_OBJECT((*links), h, key, l)
|
|
|
|
add_link((TReport_link*)l);
|
|
|
|
}
|
2004-05-27 10:55:07 +00:00
|
|
|
*/
|
2004-05-07 10:25:51 +00:00
|
|
|
}
|
|
|
|
|
2004-05-27 10:55:07 +00:00
|
|
|
long TReport_book::print_section(TReport_section& rs)
|
2004-05-07 10:25:51 +00:00
|
|
|
{
|
|
|
|
if (_print_aborted)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
rs.load_fields();
|
2004-05-18 13:47:49 +00:00
|
|
|
|
|
|
|
// Non sono sicuro se vada prima di load_fields o dopo execute_prescript
|
|
|
|
if (rs.condition().not_empty())
|
|
|
|
{
|
|
|
|
TVariant var;
|
2004-05-27 10:55:07 +00:00
|
|
|
_report->evaluate(rs.condition(), var, _nullfld);
|
2004-05-18 13:47:49 +00:00
|
|
|
if (!var.as_bool())
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-05-07 10:25:51 +00:00
|
|
|
rs.execute_prescript();
|
|
|
|
const long height = rs.compute_size().y; // Compute size after the initilization script!
|
|
|
|
|
|
|
|
if (height > 0) // Has some visible fields
|
|
|
|
{
|
|
|
|
bool page_break = _page_break_allowed && rs.page_break();
|
|
|
|
if (!page_break)
|
|
|
|
{
|
|
|
|
long h = height;
|
|
|
|
if (rs.keep_with_next())
|
|
|
|
h += rs.report().section('B', 1).compute_size().y;
|
|
|
|
page_break = (_delta.y + h > _logical_foot_pos);
|
|
|
|
}
|
|
|
|
if (page_break && rs.level() > 0) // Avoid recursion
|
|
|
|
{
|
|
|
|
close_page();
|
|
|
|
open_page();
|
|
|
|
}
|
|
|
|
if (_page_is_open)
|
2004-05-27 10:55:07 +00:00
|
|
|
rs.print(*this);
|
2004-05-07 10:25:51 +00:00
|
|
|
|
2004-05-24 12:51:22 +00:00
|
|
|
if (rs.level() > 0) // Ho stampato qualcosa che non sia lo sfondo!
|
2004-05-07 10:25:51 +00:00
|
|
|
_page_break_allowed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
rs.execute_postscript();
|
|
|
|
|
|
|
|
return height;
|
|
|
|
}
|
|
|
|
|
2004-05-27 10:55:07 +00:00
|
|
|
bool TReport_book::init(TReport& rep)
|
2004-05-07 10:25:51 +00:00
|
|
|
{
|
2004-05-27 10:55:07 +00:00
|
|
|
if (!TBook::init())
|
2004-05-07 10:25:51 +00:00
|
|
|
return false;
|
|
|
|
|
2004-05-27 10:55:07 +00:00
|
|
|
_report = &rep;
|
|
|
|
|
2004-05-07 10:25:51 +00:00
|
|
|
const TPoint siz = page_size();
|
|
|
|
const TPoint res = page_res();
|
2004-05-27 10:55:07 +00:00
|
|
|
|
2004-05-07 10:25:51 +00:00
|
|
|
const double pollici_pagina_y = (double)siz.y / (double)res.y;
|
2004-05-27 10:55:07 +00:00
|
|
|
const double righe_pagina = pollici_pagina_y * _report->lpi();
|
2004-05-07 10:25:51 +00:00
|
|
|
_logical_page_height = long(righe_pagina*100.0);
|
|
|
|
|
|
|
|
const double pollici_pagina_x = (double)siz.x / (double)res.x;
|
2004-05-27 10:55:07 +00:00
|
|
|
const double colonne_pagina = pollici_pagina_x * _report->cpi();
|
2004-05-07 10:25:51 +00:00
|
|
|
_logical_page_width = long(colonne_pagina*100.0);
|
|
|
|
|
2004-05-27 10:55:07 +00:00
|
|
|
const TReport_section& footer = _report->section('F',0);
|
2004-05-07 10:25:51 +00:00
|
|
|
_logical_foot_pos = footer.pos().y;
|
|
|
|
if (_logical_foot_pos <= 0)
|
|
|
|
{
|
|
|
|
const long logical_footer_height = footer.compute_size().y;
|
|
|
|
_logical_foot_pos = _logical_page_height - logical_footer_height;
|
|
|
|
}
|
|
|
|
|
2004-05-27 10:55:07 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TReport_book::add(TReport& rep)
|
|
|
|
{
|
|
|
|
if (!init(rep))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!_report->execute_prescript())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
TRecordset* rex = _report->recordset();
|
|
|
|
if (rex == NULL || rex->items() <= 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
TString msg = TR("Elaborazione report");
|
|
|
|
msg << ' ' << _report->filename();
|
|
|
|
TProgind pi(rex->items(), msg, true, true);
|
2004-05-07 10:25:51 +00:00
|
|
|
|
|
|
|
TString_array oldgroup, newgroup;
|
2004-05-27 10:55:07 +00:00
|
|
|
const int max_group = _report->find_max_level('H');
|
2004-05-07 10:25:51 +00:00
|
|
|
if (max_group >= 2)
|
|
|
|
{
|
|
|
|
for (int g = 2; g <= max_group; g++)
|
|
|
|
oldgroup.add(EMPTY_STRING, g);
|
|
|
|
}
|
2004-05-27 10:55:07 +00:00
|
|
|
const int max_body = _report->find_max_level('B');
|
2004-05-07 10:25:51 +00:00
|
|
|
int last_body_height = 0;
|
|
|
|
|
|
|
|
_is_last_page = false;
|
|
|
|
open_page();
|
2004-05-27 10:55:07 +00:00
|
|
|
for (bool ok = rex->move_to(0); ok && !_print_aborted; ok = rex->move_next())
|
2004-05-07 10:25:51 +00:00
|
|
|
{
|
|
|
|
if (max_group >= 2) // Gestione raggruppamenti
|
|
|
|
{
|
|
|
|
int changed = 0;
|
|
|
|
TVariant var;
|
|
|
|
for (int g = 2; g <= max_group; g++)
|
|
|
|
{
|
2004-05-27 10:55:07 +00:00
|
|
|
const TString& expr = _report->section('H', g).grouped_by();
|
|
|
|
_report->evaluate(expr, var, _alfafld);
|
2004-05-07 10:25:51 +00:00
|
|
|
const TString& grp = var.as_string();
|
|
|
|
newgroup.add(grp, g);
|
|
|
|
if (newgroup.row(g) != oldgroup.row(g) || rex->current_row() == 0)
|
|
|
|
changed = g;
|
|
|
|
}
|
|
|
|
if (changed)
|
|
|
|
{
|
|
|
|
oldgroup = newgroup;
|
|
|
|
|
|
|
|
if (_delta.x > 0) // Devo tornare a capo!
|
|
|
|
_delta.y += last_body_height;
|
|
|
|
_delta.x = 0;
|
|
|
|
|
|
|
|
if (rex->current_row() > 0)
|
|
|
|
{
|
|
|
|
for (int g = 2; g <= changed; g++)
|
|
|
|
_delta.y += print_section('F', g);
|
|
|
|
}
|
|
|
|
for (int g = changed; g >= 2 ; g--)
|
|
|
|
_delta.y += print_section('H', g);
|
|
|
|
}
|
|
|
|
}
|
2004-05-18 13:47:49 +00:00
|
|
|
// Stampa di tutti i body
|
2004-05-07 10:25:51 +00:00
|
|
|
for (int b = 1; b <= max_body; b++)
|
|
|
|
{
|
|
|
|
const int dy = print_section('B', b);
|
|
|
|
|
|
|
|
int column_delta = 0;
|
|
|
|
// Cerco di vedere se e' possibile la stampa etichette
|
|
|
|
if (dy > 0)
|
|
|
|
{
|
2004-05-27 10:55:07 +00:00
|
|
|
const int dx = _report->section('B', b).size().x;
|
2004-05-07 10:25:51 +00:00
|
|
|
// Se dx > 0 ho una sezione a dimensione fissa
|
|
|
|
if (dx > 0 && _delta.x+2*dx <= _logical_page_width)
|
|
|
|
{
|
|
|
|
column_delta = dx;
|
|
|
|
last_body_height = dy;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (column_delta > 0)
|
|
|
|
_delta.x += column_delta;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_delta.x = 0;
|
|
|
|
_delta.y += dy;
|
|
|
|
last_body_height = 0; // Non servirebbe strettamente
|
|
|
|
}
|
|
|
|
}
|
2004-05-27 10:55:07 +00:00
|
|
|
|
|
|
|
pi.addstatus(1);
|
|
|
|
if (pi.iscancelled())
|
|
|
|
_print_aborted = true;
|
|
|
|
|
2004-05-07 10:25:51 +00:00
|
|
|
}
|
2004-05-27 10:55:07 +00:00
|
|
|
if (!_print_aborted)
|
2004-05-07 10:25:51 +00:00
|
|
|
{
|
|
|
|
if (max_group >= 2) // Devo stampare tutte le code dei raggrupamenti
|
|
|
|
{
|
|
|
|
for (int g = 2; g <= max_group; g++)
|
|
|
|
_delta.y += print_section('F', g);
|
|
|
|
}
|
|
|
|
|
2004-05-27 10:55:07 +00:00
|
|
|
TReport_section* fl = _report->find_section('F',1);
|
|
|
|
if (fl != NULL) // Gestione footer last (se esite)
|
2004-05-18 13:47:49 +00:00
|
|
|
{
|
2004-05-27 10:55:07 +00:00
|
|
|
const int fy = fl->pos().y;
|
|
|
|
if (fy > 0) // Ha una coordinata y imposta
|
2004-05-18 13:47:49 +00:00
|
|
|
{
|
2004-05-27 10:55:07 +00:00
|
|
|
if (fy < _delta.y) // Sono gia' andato oltre quindi salto pagina
|
2004-05-18 13:47:49 +00:00
|
|
|
{
|
2004-05-27 10:55:07 +00:00
|
|
|
close_page();
|
|
|
|
open_page();
|
2004-05-18 13:47:49 +00:00
|
|
|
}
|
2004-05-27 10:55:07 +00:00
|
|
|
_delta.x = 0;
|
|
|
|
_delta.y = fy;
|
|
|
|
|
|
|
|
// Azzero temporaneamente le dimensioni del footer per evitare salti pagina
|
|
|
|
const int lfp = _logical_foot_pos;
|
|
|
|
_logical_foot_pos = _logical_page_height;
|
|
|
|
print_section(*fl);
|
|
|
|
_logical_foot_pos = lfp;
|
2004-05-18 13:47:49 +00:00
|
|
|
}
|
2004-05-27 10:55:07 +00:00
|
|
|
else
|
|
|
|
print_section(*fl); // Stampa normale
|
2004-05-18 13:47:49 +00:00
|
|
|
}
|
2004-05-27 10:55:07 +00:00
|
|
|
|
2004-05-07 10:25:51 +00:00
|
|
|
_is_last_page = true;
|
|
|
|
close_page();
|
2004-05-27 10:55:07 +00:00
|
|
|
|
|
|
|
_report->execute_postscript();
|
2004-05-07 10:25:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2004-05-27 10:55:07 +00:00
|
|
|
bool TReport_book::print(size_t pagefrom, size_t pageto, size_t copies)
|
2004-05-07 10:25:51 +00:00
|
|
|
{
|
2004-05-27 10:55:07 +00:00
|
|
|
if (pages() <= 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (pagefrom <= 0)
|
2004-05-07 10:25:51 +00:00
|
|
|
{
|
2004-05-27 10:55:07 +00:00
|
|
|
TPrinter& p = printer();
|
|
|
|
TMask msk("bagn003");
|
|
|
|
msk.set(F_PRINTER, p.printername());
|
|
|
|
if (_report != NULL)
|
|
|
|
{
|
|
|
|
msk.set(F_FORM, _report->filename());
|
|
|
|
msk.set(F_FONT, _report->font().name());
|
|
|
|
msk.set(F_SIZE, _report->font().size());
|
|
|
|
}
|
|
|
|
msk.set(F_ISGRAPHICS, p.isgraphics() ? "X" : "");
|
|
|
|
msk.set(F_FROMPAGE, 1);
|
|
|
|
msk.set(F_TOPAGE, page());
|
|
|
|
msk.set(F_COPIES, 1);
|
|
|
|
if (msk.run() == K_ENTER)
|
|
|
|
{
|
|
|
|
copies = msk.get_int(F_COPIES);
|
|
|
|
pagefrom = msk.get_int(F_FROMPAGE);
|
|
|
|
pageto = msk.get_int(F_TOPAGE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return false;
|
2004-05-07 10:25:51 +00:00
|
|
|
}
|
2004-05-27 10:55:07 +00:00
|
|
|
|
|
|
|
return TBook::print(pagefrom, pageto, copies);
|
2004-05-07 10:25:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// Remote control interface
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void abort_printing()
|
|
|
|
{ _print_aborted = true; }
|
|
|
|
|
2004-05-24 12:51:22 +00:00
|
|
|
|