Aggiunto set_row con printrow

git-svn-id: svn://10.65.10.50/trunk@2751 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
villa 1996-04-18 09:33:27 +00:00
parent f9bb573d44
commit 239ebd45e8
2 changed files with 488 additions and 505 deletions

View File

@ -56,28 +56,16 @@ class _Transfield:public TObject
} }
}; };
class _Token:public TObject 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() const { return _tag; }
{ int row() const { return _row; }
return _tag; void tag(int t) { _tag = t; }
} void row (int r) { _row = r; }
int row ()
{
return _row;
}
void tag (int t)
{
_tag = t;
}
void row (int r)
{
_row = r;
}
virtual ~ _Token () {} virtual ~ _Token () {}
}; };
@ -86,14 +74,10 @@ class _PrintfTok : public _Token
{ {
friend class TPrint_application; friend class TPrint_application;
TString _val; TString _val;
public: public:
_PrintfTok (int rw, const char *val):_val (0) _PrintfTok (int rw, const char *val) : _val(val)
{ { tag(0); row(rw); }
tag (0); virtual ~_PrintfTok () {}
row (rw);
_val = val;
}
virtual ~ _PrintfTok () {}
}; };
class _FieldTok : public _Token class _FieldTok : public _Token
@ -111,8 +95,8 @@ class _FieldTok : public _Token
int size = -1, int dec = -1): int size = -1, int dec = -1):
_fld (20) _fld (20)
{ {
tag (1); tag(1);
row (rw); row(rw);
_fld = (const char *) fld; _fld = (const char *) fld;
_flags = flags; _flags = flags;
_size = size, _align = align; _size = size, _align = align;
@ -142,11 +126,23 @@ class _PrintfRef : public _Token
_fmt = fmt; _fmt = fmt;
_fmt[0] = '%'; _fmt[0] = '%';
} }
virtual ~ _PrintfRef () virtual ~ _PrintfRef () {}
{
}
}; };
class _PrintRowToken : public _Token
// printrow direct
// must pass valid printrow (duplicated)
{
friend class TPrint_application;
TPrintrow _pr;
public:
TPrintrow& printrow() { return _pr; }
_PrintRowToken (int rw, TPrintrow& pr) : _pr((const TPrintrow&)pr)
{ tag(3); row(rw); }
virtual ~ _PrintRowToken () {}
};
void TPrint_application::_reset_tree(link_item * head) void TPrint_application::_reset_tree(link_item * head)
{ {
if (head) if (head)
@ -204,7 +200,7 @@ int TPrint_application::set_bookmark(
void TPrint_application::add_file (const char *tab, int from) void TPrint_application::add_file (const char *tab, int from)
{ {
add_file(TTable::name2log (tab), from); add_file(TTable::name2log(tab), from);
} }
// @doc EXTERNAL // @doc EXTERNAL
@ -432,19 +428,11 @@ const char* FLD (const char *tabname, const char *f, const char *picture)
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--)
{ if (t[kk] == ' ') t[kk] = f;
if (t[kk] == ' ') else break;
t[kk] = f;
else
break;
}
for (kk = 0; kk < t.len (); kk++) for (kk = 0; kk < t.len (); kk++)
{ if (t[kk] == ' ') t[kk] = f;
if (t[kk] == ' ') else break;
t[kk] = f;
else
break;
}
return t; return t;
} }
@ -452,25 +440,16 @@ TString& fill_str (TString & t, char f)
// Printapp code at last // Printapp code at last
// ======================================================== // ========================================================
//void TPrint_application::enable_link(const char* descr, char fg, char bg)
// {
// printer().setlinkdescr(descr);
// }
void TPrint_application::select_cursor (int c) void TPrint_application::select_cursor (int c)
{ {
if (c == -1) if (c == -1) _cur = NULL;
_cur = NULL; else _cur = (TCursor *) & _cursors[c];
else
_cur = (TCursor *) & _cursors[c];
} }
TCursor* TPrint_application::get_cursor (int c) TCursor* TPrint_application::get_cursor (int c)
{ {
if (c == -1) if (c == -1) return NULL;
return NULL; else return (TCursor *) & _cursors[c];
else
return (TCursor *) & _cursors[c];
} }
// @doc EXTERNAL // @doc EXTERNAL
@ -490,7 +469,7 @@ int TPrint_application::add_cursor (
return -1; return -1;
_cursors.add (c); _cursors.add (c);
_cur = c; _cur = c;
return _cursors.items () - 1; return _cursors.items() - 1;
} }
void TPrint_application::reset_row (int r) void TPrint_application::reset_row (int r)
@ -599,6 +578,17 @@ void TPrint_application::merge_export_file(const char* file, bool header, bool d
} }
} }
void TPrint_application::set_row(int r, TPrintrow& pr)
{
CHECK (r >= 1, "Print rows start at 1");
_print_defined = TRUE;
_currow = --r;
if (_currow > _maxrow)
_maxrow = _currow;
_rows.add(new _PrintRowToken(_currow, pr));
}
// @doc EXTERNAL // @doc EXTERNAL
// @mfunc Permette di settare una riga di stampa // @mfunc Permette di settare una riga di stampa
@ -719,7 +709,7 @@ void TPrint_application::set_row (
_maxrow = _currow; _maxrow = _currow;
va_list params; va_list params;
va_start (params, frmt); va_start(params, frmt);
// parse format string // parse format string
while ((ch = *fmt++) != '\0') while ((ch = *fmt++) != '\0')
@ -753,7 +743,6 @@ void TPrint_application::set_row (
digbuf[i] = '\0'; digbuf[i] = '\0';
dec = atoi (digbuf); dec = atoi (digbuf);
flags |= DEC_FLAG; flags |= DEC_FLAG;
// ch = *fmt++;
} }
else if (ch == ',') else if (ch == ',')
{ {
@ -807,31 +796,37 @@ void TPrint_application::set_row (
break; break;
case 'T': case 'T':
flags |= IGNORE_FILL; flags |= IGNORE_FILL;
// fall down
case 't': case 't':
flags |= TRANS_FLAG; flags |= TRANS_FLAG;
break; break;
case 'D': case 'D':
flags |= IGNORE_FILL; flags |= IGNORE_FILL;
// fall down
case 'd': case 'd':
flags |= DATE_FLAG; flags |= DATE_FLAG;
break; break;
case 'F': case 'F':
flags |= IGNORE_FILL; flags |= IGNORE_FILL;
// fall down
case 'f': case 'f':
flags |= BOOLEAN_FLAG; flags |= BOOLEAN_FLAG;
break; break;
case 'S': case 'S':
flags |= IGNORE_FILL; flags |= IGNORE_FILL;
// fall down
case 's': case 's':
flags |= STRING_FLAG; flags |= STRING_FLAG;
break; break;
case 'C': case 'C':
flags |= IGNORE_FILL; flags |= IGNORE_FILL;
// fall down
case 'c': case 'c':
flags |= RECNO_FLAG; flags |= RECNO_FLAG;
break; break;
case 'N': case 'N':
flags |= IGNORE_FILL; flags |= IGNORE_FILL;
// fall down
case 'n': case 'n':
flags |= NUMBER_FLAG; flags |= NUMBER_FLAG;
break; break;
@ -846,8 +841,7 @@ void TPrint_application::set_row (
flags & STRING_FLAG) flags & STRING_FLAG)
{ {
char *xxx = va_arg (params, char *); char *xxx = va_arg (params, char *);
_rows.add (new _FieldTok (_currow, xxx, _rows.add (new _FieldTok (_currow, xxx, flags, align, size, dec));
flags, align, size, dec));
} }
flags = 0x0000; flags = 0x0000;
align = 'l'; align = 'l';
@ -882,8 +876,7 @@ void TPrint_application::set_row (
islong = TRUE; islong = TRUE;
ch = *fmt++; ch = *fmt++;
if (ch == '\0') if (ch == '\0')
fatal_box ("sorry, zer's samzing vruong" fatal_box ("sorry, zer's samzing vruong uitz ioar format.");
" uitz ioar format.");
} }
if (isupper (ch)) if (isupper (ch))
{ {
@ -911,15 +904,13 @@ void TPrint_application::set_row (
case 'o': case 'o':
case 'x': case 'x':
case 'X': case 'X':
q.format (t, islong ? va_arg (params, long) : q.format (t, islong ? va_arg (params, long) : va_arg (params, int));
va_arg (params, int));
break; break;
case 'f': case 'f':
case 'e': case 'e':
case 'E': case 'E':
case 'G': case 'G':
q.format (t, islong ? va_arg (params, double) : q.format (t, islong ? va_arg (params, double) : va_arg (params, float));
va_arg (params, float));
break; break;
case 'c': case 'c':
q.format (t, va_arg (params, char)); q.format (t, va_arg (params, char));
@ -928,17 +919,12 @@ void TPrint_application::set_row (
q.format (t, va_arg (params, char *)); q.format (t, va_arg (params, char *));
break; break;
case 't': // TString case 't': // TString
q.format(t,(const char*)(TString)*((va_arg (params, TString*))));
q.format (t, (const char *)
(TString) * ((va_arg (params, TString *))));
break; break;
case 'a': // TParagraph_string case 'a': // TParagraph_string
q.format(t,(const char*)(TParagraph_string)*((va_arg (params, TParagraph_string*))));
q.format (t, (const char *)
(TParagraph_string) * ((va_arg (params, TParagraph_string *))));
break; break;
case 'r': // Real case 'r': // Real
{ {
const real& rrr = * va_arg (params, real *); const real& rrr = * va_arg (params, real *);
if (t.len () == 2 && *_picture) if (t.len () == 2 && *_picture)
@ -970,8 +956,7 @@ void TPrint_application::set_row (
_rows.add (new _PrintfTok (_currow, q)); _rows.add (new _PrintfTok (_currow, q));
} }
else else
_rows.add (new _PrintfRef (_currow, t, ch, _rows.add (new _PrintfRef (_currow, t, ch, va_arg (params, void *)));
va_arg (params, void *)));
} }
} }
break; break;
@ -989,7 +974,7 @@ void TPrint_application::set_row (
if (strind) if (strind)
{ {
strbuf[strind] = '\0'; strbuf[strind] = '\0';
_rows.add (new _PrintfTok (_currow, strbuf)); _rows.add(new _PrintfTok (_currow, strbuf));
strind = 0; strind = 0;
} }
va_end (params); va_end (params);
@ -1038,16 +1023,13 @@ void TPrint_application::print()
//************************************************ //************************************************
while (nc--) while (nc--)
{ {
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);
@ -1168,12 +1150,12 @@ bool TPrint_application::print_one (
if (_prind && file == _pr_tree->_logicnum) if (_prind && file == _pr_tree->_logicnum)
_prind->addstatus (1); _prind->addstatus (1);
TArray rw (_maxrow + 1); TArray rw(_maxrow + 1);
int *pos = new int[_maxrow + 1]; int *pos = new int[_maxrow + 1];
for (i = 0; i <= _maxrow; i++) for (i = 0; i <= _maxrow; i++)
{ {
rw.add (new TPrintrow ()); rw.add(new TPrintrow());
pos[i] = -1; pos[i] = -1;
} }
@ -1181,16 +1163,20 @@ bool TPrint_application::print_one (
for (i = 0; i <= _maxrow; i++) for (i = 0; i <= _maxrow; i++)
for (int j = 0; j < _rows.items (); j++) for (int j = 0; j < _rows.items (); j++)
{ {
_Token *t = (_Token *) & (_rows[j]); _Token* t = (_Token*)&(_rows[j]);
if (!t) if (!t) continue; // should not happen
continue; // should not happen
if (t->row () == i) if (t->row() == i)
{ {
char pic[36], fn[17]; char pic[36], fn[17];
int ch, ln, from, to; int ch, ln, from, to;
if (t->tag () == 1) if (t->tag() == 3)
{
_PrintRowToken* r = (_PrintRowToken*)t;
rw.add(r->printrow(), r->row());
}
else if (t->tag () == 1)
{ {
// it's a _FieldTok // it's a _FieldTok
_FieldTok *ft = (_FieldTok *) t; _FieldTok *ft = (_FieldTok *) t;
@ -1215,7 +1201,7 @@ bool TPrint_application::print_one (
st = normalstyle; st = normalstyle;
break; break;
} }
((TPrintrow *) (&rw[ft->row ()]))->set_style (st); ((TPrintrow *)(&rw[ft->row()]))->set_style (st);
} }
else if (ft->_flags & JUMP_FLAG) else if (ft->_flags & JUMP_FLAG)
{ {
@ -1230,8 +1216,7 @@ bool TPrint_application::print_one (
else else
// jump ahead // jump ahead
pos[ft->row ()] = pos[ft->row ()] =
((TPrintrow *) (&rw[ft->row ()]))-> ((TPrintrow *) (&rw[ft->row ()]))->lastpos () + p;
lastpos () + p;
} }
else else
{ {
@ -1280,9 +1265,7 @@ bool TPrint_application::print_one (
toprint = d.string (ft->_flags & LONG_FLAG ? full : brief); toprint = d.string (ft->_flags & LONG_FLAG ? full : brief);
if (toprint.empty ()) if (toprint.empty ())
{ {
toprint = (ft->_flags & LONG_FLAG ? toprint = (ft->_flags & LONG_FLAG ? " - - " : " - - ");
" - - " :
" - - ");
} }
} }
else if (ft->_flags & BOOLEAN_FLAG) else if (ft->_flags & BOOLEAN_FLAG)
@ -1298,8 +1281,7 @@ bool TPrint_application::print_one (
if (ft->_flags & PICTURE_FLAG) if (ft->_flags & PICTURE_FLAG)
pict = pic; pict = pic;
else if (!(ft->_flags & DEC_FLAG) && *_picture else if (!(ft->_flags & DEC_FLAG) && *_picture && isreal)
&& isreal)
pict = _picture; pict = _picture;
if (pict.len () > 0) if (pict.len () > 0)
@ -1345,12 +1327,10 @@ bool TPrint_application::print_one (
if (_fillchar != ' ' && !(ft->_flags & IGNORE_FILL)) if (_fillchar != ' ' && !(ft->_flags & IGNORE_FILL))
toprint = fill_str (toprint, _fillchar); toprint = fill_str (toprint, _fillchar);
// add to print row // add to print row
((TPrintrow *) (&rw[ft->row ()]))->put (toprint, ((TPrintrow *)(&rw[ft->row()]))->put (toprint, pos[ft->row ()]);
pos[ft->row ()]); if (pos[ft->row()] != -1)
if (pos[ft->row ()] != -1)
pos[ft->row ()] += toprint.len (); pos[ft->row ()] += toprint.len ();
} }
else if (t->tag () == 0) else if (t->tag () == 0)
{ {
// it's a _PrintfTok // it's a _PrintfTok

View File

@ -296,6 +296,9 @@ public:
// @cmember Permette di settare una riga di stampa // @cmember Permette di settare una riga di stampa
void set_row(int r, const char* fmt, ...); void set_row(int r, const char* fmt, ...);
// @cmember Setta riga di stampa usando una printrow gia' fatta
void set_row(int r, TPrintrow& pr);
// @cmember Setta i valori di traduzione per campi // @cmember Setta i valori di traduzione per campi
void set_translation(int lognum, const char* field, const char* from, const char* to); void set_translation(int lognum, const char* field, const char* from, const char* to);