Corretta ripetizione stampa dopo link; cambiamenti cosmetici

git-svn-id: svn://10.65.10.50/trunk@230 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
villa 1994-09-14 07:33:25 +00:00
parent 8097b5d8eb
commit 4e053141b7

View File

@ -1,4 +1,4 @@
// $Id: printapp.cpp,v 1.5 1994-08-31 07:29:29 villa Exp $ // $Id: printapp.cpp,v 1.6 1994-09-14 07:33:25 villa Exp $
#include <ctype.h> #include <ctype.h>
#include <stdarg.h> #include <stdarg.h>
@ -60,29 +60,27 @@ class _Token:public TObject
friend class TPrint_application; friend class TPrint_application;
int _tag; int _tag;
int _row; int _row;
public: public:
int tag () int tag ()
{ {
return _tag; return _tag;
} }
int row () int row ()
{ {
return _row; return _row;
} }
void tag (int t) void tag (int t)
{ {
_tag = t; _tag = t;
} }
void row (int r) void row (int r)
{ {
_row = r; _row = r;
} }
virtual ~ _Token () virtual ~ _Token () {}
{
}
}; };
class _PrintfTok:public _Token class _PrintfTok : public _Token
// something to be printed (actually already printed on _val) // something to be printed (actually already printed on _val)
{ {
friend class TPrint_application; friend class TPrint_application;
@ -94,12 +92,10 @@ class _PrintfTok:public _Token
row (rw); row (rw);
_val = val; _val = val;
} }
virtual ~ _PrintfTok () virtual ~ _PrintfTok () {}
{
}
}; };
class _FieldTok:public _Token class _FieldTok : public _Token
// something more complex to be printed // something more complex to be printed
{ {
friend class TPrint_application; friend class TPrint_application;
@ -127,7 +123,7 @@ class _FieldTok:public _Token
} }
}; };
class _PrintfRef:public _Token class _PrintfRef : public _Token
// to be printed by reference via format // to be printed by reference via format
// must pass valid pointer to object // must pass valid pointer to object
{ {
@ -150,8 +146,7 @@ class _PrintfRef:public _Token
} }
}; };
void TPrint_application :: void TPrint_application::_reset_tree (link_item * head)
_reset_tree (link_item * head)
{ {
if (head) if (head)
{ {
@ -163,8 +158,7 @@ _reset_tree (link_item * head)
} }
} }
link_item *TPrint_application :: link_item *TPrint_application::_look_print_node (link_item * head, int logicnum)
_look_print_node (link_item * head, int logicnum)
{ {
// look for <from> node to attach to // look for <from> node to attach to
// since it reflects a relation, it won't have more than // since it reflects a relation, it won't have more than
@ -182,14 +176,12 @@ _look_print_node (link_item * head, int logicnum)
return NULL; return NULL;
} }
void TPrint_application :: void TPrint_application::add_file (const char *tab, int from)
add_file (const char *tab, int from)
{ {
add_file (TTable ::name2log (tab), from); add_file (TTable ::name2log (tab), from);
} }
void TPrint_application :: void TPrint_application::add_file (int file, int from)
add_file (int file, int from)
{ {
link_item *nw = new link_item (file); link_item *nw = new link_item (file);
if (_pr_tree == NULL) if (_pr_tree == NULL)
@ -197,14 +189,14 @@ add_file (int file, int from)
_pr_tree = nw; _pr_tree = nw;
return; return;
} }
if (from == 0) if (from == 0)
from = _pr_tree->_logicnum; from = _pr_tree->_logicnum;
link_item *fr = _look_print_node (_pr_tree, from); link_item *fr = _look_print_node (_pr_tree, from);
CHECKD (fr, "add_file: nonexistent node: logicnum = ", from); CHECKD (fr, "add_file: nonexistent node: logicnum = ", from);
if (fr->_son) if (fr->_son)
{ {
fr = fr->_son; fr = fr->_son;
@ -221,8 +213,7 @@ add_file (int file, int from)
static char tb[120]; static char tb[120];
int TPrint_application :: int TPrint_application::enable_link (const char *descr, char fg, char bg)
enable_link (const char *descr, char fg, char bg)
{ {
TToken_string *tt = new TToken_string (30); TToken_string *tt = new TToken_string (30);
char b[2]; char b[2];
@ -232,78 +223,71 @@ enable_link (const char *descr, char fg, char bg)
tt->add (b); tt->add (b);
b[0] = bg; b[0] = bg;
tt->add (b); tt->add (b);
printer ().links ().add (tt); printer().links ().add (tt);
return printer ().links ().items () - 1; return printer().links ().items () - 1;
} }
void TPrint_application :: void TPrint_application::disable_link (char fg, char bg)
disable_link (char fg, char bg)
{ {
for (int i = 0; i < printer ().links ().items (); i++) for (int i = 0; i < printer().links ().items (); i++)
{ {
TToken_string & t = (TToken_string &) printer ().links ()[i]; TToken_string & t = (TToken_string &) printer().links ()[i];
char f = *(t.get (1)); char f = *(t.get (1));
char b = *(t.get (2)); char b = *(t.get (2));
if (f == fg && b == bg) if (f == fg && b == bg)
{ {
printer ().links ().add (NULL, i); printer().links ().add (NULL, i);
printer ().links ().pack (); printer().links ().pack ();
break; break;
} }
} }
} }
void TPrint_application :: void TPrint_application::set_multiple_link (bool on)
set_multiple_link (bool on)
{ {
printer ().setmultiplelink (on); printer().setmultiplelink (on);
} }
void TPrint_application :: void TPrint_application::_pp_link (int id, const char *text)
_pp_link (int id, const char *text)
{ {
TPrint_application *prapp = (TPrint_application *) MainApp (); TPrint_application *prapp = (TPrint_application *) MainApp ();
prapp->process_link (id, text); prapp->process_link (id, text);
} }
void TPrint_application :: void TPrint_application::_pp_header (TPrinter &)
_pp_header (TPrinter &)
{ {
TPrint_application *prapp = (TPrint_application *) MainApp (); TPrint_application *prapp = (TPrint_application *) MainApp ();
prapp->preprocess_header (); prapp->preprocess_header ();
prapp->printer ().resetheader (); prapp->printer().resetheader ();
int ii = (prapp->_header).last (); int ii = (prapp->_header).last ();
// reset and add header/footer lines // reset and add header/footer lines
for (int i = 0; i <= ii; i++) for (int i = 0; i <= ii; i++)
if ((prapp->_header).objptr (i) != NULL) if ((prapp->_header).objptr (i) != NULL)
prapp->printer ().setheaderline (i, prapp->printer().setheaderline (i,
new TPrintrow ((TPrintrow &) (prapp->_header)[i])); new TPrintrow ((TPrintrow &) (prapp->_header)[i]));
} }
void TPrint_application :: void TPrint_application::_pp_footer (TPrinter &)
_pp_footer (TPrinter &)
{ {
TPrint_application *prapp = (TPrint_application *) MainApp (); TPrint_application *prapp = (TPrint_application *) MainApp ();
prapp->preprocess_footer (); prapp->preprocess_footer ();
prapp->printer ().resetfooter (); prapp->printer().resetfooter ();
int ii = (prapp->_footer).last (); int ii = (prapp->_footer).last ();
for (int i = 0; i <= ii; i++) for (int i = 0; i <= ii; i++)
if ((prapp->_footer).objptr (i) != NULL) if ((prapp->_footer).objptr (i) != NULL)
prapp->printer ().setfooterline (i, prapp->printer().setfooterline (i,
new TPrintrow ((TPrintrow &) (prapp->_footer)[i])); new TPrintrow ((TPrintrow &) (prapp->_footer)[i]));
} }
void TPrint_application :: void TPrint_application::set_background (const char *bgdesc)
set_background (const char *bgdesc)
{ {
printer ().setbackground (bgdesc); printer().setbackground (bgdesc);
} }
const char * const char* FLD (int lognum, const char *f, int from, int to)
FLD (int lognum, const char *f, int from, int to)
{ {
sprintf (tb, "%c|%d|%s|%d|%d", 'n', lognum, f, from, to); sprintf (tb, "%c|%d|%s|%d|%d", 'n', lognum, f, from, to);
char *p = new char[strlen (tb) + 1]; char *p = new char[strlen (tb) + 1];
@ -311,8 +295,7 @@ FLD (int lognum, const char *f, int from, int to)
return p; return p;
} }
const char * const char* FLD (int lognum, const char *f, const char *picture)
FLD (int lognum, const char *f, const char *picture)
{ {
sprintf (tb, "%c|%d|%s|%s", 'p', lognum, f, picture); sprintf (tb, "%c|%d|%s|%s", 'p', lognum, f, picture);
char *p = new char[strlen (tb) + 1]; char *p = new char[strlen (tb) + 1];
@ -320,8 +303,7 @@ FLD (int lognum, const char *f, const char *picture)
return p; return p;
} }
const char * const char* FLD (const char *tabname, const char *f, int from, int to)
FLD (const char *tabname, const char *f, int from, int to)
{ {
CHECKS (strlen (tabname) < 5, "Invalid table name", tabname); CHECKS (strlen (tabname) < 5, "Invalid table name", tabname);
int lognum = TTable ::name2log (tabname); int lognum = TTable ::name2log (tabname);
@ -331,8 +313,7 @@ FLD (const char *tabname, const char *f, int from, int to)
return p; return p;
} }
const char * const char* FLD (const char *tabname, const char *f, const char *picture)
FLD (const char *tabname, const char *f, const char *picture)
{ {
CHECKS (strlen (tabname) < 5, "Invalid table name", tabname); CHECKS (strlen (tabname) < 5, "Invalid table name", tabname);
int lognum = TTable ::name2log (tabname); int lognum = TTable ::name2log (tabname);
@ -342,7 +323,7 @@ FLD (const char *tabname, const char *f, const char *picture)
return p; return p;
} }
TString & fill_str (TString & t, char f) TString& fill_str (TString & t, char f)
{ {
for (int kk = t.len () - 1; kk >= 0; kk--) for (int kk = t.len () - 1; kk >= 0; kk--)
{ {
@ -370,8 +351,7 @@ TString & fill_str (TString & t, char f)
// printer().setlinkdescr(descr); // printer().setlinkdescr(descr);
// } // }
void TPrint_application :: void TPrint_application::select_cursor (int c)
select_cursor (int c)
{ {
if (c == -1) if (c == -1)
_cur = NULL; _cur = NULL;
@ -379,8 +359,7 @@ select_cursor (int c)
_cur = (TCursor *) & _cursors[c]; _cur = (TCursor *) & _cursors[c];
} }
TCursor *TPrint_application :: TCursor* TPrint_application::get_cursor (int c)
get_cursor (int c)
{ {
if (c == -1) if (c == -1)
return NULL; return NULL;
@ -388,8 +367,7 @@ get_cursor (int c)
return (TCursor *) & _cursors[c]; return (TCursor *) & _cursors[c];
} }
int TPrint_application :: int TPrint_application::add_cursor (TCursor * c)
add_cursor (TCursor * c)
{ {
if (c == NULL) if (c == NULL)
return -1; return -1;
@ -398,8 +376,7 @@ add_cursor (TCursor * c)
return _cursors.items () - 1; return _cursors.items () - 1;
} }
void TPrint_application :: void TPrint_application::reset_row (int r)
reset_row (int r)
{ {
r--; r--;
int tmp = _rows.items (); int tmp = _rows.items ();
@ -417,16 +394,14 @@ reset_row (int r)
_maxrow--; _maxrow--;
} }
void TPrint_application :: void TPrint_application::reset_print ()
reset_print ()
{ {
_rows.destroy (); _rows.destroy ();
_maxrow = 0; _maxrow = 0;
_print_defined = FALSE; _print_defined = FALSE;
} }
void TPrint_application :: void TPrint_application::set_header (int r, const char *fmt,...)
set_header (int r, const char *fmt,...)
{ {
CHECK (r >= 1, "Header rows start at 1"); CHECK (r >= 1, "Header rows start at 1");
va_list vl; va_list vl;
@ -443,8 +418,7 @@ set_header (int r, const char *fmt,...)
pp->put (__tmp_string); pp->put (__tmp_string);
} }
void TPrint_application :: void TPrint_application::set_footer (int r, const char *fmt,...)
set_footer (int r, const char *fmt,...)
{ {
CHECK (r >= 1, "Footer rows start at 1"); CHECK (r >= 1, "Footer rows start at 1");
va_list vl; va_list vl;
@ -460,33 +434,29 @@ set_footer (int r, const char *fmt,...)
pp->put (__tmp_string); pp->put (__tmp_string);
} }
void TPrint_application :: void TPrint_application::reset_header ()
reset_header ()
{ {
_header.destroy (); _header.destroy ();
printer ().resetheader (); printer().resetheader ();
} }
void TPrint_application :: void TPrint_application::reset_footer ()
reset_footer ()
{ {
_footer.destroy (); _footer.destroy ();
printer ().resetfooter (); printer().resetfooter ();
} }
void TPrint_application :: void TPrint_application::fill_page (int from)
fill_page (int from)
{ {
from--; from--;
for (int i = (from == -1 ? _maxrow : from); i <= printer ().formlen (); i++) for (int i = (from == -1 ? _maxrow : from); i <= printer().formlen (); i++)
{ {
reset_row (i); reset_row (i);
set_row (i, ""); set_row (i, "");
} }
} }
void TPrint_application :: void TPrint_application::set_row (int r, const char *frmt,...)
set_row (int r, const char *frmt,...)
{ {
CHECK (r >= 1, "Print rows start at 1"); CHECK (r >= 1, "Print rows start at 1");
@ -777,19 +747,21 @@ set_row (int r, const char *frmt,...)
va_end (params); va_end (params);
} }
void TPrint_application :: void TPrint_application::set_translation (int lognum, const char *field,
set_translation (int lognum, const char *field, const char *from, const char *to)
const char *from, const char *to)
{ {
_transtab.add (new _Transfield (lognum, field, from, to)); _transtab.add (new _Transfield (lognum, field, from, to));
} }
void TPrint_application::print () void TPrint_application::print()
{ {
// open printer if needed // open printer if needed
if (!(printer ().isopen ())) if (!(printer().isopen ()))
if (!printer ().open ()) if (!printer().open ())
return; return;
// only external apps can change it
_repeat_print = FALSE;
// never print multiple copies if printer is viswin // never print multiple copies if printer is viswin
// only application may repeat printing by setting _repeat_print // only application may repeat printing by setting _repeat_print
@ -801,68 +773,65 @@ void TPrint_application::print ()
if (_cur == NULL) if (_cur == NULL)
{ {
//************************************************ //************************************************
while (_repeat_print || nc--) while (nc--)
{ {
_repeat_print = FALSE;
int cnt = 0;
int cnt = 0; bool ok = TRUE;
bool ok = TRUE; do
do
{ {
if (preprocess_print (0, cnt)) if (preprocess_print (0, cnt))
{ {
int cnt2 = 0; int cnt2 = 0;
do do
{ {
if (preprocess_page (0, cnt2)) if (preprocess_page (0, cnt2))
{ {
set_page (0, cnt2); set_page (0, cnt2);
ok = print_one (0); ok = print_one (0);
} }
} }
while (ok && postprocess_page (0, cnt2++) == REPEAT_PAGE); while (ok && postprocess_page (0, cnt2++) == REPEAT_PAGE);
} }
} }
while (ok && postprocess_print (0, cnt++) == REPEAT_PAGE); while (ok && postprocess_print (0, cnt++) == REPEAT_PAGE);
// ***************************************************** // *****************************************************
} }
} }
else else
{ {
// cursor exists ********************************************* // cursor exists *********************************************
while (_repeat_print || nc--) while (nc--)
{ {
_repeat_print = FALSE; (*_cur) = 0l;
(*_cur) = 0l; _cur->freeze (TRUE);
_cur->freeze (TRUE);
if (_cur->items () >= _wthr &&
if (_cur->items () >= _wthr && (_force_progind || printer ().printtype () != screenvis))
(_force_progind || printer ().printtype () != screenvis)) _prind = new TProgind (_cur->items (),
_prind = new TProgind (_cur->items (), (char *) (const char *) _wmess,
(char *) (const char *) _wmess, _wcancel, _wbar, 35);
_wcancel, _wbar, 35); print_tree (_pr_tree);
print_tree (_pr_tree); _cur->freeze (FALSE);
_cur->freeze (FALSE);
if (_prind)
if (_prind) {
{
delete _prind;; delete _prind;;
_prind = NULL; _prind = NULL;
} }
} }
// ************************************************************************ // ****************************************************************
} }
if (printer().isopen ()) if (printer().isopen ())
{ {
printer().close (); printer().close();
printer().resetheader (); printer().resetheader();
printer().resetfooter (); printer().resetfooter();
} }
postclose_print (); postclose_print ();
} }
bool TPrint_application :: bool TPrint_application::print_tree (link_item * head)
print_tree (link_item * head)
{ {
bool go = TRUE; bool go = TRUE;
while (head) while (head)
@ -1195,11 +1164,11 @@ bool TPrint_application::print_one (int file)
for (i = 0; i <= _maxrow; i++) for (i = 0; i <= _maxrow; i++)
{ {
TPrintrow *pr = (TPrintrow *) & rw[i]; TPrintrow *pr = (TPrintrow *) & rw[i];
if (!(printer ().print (*pr))) if (!(printer().print (*pr)))
break; break;
} }
if (_auto_ff && _maxrow < printer ().formlen ()) if (_auto_ff && _maxrow < printer().formlen ())
printer ().formfeed (); printer().formfeed ();
delete pos; delete pos;
// TRUE if all rows have been printed // TRUE if all rows have been printed
@ -1213,7 +1182,7 @@ bool TPrint_application::menu(MENU_TAG m)
if (m >= BAR_ITEM (1) && m <= BAR_ITEM (20)) if (m >= BAR_ITEM (1) && m <= BAR_ITEM (20))
{ {
_last_choice = m; _last_choice = m;
do_print ((m - BAR_ITEM (0)) / 100); do_print((m - BAR_ITEM (0)) / 100);
} }
// Se non esistono altre voci di menu termina l'applicazione // Se non esistono altre voci di menu termina l'applicazione
@ -1223,9 +1192,9 @@ bool TPrint_application::menu(MENU_TAG m)
bool TPrint_application::create () bool TPrint_application::create ()
{ {
TApplication ::create (); TApplication ::create ();
printer ().setfooterhandler (_pp_footer); printer().setfooterhandler (_pp_footer);
printer ().setheaderhandler (_pp_header); printer().setheaderhandler (_pp_header);
printer ().setlinkhandler (_pp_link); printer().setlinkhandler (_pp_link);
user_create (); user_create ();
dispatch_e_menu (_last_choice); dispatch_e_menu (_last_choice);
return TRUE; return TRUE;
@ -1242,7 +1211,7 @@ void TPrint_application::do_print (int n)
{ {
while (set_print (n)) while (set_print (n))
{ {
print (); do { print(); } while (_repeat_print);
enable_print_menu (); enable_print_menu ();
} }
} }