1999-04-06 15:34:39 +00:00
# define __FORM_CPP
1994-11-10 14:17:03 +00:00
# include <applicat.h>
1999-01-19 09:15:17 +00:00
# include <currency.h>
1999-04-06 15:34:39 +00:00
# include <defmask.h>
# include <expr.h>
1994-11-10 14:17:03 +00:00
# include <form.h>
1994-12-27 14:59:25 +00:00
# include <msksheet.h>
1995-04-20 14:35:14 +00:00
# include <printer.h>
1994-11-10 14:17:03 +00:00
# include <relation.h>
1997-06-16 12:41:59 +00:00
# include <tabutil.h>
1999-04-06 15:34:39 +00:00
# include <utility.h>
1994-11-10 14:17:03 +00:00
1999-04-06 15:34:39 +00:00
# include "../ba/bafrm.h"
1994-11-10 14:17:03 +00:00
1995-05-18 14:18:01 +00:00
///////////////////////////////////////////////////////////
// Utility functions
///////////////////////////////////////////////////////////
1996-01-31 17:19:02 +00:00
1996-02-05 19:00:53 +00:00
// @doc INTERNAL
1996-01-31 17:19:02 +00:00
// @func Funzione che converte dalla notazione carattere al corrispondente
// enum <t pagetype>
//
// @rdesc Ritorna il <t pagetype> corrispondente
pagetype char2page (
char c ) // @parm Notazione carattere del tipo di pagina
1996-02-05 19:00:53 +00:00
1995-05-18 14:18:01 +00:00
{
pagetype pt ;
switch ( c )
{
case ' 1 ' :
case ' E ' :
pt = even_page ; break ;
case ' 2 ' :
case ' F ' :
pt = first_page ; break ;
case ' 3 ' :
case ' L ' :
pt = last_page ; break ;
default :
pt = odd_page ; break ;
}
return pt ;
1994-12-20 15:11:26 +00:00
}
1994-11-10 14:17:03 +00:00
///////////////////////////////////////////////////////////
// TForm_flags
///////////////////////////////////////////////////////////
TForm_flags : : TForm_flags ( )
{
1999-01-19 09:15:17 +00:00
automagic = dirty = finkr = finkl = memo = newpage = price = FALSE ;
1995-12-14 10:45:17 +00:00
shown = enabled = TRUE ;
1994-11-10 14:17:03 +00:00
}
1995-03-22 09:07:04 +00:00
// Read from string
// Certified 100%
1994-11-10 14:17:03 +00:00
bool TForm_flags : : update ( const char * s )
{
1995-03-22 09:07:04 +00:00
CHECK ( s , " NULL flags string " ) ;
1994-11-10 14:17:03 +00:00
for ( ; * s ; s + + ) switch ( toupper ( * s ) )
{
1994-12-15 18:06:43 +00:00
case ' A ' :
automagic = TRUE ; break ;
case ' D ' :
enabled = FALSE ; break ;
case ' H ' :
shown = FALSE ; break ;
1995-12-14 10:45:17 +00:00
case ' F ' :
finkl = TRUE ; break ;
case ' K ' :
finkr = TRUE ; break ;
1995-12-22 15:57:45 +00:00
case ' M ' :
memo = TRUE ; break ;
1997-06-16 12:41:59 +00:00
case ' N ' :
newpage = TRUE ; break ;
1999-01-19 09:15:17 +00:00
case ' U ' :
price = TRUE ; break ;
1995-12-14 10:45:17 +00:00
default :
1994-12-15 18:06:43 +00:00
error_box ( " Unknown form item flag '%c' " , * s ) ; break ;
}
1994-11-10 14:17:03 +00:00
return TRUE ;
}
1994-12-20 15:11:26 +00:00
1995-03-22 09:07:04 +00:00
// Print on stream
// Certified 100%
1994-11-10 14:17:03 +00:00
void TForm_flags : : print_on ( ostream & out ) const
{
1994-12-07 18:03:51 +00:00
TString16 s ;
1994-11-10 14:17:03 +00:00
if ( automagic ) s < < " A " ;
1994-12-15 18:06:43 +00:00
if ( ! enabled ) s < < " D " ;
if ( ! shown ) s < < " H " ;
1996-02-03 10:52:05 +00:00
if ( memo ) s < < " M " ;
1997-06-16 12:41:59 +00:00
if ( newpage ) s < < " N " ;
1995-12-14 10:45:17 +00:00
if ( finkl ) s < < " F " ;
if ( finkr ) s < < " K " ;
1999-01-19 09:15:17 +00:00
if ( price ) s < < " U " ;
1994-11-10 14:17:03 +00:00
1994-12-27 14:59:25 +00:00
if ( s . not_empty ( ) )
out < < " FLAGS \" " < < s < < ' " ' < < endl ;
1994-11-10 14:17:03 +00:00
}
///////////////////////////////////////////////////////////
// TForm_item
///////////////////////////////////////////////////////////
TForm_item : : TForm_item ( TPrint_section * section )
1998-08-25 18:07:30 +00:00
: _section ( section ) , _x ( - 1 ) , _y ( - 1 ) , _width ( 0 ) ,
_height ( 0 ) , _effective_height ( 0 ) , _id ( 0 ) , _ofs ( 0 ) ,
1997-06-16 12:52:23 +00:00
_temp ( FALSE )
1994-11-10 14:17:03 +00:00
{ }
1996-05-20 13:07:32 +00:00
void TForm_item : : copy_to_form_item ( TForm_item * fi ) const
1996-04-17 16:43:58 +00:00
{
1997-06-16 12:52:23 +00:00
fi - > _flag = _flag ; fi - > _group = _group ;
1999-04-06 15:34:39 +00:00
/* come copiarlo facendo una cosa orrenda...
1997-06-16 12:52:23 +00:00
fi - > _special . destroy ( ) ;
specials ( ) . restart ( ) ;
int items = special_items ( ) ;
for ( int k = 0 ; k < items ; k + + )
{
THash_object * ho = specials ( ) . get_hashobj ( ) ;
fi - > _special . add ( ho - > key ( ) , ho - > obj ( ) ) ;
}
1999-04-06 15:34:39 +00:00
*/
fi - > _special = _special ; // sarebbe utile avere un "operator =" per i TAssoc_array
1997-06-16 12:52:23 +00:00
fi - > _temp = _temp ; fi - > _id = _id ;
fi - > _x = _x ; fi - > _y = _y ;
fi - > _width = _width ; fi - > _height = _height ;
fi - > _effective_height = _effective_height ;
fi - > _ofs = _ofs ; fi - > _prompt = _prompt ;
fi - > _desc = _desc ; fi - > _col_head = _col_head ;
1999-04-06 15:34:39 +00:00
/* Anche qui... copia uno alla volta
1997-06-16 12:52:23 +00:00
items = _message . items ( ) ;
for ( k = 0 ; k < items ; k + + )
fi - > _message . add ( _message . row ( k ) , k ) ;
1999-04-06 15:34:39 +00:00
*/
fi - > _message = _message ; // sarebbe utile avere un "operator =" per i TString_array
1996-04-17 16:43:58 +00:00
}
TObject * TForm_item : : dup ( ) const
{
1997-06-16 12:52:23 +00:00
TForm_item * fi = new TForm_item ( _section ) ;
copy_to_form_item ( fi ) ;
return fi ;
1996-04-17 16:43:58 +00:00
}
1994-11-10 14:17:03 +00:00
bool TForm_item : : parse_head ( TScanner & scanner )
1997-06-16 12:41:59 +00:00
{
1997-06-16 12:52:23 +00:00
_id = scanner . integer ( ) ;
1997-06-16 12:41:59 +00:00
1997-06-16 12:52:23 +00:00
if ( _id = = 0 ) // Temporary
_id = _section - > fields ( ) + 1 ;
1997-06-16 12:41:59 +00:00
1997-06-16 12:52:23 +00:00
_width = scanner . integer ( ) ;
if ( _width > 0 )
_height = scanner . integer ( ) ;
return TRUE ;
1994-11-10 14:17:03 +00:00
}
1994-12-20 15:11:26 +00:00
1994-11-10 14:17:03 +00:00
void TForm_item : : print_on ( ostream & out ) const
{
1997-06-16 12:52:23 +00:00
out < < class_name ( ) < < ' ' < < id ( ) ;
if ( _width > 0 )
{
out < < ' ' < < _width ;
if ( _height > 0 )
out < < ' ' < < _height ;
}
out < < " \n BEGIN \n " ;
1994-11-10 14:17:03 +00:00
1997-06-16 12:52:23 +00:00
print_body ( out ) ;
1994-11-10 14:17:03 +00:00
1997-06-16 12:52:23 +00:00
out < < " END \n " < < endl ;
1994-11-10 14:17:03 +00:00
}
1994-12-20 15:11:26 +00:00
1994-11-10 14:17:03 +00:00
void TForm_item : : print_body ( ostream & out ) const
{
1997-06-16 12:52:23 +00:00
out < < " KEY \" " < < _desc < < " \" \n " ;
1995-01-02 09:33:00 +00:00
1997-06-16 12:52:23 +00:00
if ( _y > = 0 )
out < < " PROMPT " < < _x < < ' ' < < _y < < " \" " < < _prompt < < " \" \n " ;
1994-11-10 14:17:03 +00:00
1997-06-16 12:52:23 +00:00
if ( _group . ones ( ) )
out < < " GROUP " < < _group < < " \n " ;
1994-11-10 14:17:03 +00:00
1997-06-16 12:52:23 +00:00
out < < _flag ;
1994-11-10 14:17:03 +00:00
1997-06-16 12:52:23 +00:00
if ( _message . items ( ) = = 1 )
{
const TToken_string & m = _message . row ( 0 ) ;
if ( ! m . empty_items ( ) )
out < < " MESSAGE " < < m < < endl ;
}
1994-12-20 15:11:26 +00:00
1997-06-16 12:52:23 +00:00
if ( _special . items ( ) > 0 )
{
TAssoc_array & aa = specials ( ) ;
aa . restart ( ) ;
1994-11-10 14:17:03 +00:00
1997-06-16 12:52:23 +00:00
THash_object * op ;
1999-01-19 09:15:17 +00:00
1997-06-16 12:52:23 +00:00
while ( ( op = aa . get_hashobj ( ) ) ! = NULL )
{
TToken_string & t = ( TToken_string & ) op - > obj ( ) ;
1999-01-19 09:15:17 +00:00
TString typ ( t . get ( 0 ) ) ;
TString val ( t . get ( 1 ) ) ;
TString des ( t . get ( 2 ) ) ;
1997-06-16 12:52:23 +00:00
out < < " SPECIAL " < < typ < < " " < < op - > key ( )
< < " \" " < < val < < " \" \" " < < des < < " \" \n " ;
}
}
1997-06-16 12:41:59 +00:00
}
1994-11-10 14:17:03 +00:00
1997-06-16 12:41:59 +00:00
bool TForm_item : : parse_item ( TScanner & scanner )
{
1997-06-16 12:52:23 +00:00
if ( scanner . key ( ) = = " PR " )
{
_x = scanner . integer ( ) ;
_y = scanner . integer ( ) ;
_prompt = scanner . string ( ) ;
return TRUE ;
}
if ( scanner . key ( ) = = " FL " )
return _flag . update ( scanner . string ( ) ) ;
if ( scanner . key ( ) = = " ME " )
{
TFixed_string m ( scanner . line ( ) ) ;
m . strip_spaces ( ) ;
int n = 0 ;
if ( m . left ( 5 ) = = " EMPTY " )
{
n = 1 ;
m . ltrim ( 5 ) ;
}
if ( ! m . blank ( ) )
message ( n ) . add ( m ) ;
return TRUE ;
}
if ( scanner . key ( ) = = " KE " )
{
_desc = scanner . string ( ) ;
return TRUE ;
}
if ( scanner . key ( ) = = " GR " )
{
_group . set ( scanner . line ( ) ) ;
return TRUE ;
}
if ( scanner . key ( ) = = " SP " )
{
TToken_string val ( scanner . pop ( ) ) ;
TString16 var = scanner . pop ( ) ;
val . add ( scanner . string ( ) ) ;
val . add ( scanner . string ( ) ) ;
_special . add ( var , val ) ;
return TRUE ;
}
yesnofatal_box ( " Unknown symbol in item '%s': '%s' " ,
( const char * ) key ( ) , ( const char * ) scanner . token ( ) ) ;
return FALSE ;
1994-11-10 14:17:03 +00:00
}
bool TForm_item : : parse ( TScanner & scanner )
{
1997-06-16 12:52:23 +00:00
bool ok = parse_head ( scanner ) ;
1994-11-10 14:17:03 +00:00
1997-06-16 12:52:23 +00:00
if ( ok & & scanner . popkey ( ) ! = " BE " )
ok = yesnofatal_box ( " Missing BEGIN in form item %s " , ( const char * ) key ( ) ) ;
1994-11-10 14:17:03 +00:00
1997-06-16 12:52:23 +00:00
while ( ok & & scanner . popkey ( ) ! = " EN " )
ok = parse_item ( scanner ) ;
1994-11-10 14:17:03 +00:00
1997-06-16 12:52:23 +00:00
return ok ;
1994-11-10 14:17:03 +00:00
}
1995-05-29 10:25:10 +00:00
bool TForm_item : : read_from ( const TRectype & prof )
{
1997-06-16 12:52:23 +00:00
CHECK ( prof . num ( ) = = LF_RFORM , " Il record deve essere del file LF_RFORM " ) ;
bool changed = FALSE ;
int i = prof . get_int ( " X " ) ;
if ( _x ! = i )
{
_x = i ;
changed = TRUE ;
}
i = prof . get_int ( " Y " ) ;
if ( _y ! = i )
{
_y = i ;
changed = TRUE ;
}
i = prof . get_int ( " LEN " ) ;
if ( _width ! = i )
{
_width = i ;
changed = TRUE ;
}
i = prof . get_int ( " HGT " ) ;
if ( _height ! = i )
{
_height = i ;
changed = TRUE ;
}
TString p ( prof . get ( " PROMPT " ) ) ;
if ( p . not_empty ( ) )
{
if ( p [ 0 ] = = ' \xFE ' ) p . cut ( 0 ) ;
const int l = p . len ( ) ;
if ( l > 0 & & p [ l - 1 ] = = ' \xFF ' )
{
p [ l - 1 ] = ' ' ;
p < < ' \0 ' ;
}
_prompt = p ;
changed = TRUE ;
}
const bool s = prof . get_bool ( " ATTIVO " ) ;
if ( _flag . shown ! = s )
{
_flag . shown = s ;
changed = TRUE ;
}
TToken_string special ( prof . get ( " SPECIAL " ) , ' \n ' ) ;
special . rtrim ( ) ;
const int sp_items = special . items ( ) ;
for ( i = 0 ; i < sp_items ; i + + )
{
TToken_string sp ( special . get ( i ) , ' $ ' ) ;
TString key ( sp . get ( 0 ) ) ;
TString val ( sp . get ( 1 ) ) ;
if ( ! _special . is_key ( key ) )
{
error_box ( " Variabile speciale non presente nel profilo: %s " ,
( const char * ) key ) ;
continue ;
}
TToken_string & tt = ( TToken_string & ) _special [ key ] ;
tt . add ( val , 1 ) ;
// forza riscrittura su memo
if ( tt . items ( ) = = 3 ) tt . add ( " X " ) ;
}
return TRUE ;
1995-05-29 10:25:10 +00:00
}
void TForm_item : : print_on ( TRectype & prof )
{
1997-06-16 12:52:23 +00:00
CHECK ( prof . num ( ) = = LF_RFORM , " Il record deve essere del file LF_RFORM " ) ;
prof . put ( " ID " , id ( ) ) ;
prof . put ( " X " , _x ) ;
prof . put ( " Y " , _y ) ;
prof . put ( " LEN " , width ( ) ) ;
prof . put ( " HGT " , height ( ) ) ;
if ( _prompt . empty ( ) ) _prompt < < ' \xFE ' < < ' \0 ' ;
const int l = _prompt . len ( ) ;
const char c = _prompt [ l - 1 ] ;
if ( c = = ' ' ) _prompt [ l - 1 ] = ' \xFF ' ;
prof . put ( " PROMPT " , _prompt ) ;
prof . put ( " ATTIVO " , shown ( ) ? " X " : " " ) ;
// specials: se e' stato cambiato, la tokenstring del valore contiene
// una X alla fine (campo 3)
{
TToken_string special ( 128 , ' \n ' ) ;
_special . restart ( ) ;
for ( int i = 0 ; i < _special . items ( ) ; i + + )
{
THash_object * o = _special . get_hashobj ( ) ;
TString key ( o - > key ( ) ) ;
TToken_string & tt = ( TToken_string & ) o - > obj ( ) ;
if ( tt . items ( ) = = 4 )
{
TToken_string sp ( key , ' $ ' ) ;
TString val ( tt . get ( 1 ) ) ;
sp . add ( val ) ;
special . add ( sp ) ;
}
}
special . rtrim ( ) ;
prof . put ( " SPECIAL " , special ) ;
}
1995-05-29 10:25:10 +00:00
}
1996-02-05 19:00:53 +00:00
// @doc EXTERNAL
1996-01-31 17:19:02 +00:00
// @mfunc Abilita/Disabilita il campo
void TForm_item : : enable (
1997-06-16 12:52:23 +00:00
bool on ) // @parm Operazione da svolgere sul campo:
// @flag TRUE | Il campo viene abiliato
// @flag FALSE | Il campo viene disabiliato
1996-01-31 17:19:02 +00:00
1996-07-24 08:43:02 +00:00
// @comm Viene automaticamente setta se il campo diventi visibile o nascosto (chiama <mf TForm_item::show>)
1994-11-10 14:17:03 +00:00
{
1997-06-16 12:52:23 +00:00
_flag . enabled = on ;
show ( on ) ;
1994-11-10 14:17:03 +00:00
}
1996-02-03 10:52:05 +00:00
void TForm_item : : set_special_value ( const char * s , const char * val )
{
1997-06-16 12:52:23 +00:00
TToken_string & tt = ( TToken_string & ) _special [ s ] ;
tt . add ( val , 1 ) ;
if ( tt . items ( ) = = 3 ) tt . add ( " X " ) ;
1996-02-03 10:52:05 +00:00
}
const char * TForm_item : : get_special_item ( const char * s , int n ) const
{
1997-06-16 12:52:23 +00:00
TAssoc_array & sp = ( TAssoc_array & ) _special ;
if ( sp . is_key ( s ) )
{
TToken_string & tt = ( TToken_string & ) sp [ s ] ;
return tt . get ( n ) ;
} else return " " ;
1996-02-03 10:52:05 +00:00
}
1994-11-10 14:17:03 +00:00
void TForm_item : : string_at ( int x , int y , const char * s )
{
1997-06-16 12:52:23 +00:00
if ( shown ( ) )
{
if ( section ( ) . columnwise ( ) ) x + = _ofs ;
TPrintrow & row = section ( ) . row ( y - 1 ) ; // Seleziona riga di stampa
1995-05-29 10:25:10 +00:00
1997-06-16 12:52:23 +00:00
if ( _width > 0 & & strlen ( s ) > ( word ) _width ) // Tronca testo se necessario
{
2003-03-27 12:14:51 +00:00
TString & tmp = get_tmp_string ( ) ;
tmp . strncpy ( s , _width ) ;
s = tmp ;
1997-06-16 12:52:23 +00:00
}
1999-01-19 09:15:17 +00:00
row . put ( s , x - 1 ) ; // Stampa testo
1997-06-16 12:52:23 +00:00
}
1994-11-10 14:17:03 +00:00
}
TToken_string & TForm_item : : message ( int m )
{
1997-06-16 12:52:23 +00:00
TToken_string * t = ( TToken_string * ) _message . objptr ( m ) ;
if ( t = = NULL )
{
t = new TToken_string ( 16 ) ;
_message . add ( t , m ) ;
}
return * t ;
1994-11-10 14:17:03 +00:00
}
1996-02-05 19:00:53 +00:00
// @doc EXTERNAL
1997-06-16 12:41:59 +00:00
1996-01-31 17:19:02 +00:00
// @mfunc Manda il messaggio al campo <p dest>
void TForm_item : : send_message (
1997-06-16 12:52:23 +00:00
const TString & cmd , // @parm Messaggio di comando
TForm_item & des ) const // @parm Campo a cui destinare il messaggio
{
if ( cmd = = " ADD " | | cmd = = " INC " )
{
if ( form ( ) . message_add_enabled ( ) )
{
const real n ( ( cmd [ 0 ] = = ' I ' ) ? " 1.0 " : get ( ) ) ;
real r ( des . get ( ) ) ;
r + = n ;
des . set ( r . string ( ) ) ;
}
} else if ( cmd = = " COPY " ) {
des . set ( get ( ) ) ;
} else if ( cmd = = " APPEND " ) {
TString256 val = des . get ( ) ;
if ( val . not_empty ( ) ) val < < ' ' ;
val < < get ( ) ;
des . set ( val ) ;
1998-05-27 13:41:48 +00:00
} else if ( cmd = = " RESET " ) {
des . set ( " " ) ;
1997-09-19 08:47:46 +00:00
} else if ( cmd = = " DISABLE " ) {
1997-06-16 12:52:23 +00:00
des . disable ( ) ;
} else if ( cmd = = " ENABLE " ) {
des . enable ( ) ;
} else if ( cmd = = " HIDE " ) {
des . hide ( ) ;
} else if ( cmd = = " SHOW " ) {
des . show ( ) ;
1997-09-19 08:47:46 +00:00
} else if ( cmd = = " SUB " ) {
const real n ( get ( ) ) ;
real r ( des . get ( ) ) ;
r - = n ;
des . set ( r . string ( ) ) ;
1997-06-16 12:52:23 +00:00
} else if ( cmd [ 0 ] = = ' " ' ) {
TString256 val ( cmd ) ;
val . strip ( " \" " ) ;
des . set ( val ) ;
} else
error_box ( " Unknown message in item '%s': '%s' " ,
( const char * ) key ( ) , ( const char * ) cmd ) ;
1994-11-10 14:17:03 +00:00
}
1995-07-19 09:57:25 +00:00
TForm_item & TForm_item : : find_field ( const TString & id ) const
{
1997-06-16 12:52:23 +00:00
if ( isdigit ( id [ 0 ] ) ) // Field in the same section
{
TForm_item & des = section ( ) . find_field ( atoi ( id ) ) ;
return des ;
}
const int freccia = id . find ( " -> " ) ;
const pagetype pt = ( freccia = = 2 ) ? char2page ( id [ 1 ] ) : section ( ) . page_type ( ) ;
char se ;
int id_num ;
int pos_id ;
1998-05-27 13:41:48 +00:00
if ( freccia > = 0 )
1997-06-16 12:52:23 +00:00
{
pos_id = freccia + 2 ;
id_num = atoi ( id . mid ( pos_id ) ) ;
se = id [ 0 ] ;
} else {
id_num = 0 ;
se = section ( ) . section_type ( ) ;
pos_id = 0 ;
}
if ( id_num ) // id numerico: campo semplice
{
TForm_item & des = form ( ) . find_field ( se , pt , id_num ) ;
return des ;
} else { // id stringa : campo sezione
TForm_item & des = form ( ) . find_field ( se , pt , id . mid ( pos_id ) ) ;
return des ;
}
1997-06-16 12:41:59 +00:00
}
// il parametro num serve per identificare il messaggio nelle listbox...
1994-11-10 14:17:03 +00:00
bool TForm_item : : do_message ( int num )
{
1997-06-16 12:52:23 +00:00
TToken_string & messaggio = message ( num ) ;
2002-12-20 16:15:03 +00:00
if ( messaggio . empty_items ( ) )
return FALSE ;
1999-01-19 09:15:17 +00:00
TToken_string msg ( 16 , ' , ' ) ;
1997-06-16 12:52:23 +00:00
for ( const char * m = messaggio . get ( 0 ) ; m ; m = messaggio . get ( ) )
{
msg = m ;
if ( * m = = ' _ ' )
form ( ) . validate ( * this , msg ) ;
else
{
const TString80 cmd ( msg . get ( ) ) ; // Get command
const TString80 id = msg . get ( ) ; // Get destination
if ( id . right ( 1 ) = = " @ " )
{
const byte group = atoi ( id ) ;
// Send the message to all fields in local and upper sections with the given group
send_message_to_group ( cmd , group , section ( ) , & section ( ) ) ;
}
1998-05-27 13:41:48 +00:00
else
1997-06-16 12:52:23 +00:00
{
TForm_item & des = find_field ( id ) ;
send_message ( cmd , des ) ;
}
}
}
return TRUE ;
1997-06-16 12:41:59 +00:00
}
void TForm_item : : send_message_to_group ( const char * cmd , byte id , const TPrint_section & section , const TPrint_section * starting_section )
{
1997-06-16 12:52:23 +00:00
TForm_item * f ;
// look into local section
for ( word i = 0 ; i < section . fields ( ) ; i + + )
{
f = & section . field ( i ) ;
if ( f - > in_group ( id ) )
send_message ( cmd , * f ) ;
}
// look into the section above ("father" )
if ( section . section_above ( ) & & section . section_above ( ) ! = starting_section ) {
send_message_to_group ( cmd , id , * section . section_above ( ) , & section ) ;
}
// look into sections beside ("brothers" )
for ( int j = 0 ; j < section . subsections ( ) ; j + + ) {
1998-04-30 15:31:34 +00:00
const TPrint_section & bs = section . subsection ( j ) - > printsection ( ) ;
1997-06-16 12:52:23 +00:00
if ( & bs ! = starting_section ) {
1998-04-30 15:31:34 +00:00
send_message_to_group ( cmd , id , section . subsection ( j ) - > printsection ( ) , & section ) ;
1997-06-16 12:52:23 +00:00
}
}
1994-11-10 14:17:03 +00:00
}
bool TForm_item : : update ( )
2000-10-03 13:45:12 +00:00
{
1997-06-16 12:52:23 +00:00
if ( _prompt . right ( 1 ) = = " # " )
{
1999-04-06 16:31:40 +00:00
TString prompt ( _prompt ) ;
1997-06-16 12:52:23 +00:00
for ( int i = prompt . len ( ) - 2 ; i > = 0 ; i - - )
if ( prompt [ i ] ! = ' # ' ) break ;
prompt . cut ( i + 1 ) ;
string_at ( x ( ) , _y , prompt ) ;
}
else string_at ( x ( ) , _y , _prompt ) ;
1997-06-16 12:41:59 +00:00
1997-06-16 12:52:23 +00:00
return TRUE ;
1994-11-10 14:17:03 +00:00
}
1995-12-14 10:45:17 +00:00
void TForm_item : : print_on ( TToken_string & row ) const
1997-06-16 12:41:59 +00:00
{
1997-06-16 12:52:23 +00:00
row . cut ( 0 ) ;
row . add ( id ( ) ) ;
row . add ( key ( ) ) ;
row . add ( _y ) ;
row . add ( _x ) ;
row . add ( shown ( ) ? " " : " X " ) ;
1997-06-16 12:41:59 +00:00
1997-06-16 12:52:23 +00:00
if ( form ( ) . edit_level ( ) > 1 )
{
const long fu = _group . first_one ( ) ;
if ( fu > 0 ) row . add ( fu ) ;
else row . add ( " " ) ;
}
1997-06-16 12:41:59 +00:00
}
1995-12-14 10:45:17 +00:00
1997-06-16 12:41:59 +00:00
const TString & TForm_item : : picture ( ) const
{
1999-04-16 12:02:04 +00:00
NFCHECK ( " Can't get the picture of a generic form item! " ) ;
return EMPTY_STRING ;
1995-12-11 17:36:57 +00:00
}
void TForm_item : : set_picture ( const char * )
1997-06-16 12:41:59 +00:00
{
1999-04-16 12:02:04 +00:00
NFCHECK ( " Can't set the picture of a generic form item! " ) ;
1995-12-11 17:36:57 +00:00
}
1996-01-09 10:37:29 +00:00
TToken_string & TForm_item : : memo_info ( )
{
1999-04-16 12:02:04 +00:00
NFCHECK ( " Can't get a memo of a generic form item! " ) ;
1999-04-07 14:41:07 +00:00
return ( TToken_string & ) EMPTY_STRING ;
1996-01-09 10:37:29 +00:00
}
1996-01-05 18:39:12 +00:00
short TForm_item : : x ( )
1995-12-14 10:45:17 +00:00
{
1997-06-16 12:52:23 +00:00
if ( _section = = NULL | | ! _section - > columnwise ( ) )
return _x ;
return _section - > tab ( _x - 1 ) + _section - > ofspc ( ) ;
1995-12-14 10:45:17 +00:00
}
1995-12-11 17:36:57 +00:00
1997-06-16 12:41:59 +00:00
1995-05-09 09:12:26 +00:00
///////////////////////////////////////////////////////////
// TForm_subsection
///////////////////////////////////////////////////////////
1997-07-30 12:36:24 +00:00
TForm_subsection : : TForm_subsection ( TPrint_section * s , const char * nm )
: TForm_item ( s ) , _ssec ( & ( s - > form ( ) ) , s - > section_type ( ) , s - > page_type ( ) ) ,
1998-04-30 15:31:34 +00:00
_file_id ( - 1 ) , _name ( nm ) , _condexpr ( NULL ) ,
_title_section ( NULL ) , _qtitle_section ( NULL ) , _title_type ( type_notitle ) , _show_title ( FALSE )
1997-07-30 12:36:24 +00:00
{
_ssec . set_subsection_above ( this ) ;
}
1995-05-09 09:12:26 +00:00
1997-06-16 12:41:59 +00:00
TForm_subsection : : ~ TForm_subsection ( )
{
1997-06-16 12:52:23 +00:00
if ( _condexpr ) delete _condexpr ;
1998-04-30 15:31:34 +00:00
// _title_section e _qtitle_section sono puntatori a subsection contenute nel corpo, quindi non vanno deallocati
1997-06-16 12:41:59 +00:00
}
1995-05-09 09:12:26 +00:00
1997-06-16 12:41:59 +00:00
TObject * TForm_subsection : : dup ( ) const
{
1997-06-16 12:52:23 +00:00
TForm_subsection * fs = new TForm_subsection ( _section ) ;
copy_to_form_item ( fs ) ;
fs - > _ssec = _ssec ;
fs - > _name = _name ;
fs - > _file_id = _file_id ;
1998-04-30 15:31:34 +00:00
fs - > _title_type = _title_type ;
fs - > _show_title = _show_title ;
if ( _condexpr )
fs - > _condexpr = new TExpression ( ( const char * ) _condexpr ) ;
else
fs - > _condexpr = NULL ;
if ( _title_section )
fs - > _title_section = ( TForm_subsection * ) _title_section - > dup ( ) ;
else
fs - > _title_section = NULL ;
if ( _qtitle_section )
fs - > _qtitle_section = ( TForm_subsection * ) _qtitle_section - > dup ( ) ;
else
fs - > _qtitle_section = NULL ;
1997-06-16 12:52:23 +00:00
return fs ;
1997-06-16 12:41:59 +00:00
}
1995-05-09 09:12:26 +00:00
1997-06-16 12:41:59 +00:00
int TForm_subsection : : fileid ( )
{
1997-06-16 12:52:23 +00:00
return _file_id ;
1997-06-16 12:41:59 +00:00
}
// restituisce la condizione della sottosezione
const char * TForm_subsection : : condition ( )
{
1997-06-16 12:52:23 +00:00
if ( _condexpr )
return ( const char * ) _condexpr - > string ( ) ;
else
return NULL ;
1997-06-16 12:41:59 +00:00
}
1995-05-09 09:12:26 +00:00
1997-06-16 12:41:59 +00:00
// imposta la condizione della sottosezione
2000-05-05 15:25:49 +00:00
void TForm_subsection : : setcondition ( const char * cond , TTypeexp type )
1997-06-16 12:41:59 +00:00
{
2000-05-05 15:25:49 +00:00
if ( _condexpr )
{
if ( _file_id ! = - 1 )
1998-04-30 15:31:34 +00:00
printsection ( ) . set_subs_cond ( _file_id , cond , _condexpr - > string ( ) ) ;
1997-06-16 12:52:23 +00:00
delete _condexpr ;
}
_condexpr = new TExpression ( cond , type ) ;
1997-06-16 12:41:59 +00:00
}
1995-05-09 09:12:26 +00:00
1998-04-30 15:31:34 +00:00
// imposta la sottosezione titolo
void TForm_subsection : : set_title_section ( TForm_subsection * s )
{
if ( _title_section ) delete _title_section ;
_title_section = s ;
}
// imposta la sottosezione titolo di coda
void TForm_subsection : : set_qtitle_section ( TForm_subsection * s )
{
if ( _qtitle_section ) delete _qtitle_section ;
_qtitle_section = s ;
}
void TPrint_section : : print_title ( )
{
TPrinter & pr = printer ( ) ;
if ( pr . current_row ( ) > pr . headersize ( ) + 1 )
if ( word ( height ( ) ) > pr . rows_left ( ) )
pr . formfeed ( ) ;
word last_printed_row = 0 ;
const word maxs = ( word ) subsections ( ) ;
for ( word s = 0 ; s < ( word ) maxs ; s + + )
{
TForm_subsection & ssec = * subsection ( s ) ;
for ( ; last_printed_row < ( word ) ssec . y ( ) - 1 ; last_printed_row + + )
pr . print ( titlerow ( last_printed_row ) ) ;
if ( ssec . shown ( ) )
ssec . printsection ( ) . print_title ( ) ;
}
for ( ; last_printed_row < ( word ) height ( ) ; last_printed_row + + )
pr . print ( titlerow ( last_printed_row ) ) ;
}
1997-06-16 12:41:59 +00:00
void TPrint_section : : set_subs_cond ( int file , const char * newcond , const char * oldcond )
1996-04-17 16:43:58 +00:00
{
1997-06-16 12:52:23 +00:00
TForm_subsection * s ;
s = ( TForm_subsection * ) ( _subsections . first_item ( ) ) ;
while ( s ) {
TString newsubcond ( s - > condition ( ) ) ;
if ( file ! = - 1 & & s - > fileid ( ) = = file & & newsubcond . not_empty ( ) ) {
// there's another file group subsection below....
newsubcond = newsubcond . mid ( strlen ( oldcond ) ) ;
newsubcond . insert ( newcond ) ;
s - > setcondition ( newsubcond , _strexpr ) ;
}
s = ( TForm_subsection * ) ( _subsections . succ_item ( ) ) ;
}
1997-06-16 12:41:59 +00:00
}
// ritorna l'indirizzo della prima sottosezione condizionale di livello superiore alla corrente
TForm_subsection * TForm_subsection : : upper_conditional ( ) const
{
1997-06-16 12:52:23 +00:00
if ( section ( ) . subsection_above ( ) )
{
if ( section ( ) . subsection_above ( ) - > _condexpr & & section ( ) . subsection_above ( ) - > _file_id > 0 )
return section ( ) . subsection_above ( ) ;
else
return section ( ) . subsection_above ( ) - > upper_conditional ( ) ;
} else
return NULL ;
1996-04-17 16:43:58 +00:00
}
1995-05-09 09:12:26 +00:00
1998-04-30 15:31:34 +00:00
// Esegue una post visita dell'albero delle subsection, stampando tutte le section "Titolo"
bool TForm_subsection : : print_titles ( )
{
if ( section ( ) . subsection_above ( ) )
section ( ) . subsection_above ( ) - > print_titles ( ) ;
bool ok = TRUE ;
// print the title
if ( _title_section ! = NULL & & _title_section - > _show_title )
{
if ( shown ( ) & & _title_section - > shown ( ) )
{
_title_section - > printsection ( ) . print_title ( ) ;
}
_title_section - > show_title ( FALSE ) ;
}
return ok ;
}
bool TForm_subsection : : print_qtitle ( )
{
bool ok = TRUE ;
// print the title
if ( _qtitle_section ! = NULL )
{
if ( shown ( ) & & _qtitle_section - > shown ( ) )
{
print_titles ( ) ;
_qtitle_section - > printsection ( ) . print_title ( ) ;
}
}
return ok ;
}
1997-06-16 12:41:59 +00:00
1995-06-07 10:47:05 +00:00
bool TForm_subsection : : parse ( TScanner & s )
1997-06-16 12:41:59 +00:00
{
1997-06-16 12:52:23 +00:00
_section - > add_subsection ( this ) ;
name ( s . pop ( ) ) ;
//_width = s.integer(); // ...unused
//_x = s.integer(); // ...unused
_y = s . integer ( ) ; // posizione rispetto ai campi della sezione "padre"
_height = s . integer ( ) ; // minima altezza (primo "header")
_ssec . parse_head ( s ) ;
s . popkey ( ) ;
if ( s . key ( ) = = " FI " ) // FI_LE su cui iterare con next_match
{
_file_id = name2log ( s . pop ( ) ) ;
if ( s . popkey ( ) = = " GR " | | s . key ( ) = = " BY " )
{
// GR_OUP or BY group : gestione dei raggruppamenti o big skip
TString e ;
TForm_subsection * uppersec = upper_conditional ( ) ;
2000-05-05 15:25:49 +00:00
e = s . line ( ) ;
1997-06-16 12:52:23 +00:00
if ( uppersec & & uppersec - > _file_id = = _file_id )
2000-05-05 15:25:49 +00:00
{
1997-06-16 12:52:23 +00:00
// se anche la sezione soprastante
2000-05-05 15:25:49 +00:00
const TString & eu = uppersec - > _condexpr - > string ( ) ;
if ( e ! = eu )
{
e . insert ( " + " ) ;
if ( e ! = eu . right ( e . len ( ) ) )
e . insert ( eu ) ; // Aggiungo espressione precedente
else
e = eu ; // Inutile aggiungere espressione gi<67> presente
}
}
1997-06-16 12:52:23 +00:00
_condexpr = new TExpression ( e , _strexpr ) ;
_bigskip = s . key ( ) = = " BY " ;
} else
s . push ( ) ;
} else {
if ( s . key ( ) = = " NU " ) // NU_MERIC CONDITION di gestione della sezione
_condexpr = new TExpression ( s . line ( ) , _numexpr ) ; //
else if ( s . key ( ) = = " ST " ) // ST_RING CONDITION di gestione della sezione
_condexpr = new TExpression ( s . line ( ) , _strexpr ) ; //
1998-04-30 15:31:34 +00:00
else if ( s . key ( ) = = " HE " ) // sottosezione HE_ADER (titolo), stampa solo se altr sotto sez verranno stampati
{
_title_type = type_title ;
if ( section ( ) . subsection_above ( ) )
section ( ) . subsection_above ( ) - > set_title_section ( this ) ;
}
else if ( s . key ( ) = = " FO " ) // sottosezione FO_OOTER (titolo di coda), stampato solo se altr sotto sez verranno stampati
{
_title_type = type_qtitle ;
if ( section ( ) . subsection_above ( ) )
section ( ) . subsection_above ( ) - > set_qtitle_section ( this ) ;
}
1997-06-16 12:52:23 +00:00
else if ( s . key ( ) ! = " GR " ) // GR_OUP section (raggruppamento puro)
s . push ( ) ;
1997-06-16 12:41:59 +00:00
}
1997-06-16 12:52:23 +00:00
if ( s . popkey ( ) = = " FL " )
_flag . update ( s . string ( ) ) ;
else s . push ( ) ;
return ( _ssec . parse_body ( s ) ) ;
1995-06-07 10:47:05 +00:00
}
1997-06-16 12:41:59 +00:00
// nel caso di subsection viene chiamata la set_body anzich<63> la update
1995-06-07 10:47:05 +00:00
bool TForm_subsection : : update ( )
1998-04-30 15:31:34 +00:00
{
return TRUE ;
}
1997-06-16 12:41:59 +00:00
1998-04-30 15:31:34 +00:00
bool TForm_subsection : : print_body ( sec_print_mode showfields )
1997-06-16 12:41:59 +00:00
{
2000-05-05 15:25:49 +00:00
bool at_newpage = ( atnewpage ( ) | | printer ( ) . rows_left ( ) < ( word ) minheight ( ) ) ;
1997-06-16 12:52:23 +00:00
bool ok = FALSE ;
TCursor * cur = form ( ) . cursor ( ) ;
TRelation * rel = ( TRelation * ) form ( ) . relation ( ) ;
1998-08-25 18:07:30 +00:00
set_effective_height ( 0 ) ; // resetta l'altezza della sottosezione al suo "minimo"
1998-04-30 15:31:34 +00:00
if ( ! enabled ( ) )
return FALSE ;
if ( is_title ( ) )
{
show_title ( TRUE ) ;
showfields = printmode_title ; // calcola e bufferizza ora, rimanda la stampa dopo ...
}
if ( ! shown ( ) )
showfields = printmode_noprint ;
1997-06-16 12:52:23 +00:00
if ( cur = = NULL | | ( _file_id = = - 1 & & _condexpr = = NULL ) ) // ...unused
1998-05-27 13:41:48 +00:00
ok = _ssec . update_and_print ( showfields , at_newpage ) ;
1997-06-16 12:52:23 +00:00
else if ( _file_id = = - 1 & & _condexpr ! = NULL ) // subsection condizionale
{
if ( ( bool ) ( _section - > eval_expr ( * _condexpr , _file_id ) ) )
1998-05-27 13:41:48 +00:00
ok = _ssec . update_and_print ( showfields , at_newpage ) ;
1997-06-16 12:52:23 +00:00
}
else
{
1998-04-30 15:31:34 +00:00
_ssec . set_repeat_count ( 0 ) ;
1997-06-16 12:52:23 +00:00
if ( _condexpr ) { // sottosezione di raggruppamenti su file
int i = 0 ;
2000-05-05 15:25:49 +00:00
TString group_expr = _section - > eval_expr ( * _condexpr , _file_id ) . as_string ( ) ;
1997-06-16 12:52:23 +00:00
bool again = TRUE ;
1998-08-25 18:07:30 +00:00
while ( again & & group_expr = = _section - > eval_expr ( * _condexpr , _file_id ) . as_string ( ) )
1997-06-16 12:52:23 +00:00
{
form ( ) . match_result ( _file_id ) ;
if ( ! _bigskip | | i = = 0 )
{
1998-05-27 13:41:48 +00:00
ok | = _ssec . update_and_print ( showfields , at_newpage ) ;
1997-06-16 12:52:23 +00:00
_ssec . set_repeat_count ( + + i ) ;
}
if ( form ( ) . next_match_done ( _file_id ) )
{
again = form ( ) . last_match_result ( _file_id ) ; // continue if there WAS a match
} else {
again = cur - > next_match ( _file_id ) ;
form ( ) . match_result ( _file_id , again ) ; // store if a match occoured
1997-06-16 12:41:59 +00:00
}
2000-05-05 15:25:49 +00:00
at_newpage = ( atnewpage ( ) | | printer ( ) . rows_left ( ) < ( word ) minheight ( ) ) ;
1998-04-30 15:31:34 +00:00
}
// _ssec.set_repeat_count(0);
1997-06-16 12:52:23 +00:00
} else { // sottosezione di file
int i = 0 ;
if ( cur - > is_first_match ( _file_id ) )
{
bool again ;
1999-04-06 16:31:40 +00:00
do {
1997-06-16 12:52:23 +00:00
form ( ) . match_result ( _file_id ) ;
1998-05-27 13:41:48 +00:00
ok | = _ssec . update_and_print ( showfields , at_newpage ) ;
1997-06-16 12:52:23 +00:00
_ssec . set_repeat_count ( + + i ) ;
if ( form ( ) . next_match_done ( _file_id ) )
again = form ( ) . last_match_result ( _file_id ) ;
else
again = cur - > next_match ( _file_id ) ;
2000-05-05 15:25:49 +00:00
at_newpage = ( atnewpage ( ) | | printer ( ) . rows_left ( ) < ( word ) minheight ( ) ) ;
1999-04-06 16:31:40 +00:00
} while ( again ) ;
1999-04-07 14:41:07 +00:00
ok | = ( _ssec . repeat_count ( ) > 0 ) ; // (ovvero, sempre true: se c'e' un first match)
1997-06-16 12:52:23 +00:00
}
1998-04-30 15:31:34 +00:00
// _ssec.set_repeat_count(0);
1997-06-16 12:52:23 +00:00
}
}
1998-04-30 15:31:34 +00:00
1997-06-16 12:52:23 +00:00
return ok ;
1995-06-07 10:47:05 +00:00
}
1995-05-09 09:12:26 +00:00
1997-06-16 12:41:59 +00:00
// @mfunc Abilita (default) o disabilita la stampa di tutti i campi della sottosezione
/*void TForm_subsection::show(bool on)
1995-05-09 09:12:26 +00:00
{
1997-06-16 12:52:23 +00:00
TForm_item : : show ( on ) ;
1995-05-09 09:12:26 +00:00
for ( unsigned int i = 0 ; i < _ssec . fields ( ) ; i + + )
_ssec . field ( i ) . show ( on ) ;
}
1997-06-16 12:41:59 +00:00
// @mfunc Abilita (default) o disabilita la valutazione e la stampa di tutti i campi della sottosezione
1995-05-09 09:12:26 +00:00
void TForm_subsection : : enable ( bool on )
{
1997-06-16 12:52:23 +00:00
TForm_item : : enable ( on ) ;
1995-05-09 09:12:26 +00:00
for ( unsigned int i = 0 ; i < _ssec . fields ( ) ; i + + )
_ssec . field ( i ) . enable ( on ) ;
1997-06-16 12:41:59 +00:00
} */
1994-11-10 14:17:03 +00:00
///////////////////////////////////////////////////////////
// TForm_string
///////////////////////////////////////////////////////////
1997-06-16 12:41:59 +00:00
TForm_string : : TForm_string ( TPrint_section * section )
1997-06-16 12:52:23 +00:00
: TForm_item ( section ) , _memo ( " " , ' \n ' )
1996-01-09 10:37:29 +00:00
{ }
1996-05-20 13:07:32 +00:00
TObject * TForm_string : : dup ( ) const
1996-04-17 16:43:58 +00:00
{
1997-06-16 12:52:23 +00:00
TForm_string * fs = new TForm_string ( _section ) ;
copy_to_form_item ( fs ) ;
fs - > _str = _str ;
fs - > _picture = _picture ;
fs - > _field = _field ;
fs - > _memo = _memo ;
return fs ;
1996-04-17 16:43:58 +00:00
}
1994-11-10 14:17:03 +00:00
bool TForm_string : : parse_item ( TScanner & scanner )
{
1997-06-16 12:52:23 +00:00
if ( scanner . key ( ) = = " FI " ) // FIELD reference
{
TFieldref * fr = new TFieldref ( scanner . line ( ) , 0 ) ;
_field . add ( fr ) ;
return TRUE ;
}
1994-11-10 14:17:03 +00:00
1997-06-16 12:52:23 +00:00
if ( scanner . key ( ) = = " PI " ) // PICTURE def
{
set_picture ( scanner . string ( ) ) ;
return TRUE ;
}
1994-11-10 14:17:03 +00:00
1997-06-16 12:52:23 +00:00
return TForm_item : : parse_item ( scanner ) ;
1994-11-10 14:17:03 +00:00
}
bool TForm_string : : set ( const char * s )
{
1997-06-16 12:52:23 +00:00
_str = s ;
return TRUE ;
1994-11-10 14:17:03 +00:00
}
const char * TForm_string : : get ( ) const
{ return _str ; }
1995-03-22 09:07:04 +00:00
1997-06-16 12:41:59 +00:00
// Se un campo e' abilitato ed ha almeno un riferimento su file leggilo
1994-11-10 14:17:03 +00:00
bool TForm_string : : read ( )
{
1997-06-16 12:52:23 +00:00
const bool ok = enabled ( ) ;
if ( ok )
{
if ( _field . items ( ) ! = 0 )
{
const char * s = " " ;
// !?!?!?!!
const TRelation * r = ( TRelation * ) form ( ) . relation ( ) ;
CHECK ( r , " Can't read from null relation " ) ;
for ( int i = 0 ; i < _field . items ( ) & & * s = = ' \0 ' ; i + + )
s = field ( i ) . read ( * r ) ;
set ( s ) ;
}
}
return ok ;
1994-11-10 14:17:03 +00:00
}
void TForm_string : : put_paragraph ( const char * s )
{
1997-08-29 16:37:26 +00:00
if ( hidden ( ) ) return ;
1997-06-16 12:52:23 +00:00
const int h = height ( ) ;
if ( h > 1 )
{
2003-05-15 08:09:47 +00:00
TString lines ;
if ( _prompt . not_empty ( ) )
lines = _prompt ;
lines < < s ;
TParagraph_string p ( lines , width ( ) ) ;
1997-06-16 12:52:23 +00:00
for ( int i = 0 ; ( s = p . get ( ) ) ! = NULL & & i < h ; i + + )
2003-05-15 08:09:47 +00:00
string_at ( x ( ) , _y + i , s ) ;
1997-06-16 12:52:23 +00:00
_effective_height = i ;
2003-05-15 08:09:47 +00:00
1998-08-25 18:07:30 +00:00
TForm_subsection * subsec = section ( ) . subsection_above ( ) ;
if ( subsec )
{
// aggiorno l'altezza effettiva della sottosezione
if ( effective_height ( ) > 1 )
{
// il campo si <20> "espanso"
const int last_y = effective_height ( ) + y ( ) - 1 ;
if ( last_y > subsec - > height ( ) )
subsec - > set_effective_height ( last_y ) ;
}
}
1997-06-16 12:52:23 +00:00
}
1997-08-29 16:37:26 +00:00
else
{
if ( _prompt . empty ( ) )
string_at ( x ( ) , _y , s ) ;
else
string_at ( - 1 , _y , s ) ;
}
1994-11-10 14:17:03 +00:00
}
1997-06-16 12:41:59 +00:00
1997-08-29 16:37:26 +00:00
void TForm_string : : apply_format ( TString & s ) const
1997-06-16 12:41:59 +00:00
{
1997-06-16 12:52:23 +00:00
TString tmp ( s ) ;
1997-08-29 16:37:26 +00:00
if ( ! picture ( ) . blank ( ) )
1997-06-16 12:52:23 +00:00
{
TToken_string delim ( 4 , ' , ' ) ; // Stringa con i due delimitatori
1997-08-29 16:37:26 +00:00
const char * pic = picture ( ) ; // Picture senza delimitatori
1997-06-16 12:52:23 +00:00
if ( pic [ 0 ] = = ' ( ' ) // Se ci sono i delimitatori ...
{
1997-08-29 16:37:26 +00:00
const int bra = picture ( ) . find ( ' ) ' ) ;
1997-06-16 12:52:23 +00:00
if ( bra > 0 ) // ... cerca la parentesi chiusa
{
1997-08-29 16:37:26 +00:00
delim = picture ( ) . sub ( 1 , bra ) ; // memorizza delimitatori
1997-06-16 12:52:23 +00:00
pic + = bra + 1 ; // toglili dalla picture
}
}
1998-04-30 15:31:34 +00:00
if ( strcmp ( class_name ( ) , " DATA " ) = = 0 & & s . empty ( ) )
1997-06-16 12:52:23 +00:00
tmp = " " ;
else
tmp . picture ( pic , s ) ; // riempi la stringa col valore pitturato
if ( ! delim . empty_items ( ) ) // Aggiungi delimitatori
{
TString16 d ( delim . get ( 0 ) ) ;
const int ld = d . len ( ) ;
if ( ld > 0 ) // Se il primo delimitatore e' valido ...
{
for ( int spc = 0 ; s [ spc ] = = ' ' ; spc + + ) ;
if ( spc < ld )
{
TString16 spazi ;
spazi . spaces ( ld - spc ) ;
tmp . insert ( spazi , 0 ) ;
spc = ld ;
}
tmp . overwrite ( d , spc - ld ) ;
}
d = delim . get ( ) ;
if ( d . not_empty ( ) ) // Se il secondo delimitatore e' valido ...
tmp < < d ; // ... aggiungilo alla fine
}
s = tmp ;
}
1997-06-16 12:41:59 +00:00
}
1994-11-10 14:17:03 +00:00
bool TForm_string : : update ( )
{
1997-06-16 12:52:23 +00:00
if ( read ( ) ) // valuta il campo
{
TForm_item : : update ( ) ;
// esegue i messaggi
1997-09-19 13:20:20 +00:00
const int n = ( _message . objptr ( 1 ) ! = NULL & & * get ( ) = = ' \0 ' ? 1 : 0 ) ;
1997-06-16 12:52:23 +00:00
do_message ( n ) ;
// prende il campo e lo stampa
1997-09-19 13:20:20 +00:00
TString s ( get ( ) ) ;
1997-09-19 13:39:28 +00:00
apply_format ( s ) ;
1997-06-16 12:52:23 +00:00
put_paragraph ( s ) ;
}
return TRUE ;
1994-11-10 14:17:03 +00:00
}
1995-12-14 10:45:17 +00:00
const char * TForm_string : : example ( ) const
1997-06-16 12:41:59 +00:00
{
2003-03-27 12:14:51 +00:00
TString & prova = get_tmp_string ( ) ;
prova = " XXXXXXXXXXXXXXXXXXXXXXXXXX " ;
1997-08-29 16:37:26 +00:00
apply_format ( prova ) ;
1997-06-16 12:52:23 +00:00
const int w = width ( ) ;
2003-03-27 12:14:51 +00:00
if ( prova . size ( ) > w & & w > 0 )
prova . cut ( w ) ;
return prova ;
1995-12-14 10:45:17 +00:00
}
1994-11-10 14:17:03 +00:00
///////////////////////////////////////////////////////////
// TForm_number
///////////////////////////////////////////////////////////
class TForm_number : public TForm_string
1997-06-16 12:41:59 +00:00
{
1995-05-18 14:18:01 +00:00
1997-06-16 12:41:59 +00:00
protected : // TForm_string
1997-06-16 12:52:23 +00:00
virtual const char * class_name ( ) const { return " NUMERO " ; }
virtual bool parse_head ( TScanner & scanner ) ;
virtual bool update ( ) ;
//virtual int height() const { return 0; }
1997-06-16 12:41:59 +00:00
protected :
1997-06-16 12:52:23 +00:00
int decimals ( ) const { return _height ; }
1994-11-10 14:17:03 +00:00
public :
1995-11-24 09:54:06 +00:00
1999-01-19 09:15:17 +00:00
void real2currency ( const real & r , TString & str ) const ;
1997-06-16 12:52:23 +00:00
virtual TObject * dup ( ) const ;
void set_decimals ( int d ) { _height = d ; }
virtual const char * example ( ) const ;
virtual void set_picture ( const char * p ) ;
1997-08-29 16:37:26 +00:00
virtual void apply_format ( TString & s ) const ;
1997-06-16 12:52:23 +00:00
virtual void put_paragraph ( const char * s ) ;
1995-12-14 10:45:17 +00:00
1997-06-16 12:52:23 +00:00
TForm_number ( TPrint_section * section ) : TForm_string ( section ) { }
virtual ~ TForm_number ( ) { }
1994-11-10 14:17:03 +00:00
} ;
bool TForm_number : : parse_head ( TScanner & scanner )
1997-06-16 12:41:59 +00:00
{
1997-06-16 12:52:23 +00:00
return TForm_item : : parse_head ( scanner ) ;
1994-11-10 14:17:03 +00:00
}
1996-05-20 13:07:32 +00:00
TObject * TForm_number : : dup ( ) const
{
1997-06-16 12:52:23 +00:00
TForm_number * fn = new TForm_number ( _section ) ;
copy_to_form_item ( fn ) ;
return fn ;
1996-05-20 13:07:32 +00:00
}
1994-11-10 14:17:03 +00:00
1996-01-23 12:16:28 +00:00
void TForm_number : : put_paragraph ( const char * s )
{
2000-05-05 15:25:49 +00:00
if ( hidden ( ) ) return ;
1997-06-16 12:52:23 +00:00
int gap = 0 ;
if ( section ( ) . columnwise ( ) )
{
const int w = width ( ) ;
const int l = strlen ( s ) ;
if ( w > l ) gap = w - l ;
}
if ( _prompt . empty ( ) )
string_at ( x ( ) + gap , _y , s ) ;
else
string_at ( - 1 , _y , s ) ; // se ha il prompt stampa all'ultima posizione raggiunta
1996-01-23 12:16:28 +00:00
}
1999-01-19 09:15:17 +00:00
void TForm_number : : real2currency ( const real & r , TString & str ) const
{
2001-04-30 15:04:10 +00:00
TCurrency c ( r ) ;
1999-01-19 09:15:17 +00:00
c . set_price ( _flag . price ! = 0 ) ;
2001-04-30 15:04:10 +00:00
2001-06-25 10:41:20 +00:00
const TExchange * oe = form ( ) . output_exchange ( ) ;
if ( oe & & ! c . get_exchange ( ) . same_value_as ( * oe ) )
c . change_value ( * oe ) ;
2001-04-30 15:04:10 +00:00
1999-01-19 09:15:17 +00:00
const TString & pic = picture ( ) ;
2001-04-30 15:04:10 +00:00
const int piclen = pic . len ( ) ;
1999-01-19 09:15:17 +00:00
const bool dotted = pic . empty ( ) | | pic . find ( ' . ' ) > = 0 ;
str = c . string ( dotted ) ;
const int w = width ( ) ;
2001-04-30 15:04:10 +00:00
if ( w > piclen )
1999-01-19 09:15:17 +00:00
str . right_just ( w ) ;
}
1994-11-10 14:17:03 +00:00
bool TForm_number : : update ( )
{
1997-06-16 12:52:23 +00:00
if ( read ( ) ) // valuta il campo
{
TForm_item : : update ( ) ;
2002-12-20 16:15:03 +00:00
real n = get ( ) ; // Trasforma la stringa in numero reale
1998-10-01 13:59:39 +00:00
2002-12-20 16:15:03 +00:00
// Arrotonda intelligentemente il numero
int round_dec = decimals ( ) ;
if ( round_dec = = 0 & & width ( ) > 9 & & form ( ) . magic_currency ( ) ) // Magic currency?
round_dec = TCurrency : : get_firm_dec ( ) ;
n . round ( round_dec ) ;
1997-06-16 12:52:23 +00:00
2002-12-20 16:15:03 +00:00
if ( _message . items ( ) > 0 )
{
const int nm = ( _message . objptr ( 1 ) ! = NULL & & n . is_zero ( ) ) ? 1 : 0 ;
do_message ( nm ) ;
n = get ( ) ; // Il numero potrebbe essere cambiato dal messaggio!
n . round ( round_dec ) ;
}
1998-11-04 18:04:26 +00:00
bool print = TRUE ;
if ( n . is_zero ( ) )
{
char sep = picture ( ) . find ( ' E ' ) > = 0 ? ' . ' : ' , ' ;
int comma = picture ( ) . find ( sep ) ;
if ( comma < 0 )
comma = picture ( ) . len ( ) ;
print = comma > 0 & & picture ( ) [ comma - 1 ] = = ' @ ' ;
}
if ( print )
1997-06-16 12:52:23 +00:00
{
2002-12-20 16:15:03 +00:00
TString80 print_string ;
bool app_for = TRUE ; // Apply format?
if ( form ( ) . magic_currency ( ) )
1999-01-19 09:15:17 +00:00
{
const bool b1 = picture ( ) = = " . " | | ( picture ( ) . len ( ) > = 9 & & picture ( ) . find ( ' , ' ) < 0 ) ;
const bool b2 = width ( ) > = 9 & & decimals ( ) = = 0 ;
if ( b1 | | b2 )
2002-12-20 16:15:03 +00:00
{
real2currency ( n , print_string ) ;
app_for = FALSE ; // La stringa <20> gi<67> belle che formattata!
}
1999-01-19 09:15:17 +00:00
}
2002-12-20 16:15:03 +00:00
if ( app_for )
{
print_string = n . string ( ) ;
apply_format ( print_string ) ;
}
put_paragraph ( print_string ) ;
1997-06-16 12:52:23 +00:00
}
}
return TRUE ;
1994-11-10 14:17:03 +00:00
}
1997-08-29 16:37:26 +00:00
void TForm_number : : apply_format ( TString & s ) const
1995-12-14 10:45:17 +00:00
{
1997-06-16 12:52:23 +00:00
if ( ! picture ( ) . blank ( ) )
1997-08-29 16:37:26 +00:00
{
real n ( s ) ;
1997-06-16 12:52:23 +00:00
TToken_string delim ( 4 , ' , ' ) ; // Stringa con i due delimitatori
1999-01-19 09:15:17 +00:00
TString pic ( picture ( ) ) ; // Picture senza delimitatori
1997-06-16 12:52:23 +00:00
int maxlen = - 1 ;
if ( pic [ 0 ] = = ' ( ' ) // Se ci sono i delimitatori ...
{
const int bra = pic . find ( ' ) ' ) ;
if ( bra > 0 ) // ... cerca la parentesi chiusa
{
delim = pic . sub ( 1 , bra ) ; // memorizza delimitatori
pic . ltrim ( bra + 1 ) ; // toglili dalla picture
}
}
const int at = pic . find ( ' @ ' ) ;
if ( at > 0 )
{
const int len = atoi ( & pic [ at + 1 ] ) ;
if ( len > 0 )
{
maxlen = len ;
pic . cut ( at ) ;
}
}
1999-01-19 09:15:17 +00:00
s = n . string ( pic ) ; // riempi la stringa col valore pitturato
1997-06-16 12:52:23 +00:00
if ( maxlen > = 0 & & maxlen < s . size ( ) )
s . cut ( maxlen ) ;
if ( ! delim . empty_items ( ) ) // Aggiungi delimitatori
{
TString16 d ( delim . get ( 0 ) ) ;
const int ld = d . len ( ) ;
if ( ld > 0 ) // Se il primo delimitatore e' valido ...
{
for ( int spc = 0 ; s [ spc ] = = ' ' ; spc + + ) ;
if ( spc < ld )
{
TString16 spazi ;
1999-01-19 09:15:17 +00:00
spazi . spaces ( ld - spc ) ;
s . insert ( spazi , 0 ) ;
spc = ld ;
}
s . overwrite ( d , spc - ld ) ;
}
d = delim . get ( ) ;
if ( d . not_empty ( ) ) // Se il secondo delimitatore e' valido ...
s < < d ; // ... aggiungilo alla fine
1997-06-16 12:52:23 +00:00
}
}
2002-12-20 16:15:03 +00:00
else
{
real n ( s ) ;
s = n . stringa ( width ( ) , decimals ( ) ) ;
}
1995-12-14 10:45:17 +00:00
}
1996-01-09 11:34:13 +00:00
void TForm_number : : set_picture ( const char * p )
{
1997-06-16 12:52:23 +00:00
TForm_string : : set_picture ( p ) ;
const int comma = picture ( ) . find ( ' , ' ) ;
2000-10-03 13:45:12 +00:00
if ( comma > 0 )
set_decimals ( picture ( ) . len ( ) - comma - 1 ) ;
1997-06-16 12:41:59 +00:00
}
1996-01-09 11:34:13 +00:00
1995-12-14 10:45:17 +00:00
const char * TForm_number : : example ( ) const
{
2003-03-27 12:14:51 +00:00
TString & s = get_tmp_string ( ) ;
s = " 1234567890.123456 " ;
1997-08-29 16:37:26 +00:00
apply_format ( s ) ;
2003-03-27 12:14:51 +00:00
return s ;
1995-12-14 10:45:17 +00:00
}
1997-06-16 12:41:59 +00:00
1999-01-19 09:15:17 +00:00
///////////////////////////////////////////////////////////
// TForm_currency
///////////////////////////////////////////////////////////
class TForm_currency : public TForm_number
{
1999-07-16 14:59:11 +00:00
TForm_item * _driver ;
1999-01-19 09:15:17 +00:00
protected : // TForm_string
virtual const char * class_name ( ) const { return " VALUTA " ; }
virtual bool parse_head ( TScanner & scanner ) ;
1999-07-16 14:59:11 +00:00
virtual bool parse_item ( TScanner & scanner ) ;
1999-01-19 09:15:17 +00:00
virtual bool update ( ) ;
2001-04-30 15:04:10 +00:00
virtual const char * get ( ) const ;
1999-10-22 10:00:18 +00:00
// @cmember Manda il messaggio al campo <p dest>
virtual void send_message ( const TString & cmd , TForm_item & dest ) const ;
1999-01-19 09:15:17 +00:00
public :
virtual TObject * dup ( ) const ;
1999-10-22 10:00:18 +00:00
virtual TCurrency get_currency ( ) const ;
1999-07-16 14:59:11 +00:00
TForm_currency ( TPrint_section * section ) : TForm_number ( section ) , _driver ( NULL ) { }
1999-01-19 09:15:17 +00:00
virtual ~ TForm_currency ( ) { }
} ;
1995-12-14 10:45:17 +00:00
1999-01-19 09:15:17 +00:00
bool TForm_currency : : parse_head ( TScanner & scanner )
{
return TForm_item : : parse_head ( scanner ) ;
}
1999-07-16 14:59:11 +00:00
bool TForm_currency : : parse_item ( TScanner & scanner )
{
if ( scanner . key ( ) = = " DR " )
{
_driver = & find_field ( scanner . pop ( ) ) ;
return TRUE ;
}
return TForm_number : : parse_item ( scanner ) ;
}
1999-01-19 09:15:17 +00:00
TObject * TForm_currency : : dup ( ) const
{
TForm_currency * fn = new TForm_currency ( _section ) ;
copy_to_form_item ( fn ) ;
return fn ;
}
2001-04-30 15:04:10 +00:00
const char * TForm_currency : : get ( ) const
{
const char * val = TForm_string : : get ( ) ;
return val ;
}
1999-10-22 10:00:18 +00:00
TCurrency TForm_currency : : get_currency ( ) const
{
2001-04-30 15:04:10 +00:00
const TString & codval = _driver ? _driver - > get ( ) : form ( ) . get_curr_codval ( ) ;
1999-10-22 10:00:18 +00:00
const real n ( get ( ) ) ;
2000-10-03 13:45:12 +00:00
return TCurrency ( n , codval , ZERO , _exchange_undefined , _flag . price ! = 0 ) ;
1999-10-22 10:00:18 +00:00
}
1999-01-19 09:15:17 +00:00
bool TForm_currency : : update ( )
{
if ( read ( ) ) // valuta il campo
{
TForm_item : : update ( ) ;
2002-12-20 16:15:03 +00:00
if ( _message . items ( ) > 0 )
{
const int nm = ( _message . objptr ( 1 ) ! = NULL & & real : : is_null ( get ( ) ) ) ? 1 : 0 ;
do_message ( nm ) ;
}
1999-01-19 09:15:17 +00:00
1999-10-22 10:00:18 +00:00
if ( ! real : : is_null ( get ( ) ) )
1999-07-16 14:59:11 +00:00
{
2001-04-30 15:04:10 +00:00
TCurrency curr = get_currency ( ) ;
if ( ! _driver )
{
2001-06-25 13:34:05 +00:00
const TExchange * oe = form ( ) . output_exchange ( ) ;
if ( oe ! = NULL & & ! curr . get_exchange ( ) . same_value_as ( * oe ) )
curr . change_value ( * oe ) ;
2001-04-30 15:04:10 +00:00
}
1999-07-16 14:59:11 +00:00
// Niente apply_format(), la picture viene ignorata per i TForm_currency
2001-06-25 13:34:05 +00:00
TString80 v ;
2001-04-30 15:04:10 +00:00
const TString & pic = picture ( ) ;
2001-06-25 13:34:05 +00:00
if ( pic . find ( " LETTERE " ) > = 0 )
2001-04-30 15:04:10 +00:00
{
2001-06-25 13:34:05 +00:00
v = get ( ) ;
apply_format ( v ) ;
const int slash = v . rfind ( ' / ' ) ;
TString16 tail ;
for ( int i = v . len ( ) - 1 ; i > 0 & & ! isalnum ( v [ i ] ) ; i - - )
{
tail < < v [ i ] ;
v . cut ( i ) ;
}
2002-12-20 16:15:03 +00:00
const int zeroes_needed = curr . decimals ( ) ;
2001-06-25 13:34:05 +00:00
if ( zeroes_needed > 0 )
{
int zeroes_missing = 0 ;
if ( slash > = 0 )
{
const int decimals_already_there = v . len ( ) - slash - 1 ;
zeroes_missing = zeroes_needed - decimals_already_there ;
}
else
{
v < < ' / ' ;
zeroes_missing = zeroes_needed ;
}
for ( ; zeroes_missing > 0 ; zeroes_missing - - )
v < < ' 0 ' ;
}
2001-04-30 15:04:10 +00:00
else
2001-06-25 13:34:05 +00:00
{
if ( slash > = 0 )
v . cut ( slash ) ;
}
v < < tail ;
}
else
{
const bool dotted = pic . empty ( ) | | pic . find ( ' . ' ) > 0 ;
v = curr . string ( dotted ) ;
if ( pic . right ( 3 ) = = " ^^^ " ) // 770 only: to be improved
{
const int dec = curr . decimals ( ) ;
if ( dec = = 0 )
v . rtrim ( 3 + dotted ) ;
else
v . rtrim ( dec + 1 ) ;
}
const int w = width ( ) - ( _section - > columnwise ( ) ? _prompt . len ( ) : 0 ) ;
if ( w > v . len ( ) )
v . right_just ( w ) ;
2001-04-30 15:04:10 +00:00
}
1999-07-16 14:59:11 +00:00
put_paragraph ( v ) ;
}
else
2001-04-30 15:04:10 +00:00
{
const TString & pic = picture ( ) ;
if ( pic . right ( 1 ) [ 0 ] = = ' @ ' )
{
TString80 v ;
const int w = width ( ) - ( _section - > columnwise ( ) ? _prompt . len ( ) : 0 ) ;
int d = 0 ;
if ( _driver )
{
const TCurrency z ( ZERO , _driver - > get ( ) , ZERO , _exchange_base , _flag . price ! = 0 ) ;
d = z . decimals ( ) ;
}
else
2001-06-25 13:34:05 +00:00
{
const TExchange * oe = form ( ) . output_exchange ( ) ;
if ( oe ! = NULL )
{
const TCurrency z ( ZERO , * oe , _flag . price ! = 0 ) ;
d = z . decimals ( ) ;
}
else
d = TCurrency : : get_firm_dec ( _flag . price ! = 0 ) ;
2001-04-30 15:04:10 +00:00
}
if ( d > 0 )
{
v . format ( " %*.*lf " , w , d , 0.0 ) ;
v . replace ( ' . ' , ' , ' ) ;
}
else
v . format ( " %*d " , w , 0 ) ;
put_paragraph ( v ) ;
}
else
put_paragraph ( " " ) ;
}
1999-01-19 09:15:17 +00:00
}
return TRUE ;
}
1999-10-22 10:00:18 +00:00
void TForm_currency : : send_message ( const TString & cmd , TForm_item & dest ) const
{
if ( cmd = = " ADD " )
{
TCurrency total ;
if ( dest . class_name ( ) ! = class_name ( ) ) // La destinazione non e' un TForm_currency
{
const real n = dest . get ( ) ;
total . set_num ( n ) ;
}
else
total = ( ( TForm_currency & ) dest ) . get_currency ( ) ;
total + = get_currency ( ) ;
2001-04-30 15:04:10 +00:00
dest . set ( total . get_num ( ) . string ( ) ) ;
1999-10-22 10:00:18 +00:00
}
else
TForm_number : : send_message ( cmd , dest ) ;
}
1995-12-14 10:45:17 +00:00
1994-11-10 14:17:03 +00:00
///////////////////////////////////////////////////////////
// TForm_date
///////////////////////////////////////////////////////////
class TForm_date : public TForm_string
{
1997-06-16 12:52:23 +00:00
TString16 _format ;
1995-05-09 09:12:26 +00:00
1994-11-10 14:17:03 +00:00
protected :
1997-06-16 12:52:23 +00:00
virtual const char * class_name ( ) const { return " DATA " ; }
virtual bool read ( ) ;
virtual bool set ( const char * ) ;
bool set ( const TDate & d ) ;
virtual bool parse_item ( TScanner & scanner ) ;
virtual void print_body ( ostream & out ) const ;
1997-06-16 12:41:59 +00:00
1997-06-16 12:52:23 +00:00
virtual void print_on ( TMask & m ) ;
virtual void read_from ( const TMask & m ) ;
1997-06-16 12:41:59 +00:00
1997-06-16 12:52:23 +00:00
virtual bool read_from ( const TRectype & rform ) ;
virtual void print_on ( TRectype & rform ) ;
1997-06-16 12:41:59 +00:00
1994-11-10 14:17:03 +00:00
public :
1997-06-16 12:41:59 +00:00
1997-06-16 12:52:23 +00:00
virtual TObject * dup ( ) const ;
void set_format ( const char * f ) { _format = f ; }
virtual bool edit ( TMask & m ) ;
virtual const char * example ( ) const ;
TForm_date ( TPrint_section * section ) ;
virtual ~ TForm_date ( ) { }
1994-11-10 14:17:03 +00:00
} ;
1997-06-16 12:41:59 +00:00
TForm_date : : TForm_date ( TPrint_section * section )
1995-05-09 09:12:26 +00:00
: TForm_string ( section ) , _format ( " 1444- " )
1995-01-03 14:19:41 +00:00
{ }
1996-05-20 13:07:32 +00:00
TObject * TForm_date : : dup ( ) const
1996-04-17 16:43:58 +00:00
{
1997-06-16 12:52:23 +00:00
TForm_date * fd = new TForm_date ( _section ) ;
copy_to_form_item ( fd ) ;
fd - > _format = _format ;
return fd ;
1996-04-17 16:43:58 +00:00
}
1995-01-03 14:19:41 +00:00
bool TForm_date : : read ( )
1997-06-16 12:41:59 +00:00
{
1997-06-16 12:52:23 +00:00
bool ok = TForm_string : : read ( ) ;
if ( ok & & ! get ( ) [ 0 ] & & automagic ( ) )
set ( printer ( ) . getdate ( ) ) ;
return ok ;
1994-11-10 14:17:03 +00:00
}
1996-07-08 07:24:36 +00:00
void TForm_date : : print_body ( ostream & out ) const
1995-05-09 09:12:26 +00:00
{
1997-06-16 12:52:23 +00:00
TForm_string : : print_body ( out ) ;
out < < " FORMAT \" " < < _format < < " \" \n " ;
1995-05-09 09:12:26 +00:00
}
bool TForm_date : : parse_item ( TScanner & scanner )
{
1997-06-16 12:52:23 +00:00
if ( scanner . key ( ) = = " FO " )
{
_format = scanner . string ( ) ;
return TRUE ;
}
return TForm_string : : parse_item ( scanner ) ;
1995-05-09 09:12:26 +00:00
}
1995-05-29 10:25:10 +00:00
bool TForm_date : : read_from ( const TRectype & prof )
1997-06-16 12:41:59 +00:00
{
1997-06-16 12:52:23 +00:00
bool changed = TForm_string : : read_from ( prof ) ;
1997-06-16 12:41:59 +00:00
1997-06-16 12:52:23 +00:00
const TString & df = prof . get ( " DATEFORM " ) ;
if ( df . not_empty ( ) & & df ! = _format )
{
_format = df ;
changed = TRUE ;
}
1997-06-16 12:41:59 +00:00
1997-06-16 12:52:23 +00:00
return changed ;
1995-05-29 10:25:10 +00:00
}
void TForm_date : : print_on ( TRectype & prof )
1997-06-16 12:41:59 +00:00
{
1997-06-16 12:52:23 +00:00
TForm_string : : print_on ( prof ) ;
prof . put ( " DATEFORM " , _format ) ;
1995-05-29 10:25:10 +00:00
}
1994-11-10 14:17:03 +00:00
bool TForm_date : : set ( const char * s )
{
1997-06-16 12:52:23 +00:00
const TDate da ( s ) ;
return set ( da ) ;
1995-01-03 14:19:41 +00:00
}
1995-05-18 14:18:01 +00:00
bool TForm_date : : set ( const TDate & da )
1995-01-03 14:19:41 +00:00
{
1997-06-16 12:52:23 +00:00
TFormatted_date d ( da ) ; d . set_format ( _format ) ;
TForm_string : : set ( d . string ( ) ) ;
return TRUE ;
1997-06-16 12:41:59 +00:00
}
1995-05-09 09:12:26 +00:00
void TForm_date : : print_on ( TMask & m )
1997-06-16 12:41:59 +00:00
{
1997-06-16 12:52:23 +00:00
const TDate dd ( TODAY ) ;
TFormatted_date d ( dd ) ; d . set_format ( _format ) ;
m . set ( F_DEXAMPLE , d . string ( ) ) ;
1997-06-16 12:41:59 +00:00
1997-06-16 12:52:23 +00:00
m . set ( F_DFORMAT , _format . mid ( 0 , 1 ) ) ;
m . set ( F_DDAY , _format . mid ( 1 , 1 ) ) ;
m . set ( F_DMONTH , _format . mid ( 2 , 1 ) ) ;
m . set ( F_DYEAR , _format . mid ( 3 , 1 ) ) ;
m . set ( F_DSEP , _format . mid ( 4 , 1 ) ) ;
1995-05-09 09:12:26 +00:00
1997-06-16 12:52:23 +00:00
TForm_string : : print_on ( m ) ;
1995-05-09 09:12:26 +00:00
}
void TForm_date : : read_from ( const TMask & m )
{
1997-06-16 12:52:23 +00:00
TForm_string : : read_from ( m ) ;
1995-05-29 10:25:10 +00:00
1997-06-16 12:52:23 +00:00
// adjust format string
_format [ 0 ] = m . get ( F_DFORMAT ) [ 0 ] ;
_format [ 1 ] = m . get ( F_DDAY ) [ 0 ] ;
_format [ 2 ] = m . get ( F_DMONTH ) [ 0 ] ;
_format [ 3 ] = m . get ( F_DYEAR ) [ 0 ] ;
_format [ 4 ] = m . get ( F_DSEP ) [ 0 ] ;
_format [ 5 ] = ' \0 ' ;
1995-05-09 09:12:26 +00:00
}
bool TForm_date : : edit ( TMask & m )
1997-06-16 12:41:59 +00:00
{
1997-06-16 12:52:23 +00:00
return TForm_string : : edit ( m ) ;
1995-05-09 09:12:26 +00:00
}
1995-12-14 10:45:17 +00:00
const char * TForm_date : : example ( ) const
1997-06-16 12:41:59 +00:00
{
1997-06-16 12:52:23 +00:00
const TDate dd ( TODAY ) ;
TFormatted_date d ( dd ) ; d . set_format ( _format ) ;
2003-03-27 12:14:51 +00:00
TString & s = get_tmp_string ( ) ;
s = d . string ( ) ;
return s ;
1995-12-14 10:45:17 +00:00
}
1994-11-10 14:17:03 +00:00
///////////////////////////////////////////////////////////
// TForm_list
///////////////////////////////////////////////////////////
class TForm_list : public TForm_string
{
1997-06-16 12:52:23 +00:00
TToken_string _codes ;
TToken_string _values ;
1994-11-10 14:17:03 +00:00
protected :
1997-06-16 12:52:23 +00:00
virtual const char * class_name ( ) const { return " LISTA " ; }
virtual bool parse_item ( TScanner & scanner ) ;
virtual void print_on ( TMask & m ) ;
virtual void read_from ( const TMask & m ) ;
virtual void print_body ( ostream & out ) const ;
virtual bool update ( ) ;
1994-11-10 14:17:03 +00:00
public :
1997-06-16 12:52:23 +00:00
virtual TObject * dup ( ) const ;
TForm_list ( TPrint_section * section ) ;
virtual ~ TForm_list ( ) { }
1994-11-10 14:17:03 +00:00
} ;
TForm_list : : TForm_list ( TPrint_section * section )
: TForm_string ( section )
{ }
1996-05-20 13:07:32 +00:00
TObject * TForm_list : : dup ( ) const
1996-04-17 16:43:58 +00:00
{
1997-06-16 12:52:23 +00:00
TForm_list * fl = new TForm_list ( _section ) ;
copy_to_form_item ( fl ) ;
fl - > _codes = _codes ;
fl - > _values = _values ;
return fl ;
1996-04-17 16:43:58 +00:00
}
1994-11-10 14:17:03 +00:00
bool TForm_list : : parse_item ( TScanner & scanner )
{
1997-06-16 12:52:23 +00:00
if ( scanner . key ( ) = = " IT " )
{
TToken_string s ( scanner . string ( ) ) ;
_codes . add ( s . get ( ) ) ;
_values . add ( s . get ( ) ) ;
1994-11-10 14:17:03 +00:00
1997-06-16 12:52:23 +00:00
while ( scanner . popkey ( ) = = " ME " )
{
TFixed_string m ( scanner . line ( ) ) ;
m . strip_spaces ( ) ;
message ( _values . items ( ) - 1 ) . add ( m ) ;
}
scanner . push ( ) ;
return TRUE ;
}
1997-06-16 12:41:59 +00:00
1997-06-16 12:52:23 +00:00
return TForm_string : : parse_item ( scanner ) ;
1994-11-10 14:17:03 +00:00
}
1994-12-20 15:11:26 +00:00
void TForm_list : : print_on ( TMask & m )
1997-06-16 12:41:59 +00:00
{
1997-06-16 12:52:23 +00:00
TForm_string : : print_on ( m ) ;
TSheet_field & s = ( TSheet_field & ) m . field ( F_ITEMS ) ;
s . reset ( ) ;
_codes . restart ( ) ; _values . restart ( ) ;
for ( int i = 0 ; i < _codes . items ( ) ; i + + )
{
TToken_string & row = s . row ( i ) ;
row = _codes . get ( ) ;
row . add ( _values . get ( ) ) ;
row . add ( message ( i ) ) ;
}
// s.force_update();
1994-12-20 15:11:26 +00:00
}
void TForm_list : : read_from ( const TMask & m )
{
1997-06-16 12:52:23 +00:00
TForm_string : : read_from ( m ) ;
1994-12-20 15:11:26 +00:00
1997-06-16 12:52:23 +00:00
TSheet_field & s = ( TSheet_field & ) m . field ( F_ITEMS ) ;
1997-06-16 12:41:59 +00:00
1997-06-16 12:52:23 +00:00
_codes = _values = " " ;
for ( int i = 0 ; i < s . items ( ) ; i + + )
{
TToken_string & row = s . row ( i ) ;
_codes . add ( row . get ( 0 ) ) ;
_values . add ( row . get ( ) ) ;
message ( i ) = row . get ( ) ;
}
1994-12-20 15:11:26 +00:00
}
1994-11-10 14:17:03 +00:00
1996-07-08 07:24:36 +00:00
void TForm_list : : print_body ( ostream & out ) const
1994-11-10 14:17:03 +00:00
{
1997-06-16 12:52:23 +00:00
TForm_string : : print_body ( out ) ;
1994-11-10 14:17:03 +00:00
1997-06-16 12:52:23 +00:00
TToken_string & cod = ( TToken_string & ) _codes ; // Trick to skip const
TToken_string & val = ( TToken_string & ) _values ;
1994-11-10 14:17:03 +00:00
1997-06-16 12:52:23 +00:00
int i = 0 ;
TString c ( cod . get ( 0 ) ) ;
TString v ( val . get ( 0 ) ) ;
1994-11-10 14:17:03 +00:00
1997-06-16 12:52:23 +00:00
for ( ; c [ 0 ] ; c = cod . get ( ) , v = val . get ( ) , i + + )
{
out < < " ITEM \" " < < c ;
if ( v . not_empty ( ) ) out < < ' | ' < < v ;
out < < ' " ' ;
1994-11-10 14:17:03 +00:00
1997-06-16 12:52:23 +00:00
const char * m = ( ( TForm_list * ) this ) - > message ( i ) ;
if ( * m ) out < < " MESSAGE " < < m ;
1994-11-10 14:17:03 +00:00
1997-06-16 12:52:23 +00:00
out < < endl ;
}
1994-11-10 14:17:03 +00:00
}
bool TForm_list : : update ( )
{
1997-06-16 12:52:23 +00:00
bool ok = TRUE ;
if ( ! read ( ) ) return ok ;
const TString & val = get ( ) ;
int pos = _codes . get_pos ( val ) ;
if ( pos < 0 )
{
TString def = _codes . get ( 0 ) ;
def . trim ( ) ;
if ( val = = def ) pos = 0 ; // Test default (first & empty) value
else
{
ok = yesno_box ( " Il campo '%s' non puo' valere '%s': continuare ugualmente " ,
( const char * ) key ( ) , ( const char * ) val ) ;
set ( _codes . get ( pos = 0 ) ) ;
}
}
if ( ok )
{
do_message ( pos ) ;
if ( ! hidden ( ) )
{
const char * c = _values . get ( pos ) ;
if ( c = = NULL ) c = val ;
if ( c ) string_at ( x ( ) , _y , c ) ;
}
}
return ok ;
1994-11-10 14:17:03 +00:00
}
1995-01-02 09:33:00 +00:00
///////////////////////////////////////////////////////////
// TForm_group
///////////////////////////////////////////////////////////
class TForm_group : public TForm_item
{
protected :
1997-06-16 12:52:23 +00:00
virtual const char * class_name ( ) const { return " GRUPPO " ; }
virtual bool update ( ) { return TRUE ; }
1995-01-02 09:33:00 +00:00
public :
1997-06-16 12:52:23 +00:00
TForm_group ( TPrint_section * section ) : TForm_item ( section ) { } ;
virtual ~ TForm_group ( ) { }
1995-01-02 09:33:00 +00:00
} ;
1994-11-10 14:17:03 +00:00
1995-12-14 10:45:17 +00:00
///////////////////////////////////////////////////////////
// TGraphic_section
///////////////////////////////////////////////////////////
class TGraphic_section : public TPrint_section
{
1997-06-16 12:52:23 +00:00
TString _back ;
1997-06-16 12:41:59 +00:00
protected :
1999-04-06 15:34:39 +00:00
// @cmember Crea un campo della classe specificata
virtual TForm_item * create_item ( const TString & s ) ;
virtual bool update ( ) ;
1995-12-14 10:45:17 +00:00
public :
1997-06-16 12:52:23 +00:00
void append ( const char * s ) { _back < < s ; }
1999-04-06 15:34:39 +00:00
1997-06-16 12:52:23 +00:00
TGraphic_section ( TForm * f , pagetype pt ) : TPrint_section ( f , ' G ' , pt ) { }
virtual ~ TGraphic_section ( ) { }
1995-12-14 10:45:17 +00:00
} ;
class TForm_picture : public TForm_item
1999-05-24 13:34:11 +00:00
{
TFieldref _field ;
1995-12-14 10:45:17 +00:00
protected :
1997-06-16 12:52:23 +00:00
virtual const char * class_name ( ) const { return " FIGURA " ; }
1999-05-24 13:34:11 +00:00
virtual bool parse_item ( TScanner & scanner ) ;
1997-06-16 12:52:23 +00:00
virtual bool update ( ) ;
1995-12-14 10:45:17 +00:00
public :
1999-05-24 13:34:11 +00:00
TForm_picture ( TPrint_section * section ) : TForm_item ( section ) { }
1997-06-16 12:52:23 +00:00
virtual ~ TForm_picture ( ) { }
1995-12-14 10:45:17 +00:00
} ;
class TForm_line : public TForm_item
{
protected :
1997-06-16 12:52:23 +00:00
virtual const char * class_name ( ) const { return " LINEA " ; }
virtual bool update ( ) ;
1995-12-14 10:45:17 +00:00
public :
1997-06-16 12:52:23 +00:00
TForm_line ( TGraphic_section * section ) : TForm_item ( section ) { }
virtual ~ TForm_line ( ) { }
1995-12-14 10:45:17 +00:00
} ;
1995-12-15 11:35:47 +00:00
class TForm_box : public TForm_item
{
protected :
1997-06-16 12:52:23 +00:00
virtual const char * class_name ( ) const { return " BOX " ; }
virtual bool update ( ) ;
1995-12-15 11:35:47 +00:00
public :
1997-06-16 12:52:23 +00:00
TForm_box ( TGraphic_section * section ) : TForm_item ( section ) { }
virtual ~ TForm_box ( ) { }
1995-12-15 11:35:47 +00:00
} ;
1999-05-24 13:34:11 +00:00
bool TForm_picture : : parse_item ( TScanner & scanner )
{
if ( scanner . key ( ) = = " FI " ) // FIELD reference
{
_field = scanner . line ( ) ;
return TRUE ;
}
return TForm_item : : parse_item ( scanner ) ;
}
1995-12-14 10:45:17 +00:00
bool TForm_picture : : update ( )
1997-06-16 12:41:59 +00:00
{
1999-05-24 13:34:11 +00:00
TFilename i ;
if ( _field . ok ( ) )
{
const TRelation * r = form ( ) . relation ( ) ;
if ( r )
{
TToken_string list ( _field . read ( * r ) , ' \n ' ) ;
FOR_EACH_TOKEN ( list , tok )
{
i = tok ;
const int pos = i . find ( ' | ' ) ;
if ( pos > = 0 )
i . cut ( pos ) ;
if ( stricmp ( i . ext ( ) , " bmp " ) = = 0 )
{
i . replace ( ' \\ ' , ' / ' ) ;
i . trim ( ) ;
break ;
}
else
i . cut ( 0 ) ;
}
}
else
NFCHECK ( " Can't read picture from NULL relation " ) ;
}
else
i = _prompt ;
2003-06-11 07:44:57 +00:00
i . custom_path ( ) ;
1999-05-24 13:34:11 +00:00
bool ok = i . not_empty ( ) & & i . exist ( ) ;
1997-06-16 12:52:23 +00:00
if ( ok )
{
1999-05-24 13:34:11 +00:00
i < < ' , ' < < _x < < ' , ' < < _y < < ' , ' < < ( _x + width ( ) - 1 ) < < ' , ' < < ( _y + height ( ) - 1 ) ;
if ( section ( ) . section_type ( ) = = ' G ' )
{
i . insert ( " i{ " , 0 ) ; i < < ' } ' ;
( ( TGraphic_section & ) section ( ) ) . append ( i ) ;
}
else
{
i . insert ( " @F[ " , 0 ) ; i < < ' ] ' ;
TPrintrow & row = section ( ) . row ( _y - 1 ) ;
row . put ( i ) ;
}
1997-06-16 12:52:23 +00:00
}
return ok ;
1995-12-14 10:45:17 +00:00
}
bool TForm_line : : update ( )
1997-06-16 12:41:59 +00:00
{
1997-06-16 12:52:23 +00:00
int spessore = 1 ;
char codice = ' l ' ;
for ( int j = _prompt . len ( ) - 1 ; j > = 0 ; j - - )
{
switch ( _prompt [ j ] )
{
case ' B ' :
case ' b ' :
spessore = 3 ; break ;
case ' R ' :
case ' r ' :
codice = ' r ' ; break ;
default :
break ;
}
}
2002-02-26 16:20:19 +00:00
// Calcola la vera coordinata y della linea
const int y = _y > = 0 ? _y : ( printer ( ) . formlen ( ) + _y + 1 ) ;
1997-06-16 12:52:23 +00:00
TString80 i ;
i < < ' W ' < < spessore < < codice
2002-02-26 16:20:19 +00:00
< < ' { ' < < _x < < ' , ' < < y < < ' , '
< < ( _x + width ( ) - 1 ) < < ' , ' < < ( y + height ( ) - 1 ) < < ' } ' ;
1997-06-16 12:52:23 +00:00
( ( TGraphic_section & ) section ( ) ) . append ( i ) ;
return TRUE ;
1995-12-14 10:45:17 +00:00
}
1995-12-15 11:35:47 +00:00
bool TForm_box : : update ( )
1997-06-16 12:41:59 +00:00
{
1997-06-16 12:52:23 +00:00
TString80 i ;
const int w = _prompt [ 0 ] = = ' @ ' ? 3 : 1 ;
i < < ' W ' < < w < < " b{ " < < _x < < ' , ' < < _y < < ' , '
< < ( _x + width ( ) - 1 ) < < ' , ' < < ( _y + height ( ) - 1 ) < < ' } ' ;
1997-06-16 12:41:59 +00:00
1997-06-16 12:52:23 +00:00
( ( TGraphic_section & ) section ( ) ) . append ( i ) ;
return TRUE ;
1995-12-15 11:35:47 +00:00
}
1999-04-06 15:34:39 +00:00
TForm_item * TGraphic_section : : create_item ( const TString & typ )
1995-12-14 10:45:17 +00:00
{
1999-04-06 15:34:39 +00:00
TForm_item * fff = NULL ;
if ( typ . compare ( " LINEA " , 2 , TRUE ) = = 0 )
fff = new TForm_line ( this ) ; else
if ( typ . compare ( " BOX " , 2 , TRUE ) = = 0 )
fff = new TForm_box ( this ) ; else
if ( typ . compare ( " FIGURA " , 2 , TRUE ) = = 0 )
fff = new TForm_picture ( this ) ;
return fff ;
1995-12-14 10:45:17 +00:00
}
bool TGraphic_section : : update ( )
1997-06-16 12:41:59 +00:00
{
1997-09-19 08:47:46 +00:00
_back . cut ( 0 ) ;
1997-06-16 12:52:23 +00:00
const bool ok = TPrint_section : : update ( ) ;
1997-09-19 08:47:46 +00:00
int index ;
switch ( page_type ( ) )
{
1997-10-31 13:43:39 +00:00
case even_page : index = 1 ; break ;
case first_page : index = 2 ; break ;
case last_page : index = 3 ; break ;
default : index = 0 ; break ;
1997-09-19 08:47:46 +00:00
}
printer ( ) . setbackground ( _back , index ) ;
1997-06-16 12:52:23 +00:00
return ok ;
1995-12-14 10:45:17 +00:00
}
1994-11-10 14:17:03 +00:00
///////////////////////////////////////////////////////////
// TPrint_section
///////////////////////////////////////////////////////////
1994-12-27 14:59:25 +00:00
TMask * TPrint_section : : _msk = NULL ;
1995-12-14 10:45:17 +00:00
1997-07-30 10:53:29 +00:00
word TPrint_section : : height ( ) const
{
1997-08-18 14:11:37 +00:00
word h = _height ;
1998-08-25 18:07:30 +00:00
if ( subsection_above ( ) & & ( word ) subsection_above ( ) - > effective_height ( ) > h )
{
h = subsection_above ( ) - > effective_height ( ) ;
}
1999-02-02 08:43:43 +00:00
if ( short ( h ) < 0 ) // Can't write h < 0!
1997-08-18 14:11:37 +00:00
{
if ( section_type ( ) = = ' F ' )
{
h + = printer ( ) . formlen ( ) ;
1999-02-02 08:43:43 +00:00
if ( short ( h ) < 0 ) // Still < 0 ?? get out...
1998-11-04 18:04:26 +00:00
h = 0 ;
1997-08-18 14:11:37 +00:00
}
else
{
1998-04-30 15:31:34 +00:00
h = _rows . items ( ) ;
1997-08-18 14:11:37 +00:00
if ( h = = 0 )
h = 0xFFFF - _height + 1 ; // Same as abs(_height)
}
1998-08-25 18:07:30 +00:00
}
1997-08-18 14:11:37 +00:00
return h ;
1997-07-30 10:53:29 +00:00
}
1997-06-16 12:41:59 +00:00
TExpression & TPrint_section : : eval_expr ( TExpression & expr , int defaultfile_id )
1997-06-16 12:52:23 +00:00
{
1997-08-18 14:11:37 +00:00
for ( int j = 0 ; j < expr . numvar ( ) ; j + + )
{ // scansione delle variabili dell'espressione di rvalue
TString var = expr . varname ( j ) ;
if ( var [ 0 ] = = ' # ' )
{ // riferimento ad un campo del form
var . ltrim ( 1 ) ;
TForm_item & fi = find_field ( atoi ( var ) ) ;
expr . setvar ( j , fi . get ( ) ) ; // il valore corrente del campo viene settato nell'espressione
}
else
{ // riferimento ad un campo di file
TFieldref fr = TFieldref ( var , 0 ) ;
int fileno = fr . file ( ) ;
1997-10-20 15:39:13 +00:00
// choose logical file number
fileno = ( fileno = = 0 ) ? ( defaultfile_id > 0 ? defaultfile_id : 0 ) : fileno ;
1997-08-18 14:11:37 +00:00
expr . setvar ( j , fr . read ( form ( ) . relation ( ) - > lfile ( fileno ) . curr ( ) ) ) ; // il valore corrente del campo viene settato nell'espressione
1997-06-16 12:52:23 +00:00
}
1997-08-18 14:11:37 +00:00
}
return expr ;
1997-06-16 12:41:59 +00:00
}
1997-08-18 14:11:37 +00:00
TPrint_section : : TPrint_section ( TForm * f , char st , pagetype pt , TForm_subsection * father )
1995-08-31 15:16:13 +00:00
: _height ( 0 ) , _form ( f ) , _sec_type ( st ) , _page_type ( pt ) , _dirty ( FALSE ) ,
1997-06-16 12:52:23 +00:00
_upsection ( father ) , _repeat_count ( 0 ) , _ofspc ( 0 ) , _ofsvr ( 0 ) , _nfld ( 0 ) , _temp ( 0 ) ,
_columnwise ( FALSE )
1997-06-16 12:41:59 +00:00
{
1997-06-16 12:52:23 +00:00
reset_tabs ( ) ;
1995-12-28 10:31:20 +00:00
}
1994-11-10 14:17:03 +00:00
1994-12-27 14:59:25 +00:00
TPrint_section : : ~ TPrint_section ( )
{
1997-06-16 12:52:23 +00:00
if ( _msk )
{
delete _msk ;
_msk = NULL ;
}
1994-12-27 14:59:25 +00:00
}
1999-04-06 15:34:39 +00:00
TForm_item * TPrint_section : : create_item ( const TString & s )
{
TForm_item * f = NULL ;
if ( s . compare ( " STRINGA " , 2 , TRUE ) = = 0 )
f = new TForm_string ( this ) ; else
if ( s . compare ( " NUMERO " , 2 , TRUE ) = = 0 )
f = new TForm_number ( this ) ; else
if ( s . compare ( " VALUTA " , 2 , TRUE ) = = 0 )
f = new TForm_currency ( this ) ; else
if ( s . compare ( " DATA " , 2 , TRUE ) = = 0 )
f = new TForm_date ( this ) ; else
if ( s . compare ( " LISTA " , 2 , TRUE ) = = 0 )
f = new TForm_list ( this ) ; else
if ( s . compare ( " GRUPPO " , 2 , TRUE ) = = 0 )
f = new TForm_group ( this ) ; else
if ( s . compare ( " SECTION " , 2 , TRUE ) = = 0 )
1999-05-24 13:34:11 +00:00
f = new TForm_subsection ( this ) ; else
if ( s . compare ( " FIGURA " , 2 , TRUE ) = = 0 )
f = new TForm_picture ( this ) ;
1999-04-06 15:34:39 +00:00
return f ;
}
1995-12-14 10:45:17 +00:00
void TPrint_section : : change_field ( int n , TForm_item * f )
1997-06-16 12:41:59 +00:00
{
1997-06-16 12:52:23 +00:00
_item . add ( f , n ) ;
1995-12-14 10:45:17 +00:00
}
void TPrint_section : : insert_field ( int n , TForm_item * f )
1997-06-16 12:41:59 +00:00
{
1997-06-16 12:52:23 +00:00
_item . insert ( f , n ) ;
1995-12-14 10:45:17 +00:00
}
1998-08-25 18:07:30 +00:00
void TPrint_section : : add_field ( TForm_item * f )
1997-06-16 12:41:59 +00:00
{
1997-06-16 12:52:23 +00:00
_item . add ( f ) ;
1997-06-16 12:41:59 +00:00
}
inline int TPrint_section : : subsections ( ) const
{
1997-06-16 12:52:23 +00:00
return _subsections . items ( ) ;
1997-06-16 12:41:59 +00:00
}
inline TForm_subsection * TPrint_section : : subsection ( int n ) const
{
1997-06-16 12:52:23 +00:00
return ( TForm_subsection * ) _subsections . objptr ( n ) ;
1997-06-16 12:41:59 +00:00
}
inline void TPrint_section : : add_subsection ( TForm_subsection * s )
{
1997-06-16 12:52:23 +00:00
_subsections . add ( s ) ;
1995-12-15 11:35:47 +00:00
}
1994-12-27 14:59:25 +00:00
const TPrint_section & TPrint_section : : copy ( const TPrint_section & ps )
{
1997-06-16 12:52:23 +00:00
_msk = ps . _msk ; _height = ps . _height ; _ofspc = ps . _ofspc ;
_ofsvr = ps . _ofsvr ; _nfld = ps . _nfld ; _dirty = ps . _dirty ;
1998-04-30 15:31:34 +00:00
_temp = ps . _temp ; _form = ps . _form ;
_sec_type = ps . _sec_type ; _page_type = ps . _page_type ;
_item = ps . _item ;
// subsections
_upsection = ps . _upsection ; _repeat_count = ps . _repeat_count ; _subsections = ps . _subsections ;
// columnwise
_columnwise = ps . _columnwise ;
1997-06-16 12:52:23 +00:00
for ( int i = 0 ; i < MAXCOLUMNS ; i + + ) _tab [ i ] = ps . _tab [ i ] ;
return ps ;
1994-12-27 14:59:25 +00:00
}
1994-11-10 14:17:03 +00:00
TPrintrow & TPrint_section : : row ( int num )
{
1998-04-30 15:31:34 +00:00
TPrintrow * pr = ( TPrintrow * ) _rows . objptr ( num ) ;
if ( pr = = NULL )
{
pr = new TPrintrow ;
_rows . add ( pr , num ) ;
}
return * pr ;
}
TPrintrow & TPrint_section : : titlerow ( int num )
{
TPrintrow * pr = ( TPrintrow * ) _titlerows . objptr ( num ) ;
1997-06-16 12:52:23 +00:00
if ( pr = = NULL )
{
pr = new TPrintrow ;
1998-04-30 15:31:34 +00:00
_titlerows . add ( pr , num ) ;
1997-06-16 12:52:23 +00:00
}
return * pr ;
1994-11-10 14:17:03 +00:00
}
1995-12-28 10:31:20 +00:00
void TPrint_section : : reset_tabs ( )
{
1997-06-16 12:52:23 +00:00
for ( int i = 0 ; i < MAXCOLUMNS ; i + + )
_tab [ i ] = - 1 ;
1995-12-28 10:31:20 +00:00
}
1997-06-16 12:41:59 +00:00
1995-12-14 10:45:17 +00:00
int TPrint_section : : tab ( int col )
1997-06-16 12:41:59 +00:00
{
1997-06-16 12:52:23 +00:00
int ret = - 1 ;
if ( _columnwise )
{
1997-11-12 15:21:21 +00:00
if ( _tab [ 0 ] = = - 1 & & fields ( ) )
1997-10-20 15:39:13 +00:00
{
1997-11-12 15:21:21 +00:00
_tab [ 0 ] = 2 ;
1997-06-16 12:52:23 +00:00
{
1997-11-12 15:21:21 +00:00
int extraoff = 0 ;
// compute column offset
_nfld = 0 ;
short maxcolreached = 0 , mincolreached = MAXCOLUMNS + 1 ;
for ( word i = 0 ; i < fields ( ) ; i + + )
1997-06-16 12:52:23 +00:00
{
1997-11-12 15:21:21 +00:00
if ( ! field ( i ) . is_section ( ) & & field ( i ) . shown ( ) )
{
const int curr_col = field ( i ) . _x ;
CHECKD ( curr_col > = 0 & & curr_col < MAXCOLUMNS , " Colonna ammessa e non concessa: " , field ( i ) . _x ) ;
_tab [ curr_col ] = field ( i ) . _width + 1 ; // one is for separation
if ( curr_col < mincolreached ) mincolreached = curr_col ;
if ( curr_col > maxcolreached ) maxcolreached = curr_col ;
_nfld + + ;
}
}
// cumulate offsets
if ( _upsection )
{
if ( mincolreached < = MAXCOLUMNS & & mincolreached > 0 )
{
// print section of a subsection: extra offset
extraoff = _upsection - > section ( ) . tab ( mincolreached - 1 ) ;
for ( i = 1 ; i < ( word ) mincolreached ; i + + )
{
_tab [ i ] = _upsection - > section ( ) . _tab [ i ] ;
}
if ( extraoff = = _tab [ mincolreached - 1 ] )
extraoff = 0 ;
else
extraoff - = _upsection - > section ( ) . tab ( 0 ) ;
}
}
int last = 0 ;
for ( i = mincolreached ; i < = ( word ) maxcolreached ; i + + )
{
if ( _tab [ i - 1 ] ! = - 1 )
last = i - 1 ;
if ( _tab [ i ] ! = - 1 )
_tab [ i ] + = _tab [ last ] + extraoff ;
1997-06-16 12:52:23 +00:00
}
}
}
// se manca la colonna, vai a prendere quella immediatamente prima
1997-11-12 15:21:21 +00:00
while ( _tab [ col ] = = - 1 & & col > 0 )
1997-06-16 12:52:23 +00:00
col - - ;
1997-11-12 15:21:21 +00:00
ret = _tab [ col ] ;
1997-06-16 12:52:23 +00:00
}
return ret ;
1997-06-16 12:41:59 +00:00
}
word TPrint_section : : subs_height ( ) const
1995-12-14 10:45:17 +00:00
{
1997-06-16 12:52:23 +00:00
TForm_subsection * fss ;
word h = 0 ;
if ( subsections ( ) )
{
fss = subsection ( 0 ) ;
1998-08-25 18:07:30 +00:00
h = subsection ( 0 ) - > minheight ( ) ;
1998-04-30 15:31:34 +00:00
h + = subsection ( 0 ) - > printsection ( ) . subs_height ( ) ; // ricorsione...
1997-06-16 12:52:23 +00:00
}
return h ;
1997-06-16 12:41:59 +00:00
}
void TPrint_section : : offset ( int & x , int & y )
{
1997-06-16 12:52:23 +00:00
if ( x > = 0 )
{
if ( _columnwise ) x = tab ( x - 1 ) + _ofspc ;
x + = form ( ) . offset_x ( ) ;
}
1997-08-18 14:11:37 +00:00
if ( y > = 0 )
y + = form ( ) . offset_y ( ) + ( _height * _repeat_count ) ;
1995-01-09 16:51:21 +00:00
}
1994-12-20 15:11:26 +00:00
TForm_item * TPrint_section : : parse_item ( const TString & s )
1999-04-06 15:34:39 +00:00
{
TForm_item * f = create_item ( s ) ;
2003-06-06 08:57:05 +00:00
# ifdef DBG
if ( f = = NULL )
2003-06-06 09:04:03 +00:00
yesnofatal_box ( " Tipo di campo del form non riconosciuto: '%s' " , ( const char * ) s ) ;
2003-06-06 08:57:05 +00:00
# endif
1999-04-06 15:34:39 +00:00
return f ;
1994-11-10 14:17:03 +00:00
}
1994-12-20 15:11:26 +00:00
TForm_item * TPrint_section : : parse_item ( TScanner & scanner )
{
1997-06-16 12:52:23 +00:00
return parse_item ( scanner . key ( ) ) ;
1994-12-20 15:11:26 +00:00
}
1997-06-16 12:41:59 +00:00
bool TPrint_section : : parse_head ( TScanner & scanner )
1994-11-10 14:17:03 +00:00
{
1997-06-16 12:52:23 +00:00
_height = scanner . integer ( ) ;
scanner . integer ( ) ; scanner . integer ( ) ; // Eat offset X and Y of Print_section if present
1997-06-16 12:41:59 +00:00
1997-06-16 12:52:23 +00:00
if ( scanner . popkey ( ) = = " CO " ) // COLUMNWISE attribute
_columnwise = TRUE ;
else if ( scanner . key ( ) = = " NO " ) // NORMAL (no COLUMNWISE) attribute
_columnwise = FALSE ;
1997-08-18 14:11:37 +00:00
else
{
1997-06-16 12:52:23 +00:00
if ( section_above ( ) )
_columnwise = section_above ( ) - > _columnwise ;
else
_columnwise = FALSE ;
scanner . push ( ) ;
}
return TRUE ;
1997-06-16 12:41:59 +00:00
}
bool TPrint_section : : parse_body ( TScanner & scanner )
{
1997-06-16 12:52:23 +00:00
while ( scanner . popkey ( ) ! = " EN " )
{
TForm_item * fi = parse_item ( scanner ) ;
if ( fi = = NULL ) return FALSE ;
1994-11-10 14:17:03 +00:00
1997-06-16 12:52:23 +00:00
if ( fi - > parse ( scanner ) )
{
_item . add ( fi ) ;
} else
return FALSE ;
}
return TRUE ;
1997-06-16 12:41:59 +00:00
}
1994-11-10 14:17:03 +00:00
1997-06-16 12:41:59 +00:00
bool TPrint_section : : parse ( TScanner & scanner )
{
1999-01-19 09:15:17 +00:00
if ( parse_head ( scanner ) )
1997-06-16 12:52:23 +00:00
return parse_body ( scanner ) ;
return FALSE ;
1994-11-10 14:17:03 +00:00
}
1997-06-16 12:41:59 +00:00
1995-02-09 14:47:31 +00:00
// Azzera tutte le righe della sezione di stampa
1994-12-20 15:11:26 +00:00
void TPrint_section : : reset ( )
1997-08-18 14:11:37 +00:00
{
1998-04-30 15:31:34 +00:00
for ( int i = _rows . last ( ) ; i > = 0 ; i - - )
1997-08-18 14:11:37 +00:00
{
if ( _height > 0xF000 )
1998-04-30 15:31:34 +00:00
_rows . destroy ( i ) ;
1997-08-18 14:11:37 +00:00
else
row ( i ) . reset ( ) ;
}
1994-12-20 15:11:26 +00:00
}
1997-06-16 12:41:59 +00:00
// Aggiorna tutti i campi
1994-11-10 14:17:03 +00:00
bool TPrint_section : : update ( )
{
1997-06-16 12:52:23 +00:00
bool ok = TRUE ;
1995-02-09 14:47:31 +00:00
1997-06-16 12:52:23 +00:00
reset ( ) ;
for ( word i = 0 ; i < fields ( ) ; i + + )
{
1997-08-18 14:11:37 +00:00
if ( ! field ( i ) . is_section ( ) )
1997-06-16 12:52:23 +00:00
{
const bool esito = field ( i ) . update ( ) ;
if ( ! esito ) ok = FALSE ;
}
}
2003-10-29 14:52:23 +00:00
if ( ok & & _sec_type = = ' B ' & & _page_type = = odd_page )
{
printer ( ) . set_form_name ( _form - > filename ( ) ) ;
}
1997-06-16 12:52:23 +00:00
return ok ;
1997-06-16 12:41:59 +00:00
}
1995-05-29 10:25:10 +00:00
1999-04-06 16:31:40 +00:00
1999-04-26 15:58:05 +00:00
TForm_item * TPrint_section : : exist_field ( short id ) const
{
TForm_item * f = find_field_everywhere ( id , this ) ;
return f ;
}
1995-05-18 14:18:01 +00:00
TForm_item & TPrint_section : : find_field ( short id ) const
{
1999-04-26 15:58:05 +00:00
TForm_item * f = exist_field ( id ) ;
1997-06-16 12:52:23 +00:00
if ( f ) return * f ;
1999-04-06 16:31:40 +00:00
yesnofatal_box ( " Can't find item with id %d " , id ) ;
1997-06-16 12:52:23 +00:00
return field ( 0 ) ;
1997-06-16 12:41:59 +00:00
}
// Ricerca i campi verso l'alto:
// prima la sezione attuale, poi le sezioni sopra
1999-04-06 16:31:40 +00:00
TForm_item * TPrint_section : : find_field_everywhere ( short id , const TPrint_section * starting_section ) const
1997-06-16 12:41:59 +00:00
{
1997-06-16 12:52:23 +00:00
TForm_item * f ;
for ( word i = 0 ; i < fields ( ) ; i + + )
{
f = & field ( i ) ;
1999-04-06 16:31:40 +00:00
if ( f - > id ( ) = = id ) return f ;
1997-06-16 12:52:23 +00:00
}
// look into the section above ("father" )
1999-04-06 16:31:40 +00:00
if ( section_above ( ) & & section_above ( ) ! = starting_section ) {
1997-06-16 12:52:23 +00:00
f = section_above ( ) - > find_field_everywhere ( id , this ) ;
if ( f )
return f ;
}
// look into sections beside ("brothers" )
1997-08-18 14:11:37 +00:00
for ( int j = 0 ; j < subsections ( ) ; j + + )
{
1998-04-30 15:31:34 +00:00
const TPrint_section & bs = subsection ( j ) - > printsection ( ) ;
1999-04-06 16:31:40 +00:00
if ( & bs ! = starting_section ) {
f = bs . find_field_everywhere ( id , this ) ;
1997-06-16 12:52:23 +00:00
if ( f )
return f ;
1999-04-06 16:31:40 +00:00
}
1997-06-16 12:52:23 +00:00
}
return NULL ;
1997-06-16 12:41:59 +00:00
}
1999-04-26 15:58:05 +00:00
TForm_item * TPrint_section : : exist_field ( const char * sec_name ) const
{
TForm_item * f = find_field_everywhere ( sec_name , this ) ;
return f ;
}
1997-06-16 12:41:59 +00:00
TForm_item & TPrint_section : : find_field ( const char * sec_name ) const
{
1999-04-26 15:58:05 +00:00
TForm_item * f = exist_field ( sec_name ) ;
1997-06-16 12:52:23 +00:00
if ( f ) return * f ;
1999-04-26 15:58:05 +00:00
yesnofatal_box ( " Can't find subsection '%s' " , sec_name ) ;
1997-06-16 12:52:23 +00:00
return field ( 0 ) ;
1997-06-16 12:41:59 +00:00
}
// Ricerca i campi verso il basso:
// prima la sezione attuale, poi le sottosezioni
TForm_item * TPrint_section : : find_field_everywhere ( const char * sec_name , const TPrint_section * starting_section ) const
{
1997-06-16 12:52:23 +00:00
// search here
1999-04-06 16:31:40 +00:00
for ( int j = 0 ; j < subsections ( ) ; j + + ) {
1997-06-16 12:52:23 +00:00
const char * n = subsection ( j ) - > name ( ) ;
if ( strcmp ( n , sec_name ) = = 0 )
return subsection ( j ) ;
}
// search down
1999-04-06 16:31:40 +00:00
for ( j = 0 ; j < subsections ( ) ; j + + ) {
1998-04-30 15:31:34 +00:00
TForm_item * it = subsection ( j ) - > printsection ( ) . find_field_everywhere ( sec_name , starting_section ) ;
1997-06-16 12:52:23 +00:00
if ( it )
return it ;
}
return NULL ;
1995-05-18 14:18:01 +00:00
}
1994-11-10 14:17:03 +00:00
///////////////////////////////////////////////////////////
// TForm
///////////////////////////////////////////////////////////
1997-06-16 12:41:59 +00:00
// classe per le informazioni sugli skip dei file del cursore del form
class TForm_skip_info : public TObject
{
protected :
1997-06-16 12:52:23 +00:00
virtual TObject * dup ( ) const ;
1997-06-16 12:41:59 +00:00
public :
1999-04-07 14:41:07 +00:00
bool _match_result ;
int _match_number ;
1997-06-16 12:52:23 +00:00
~ TForm_skip_info ( ) { } ;
TForm_skip_info ( ) ;
1997-06-16 12:41:59 +00:00
} ;
TObject * TForm_skip_info : : dup ( ) const
{
1997-06-16 12:52:23 +00:00
TForm_skip_info * p = new TForm_skip_info ;
1999-04-07 14:41:07 +00:00
p - > _match_result = _match_result ;
p - > _match_number = _match_number ;
1997-06-16 12:52:23 +00:00
return p ;
1997-06-16 12:41:59 +00:00
}
TForm_skip_info : : TForm_skip_info ( )
{
1999-04-07 14:41:07 +00:00
_match_result = FALSE ;
_match_number = 0 ;
1997-06-16 12:41:59 +00:00
}
1997-06-16 12:52:23 +00:00
TForm_editor & TForm : : editor ( ) const
{ return ( TForm_editor & ) main_app ( ) ; }
//
bool TForm : : parse_use ( TScanner & scanner )
{
const int logicnum = scanner . integer ( ) ;
const char * tab = NULL ;
if ( logicnum > 0 )
_relation = new TRelation ( logicnum ) ;
else
{
tab = scanner . pop ( ) ;
_relation = new TRelation ( tab ) ;
}
int key = 1 ; // key number
if ( scanner . popkey ( ) = = " KE " )
key = scanner . integer ( ) ;
else
scanner . push ( ) ;
if ( scanner . popkey ( ) = = " BY " | | scanner . key ( ) = = " FI " ) // file sorted or filtered
{
if ( scanner . key ( ) = = " BY " ) { // "sort BY": user-defined sort
TToken_string ordexpr ( parse_sortexpr ( scanner ) ) ;
_cursor = new TSorted_cursor ( _relation , ordexpr , " " , key ) ;
} else {
TToken_string filter ( parse_filter ( scanner ) ) ;
_cursor = new TCursor ( _relation , filter , key ) ;
}
} else {
scanner . push ( ) ;
_cursor = new TCursor ( _relation , " " , key ) ;
}
if ( scanner . popkey ( ) = = " FI " ) // "FIlter" : sorted defined by the user
{
TToken_string filter ( parse_filter ( scanner ) ) ;
_cursor - > setfilter ( filter ) ;
} else {
scanner . push ( ) ;
}
1995-12-14 14:30:58 +00:00
1997-06-16 12:52:23 +00:00
return TRUE ;
1994-11-10 14:17:03 +00:00
}
bool TForm : : parse_join ( TScanner & scanner )
{
1997-06-16 12:52:23 +00:00
TString16 j ( scanner . pop ( ) ) ; // File or table
1994-11-10 14:17:03 +00:00
1997-06-16 12:52:23 +00:00
int to = 0 ;
if ( scanner . popkey ( ) = = " TO " ) // TO keyword
{
const char * n = scanner . pop ( ) ;
to = name2log ( n ) ;
}
else scanner . push ( ) ;
return parse_join_param ( scanner , _relation , j , to ) ;
1997-06-16 12:41:59 +00:00
}
1994-11-10 14:17:03 +00:00
1997-06-16 12:41:59 +00:00
bool TForm : : parse_join_param ( TScanner & scanner , TRelation * rel , TString16 j , int to )
{
1997-06-16 12:52:23 +00:00
int key = 1 ;
if ( scanner . popkey ( ) = = " KE " )
key = scanner . integer ( ) ;
else scanner . push ( ) ;
1997-06-16 12:41:59 +00:00
1997-06-16 12:52:23 +00:00
int alias = 0 ;
if ( scanner . popkey ( ) = = " AL " )
alias = scanner . integer ( ) ;
else scanner . push ( ) ;
1997-06-16 12:41:59 +00:00
1997-06-16 12:52:23 +00:00
TToken_string exp ( 80 ) ;
if ( scanner . pop ( ) = = " INTO " )
{
exp = parse_filter ( scanner ) ;
}
if ( exp . empty ( ) )
yesnofatal_box ( " JOIN senza espressioni INTO " ) ;
1997-06-16 12:41:59 +00:00
1997-06-16 12:52:23 +00:00
if ( isdigit ( j [ 0 ] ) )
rel - > add ( atoi ( j ) , exp , key , to , alias ) ; // join file
else
rel - > add ( j , exp , key , to , alias ) ; // join table
return TRUE ;
1997-06-16 12:41:59 +00:00
}
bool TForm : : parse_sortedjoin ( TScanner & scanner )
{
1997-06-16 12:52:23 +00:00
TToken_string filter , sortexp ;
TString16 j ( scanner . pop ( ) ) ; // File or table
if ( scanner . popkey ( ) = = " BY " )
{
sortexp = parse_sortexpr ( scanner ) ;
} else scanner . push ( ) ;
if ( scanner . popkey ( ) = = " FI " ) {
filter = parse_filter ( scanner ) ;
} else scanner . push ( ) ;
if ( filter . empty ( ) & & sortexp . empty ( ) )
yesnofatal_box ( " Sort senza espressioni di ordinamento o filtri " ) ;
TRelation * sortrel = new TRelation ( atoi ( j ) ) ;
1999-04-07 14:41:07 +00:00
while ( ok ( ) & & scanner . popkey ( ) ! = " JO " )
1997-06-16 12:52:23 +00:00
{
if ( scanner . key ( ) = = " US " ) // USING keyword
{
TString16 subj ( scanner . pop ( ) ) ; // File or table
parse_join_param ( scanner , sortrel , subj , atoi ( j ) ) ;
} else
1999-04-06 16:31:40 +00:00
yesnofatal_box ( " Token non riconosciuto in SORT:%s " , scanner . key ( ) ) ;
1997-06-16 12:52:23 +00:00
}
int to = 0 ;
if ( scanner . popkey ( ) = = " TO " ) // TO keyword
{
const char * n = scanner . pop ( ) ;
to = name2log ( n ) ;
}
else scanner . push ( ) ;
int key = 1 ;
if ( scanner . popkey ( ) = = " KE " )
key = scanner . integer ( ) ;
else scanner . push ( ) ;
int alias = 0 ;
if ( scanner . popkey ( ) = = " AL " )
alias = scanner . integer ( ) ;
else scanner . push ( ) ;
TToken_string exp ( 80 ) ;
if ( scanner . pop ( ) = = " INTO " )
{
const char * r = scanner . pop ( ) ;
while ( strchr ( r , ' = ' ) ! = NULL )
{
exp . add ( r ) ;
r = scanner . pop ( ) ;
}
}
if ( exp . empty ( ) )
yesnofatal_box ( " JOIN senza espressioni INTO " ) ;
scanner . push ( ) ;
TSortedfile * sf = new TSortedfile ( atoi ( j ) , sortrel , sortexp , filter , key ) ;
_relation - > add ( ( TLocalisamfile * ) sf , exp , key , to , alias , FALSE ) ; // join table
return TRUE ;
1997-06-16 12:41:59 +00:00
}
TToken_string TForm : : parse_filter ( TScanner & scanner )
{
1997-06-16 12:52:23 +00:00
TToken_string filter ;
const char * r = scanner . pop ( ) ;
while ( strchr ( r , ' = ' ) ! = NULL )
{
filter . add ( r ) ;
r = scanner . pop ( ) ;
}
scanner . push ( ) ;
return filter ;
1997-06-16 12:41:59 +00:00
}
TToken_string TForm : : parse_sortexpr ( TScanner & scanner )
{
1997-06-16 12:52:23 +00:00
TToken_string sortexp ;
TToken_string se ( scanner . line ( ) , ' ' ) ;
const char * c ;
while ( c = se . get ( ) )
if ( * c ! = ' \0 ' )
sortexp . add ( c ) ;
return sortexp ;
1995-05-09 09:12:26 +00:00
}
1997-06-16 12:41:59 +00:00
TRelation_description & TForm : : rel_desc ( ) const
{
1997-06-16 12:52:23 +00:00
CHECK ( _rel_desc , " No relation description " ) ;
return * _rel_desc ;
1994-11-10 14:17:03 +00:00
}
1995-05-29 10:25:10 +00:00
bool TForm : : parse_description ( TScanner & scanner )
1995-05-09 09:12:26 +00:00
{
1997-06-16 12:52:23 +00:00
if ( edit_level ( ) > 0 )
{
CHECK ( _rel_desc = = NULL , " Can't parse descriptions two times " ) ;
_rel_desc = new TRelation_description ( * _relation ) ;
}
bool ok = scanner . popkey ( ) = = " DE " ;
if ( ok )
{
if ( edit_level ( ) > 0 )
{
scanner . popkey ( ) ; // eat BEGIN
TFieldref fld ;
while ( scanner . pop ( ) ! = " END " )
{
fld = scanner . token ( ) ;
_rel_desc - > set_cur_file ( fld . file ( ) ) ;
if ( fld . name ( ) = = " * " )
_rel_desc - > file_desc ( scanner . string ( ) ) ;
else
_rel_desc - > set_field_description ( fld . name ( ) , scanner . string ( ) ) ;
}
}
else
{
while ( scanner . line ( ) ! = " END " ) ;
ok = FALSE ;
}
}
else scanner . push ( ) ;
return ok ;
1995-05-29 10:25:10 +00:00
}
void TForm : : print_description ( ostream & out ) const
{
1997-06-16 12:52:23 +00:00
out < < " DESCRIPTION \n BEGIN \n " ;
out < < rel_desc ( ) ;
out < < " END \n " < < endl ;
1995-05-09 09:12:26 +00:00
}
1994-11-10 14:17:03 +00:00
1995-08-31 15:16:13 +00:00
bool TForm : : parse_general ( TScanner & scanner )
{
1997-06-16 12:52:23 +00:00
bool ok = scanner . popkey ( ) = = " GE " ;
if ( ok )
{
while ( scanner . pop ( ) ! = " END " )
{
if ( scanner . key ( ) = = " OF " ) // Offsets
{
_x = scanner . integer ( ) ;
_y = scanner . integer ( ) ;
}
if ( scanner . key ( ) = = " FO " ) // Font name
_fontname = scanner . string ( ) ;
if ( scanner . key ( ) = = " SI " ) // Font size
_fontsize = scanner . integer ( ) ;
if ( scanner . key ( ) = = " CA " ) // Carattere di posizionamento
_char_to_pos = scanner . string ( ) [ 0 ] ;
if ( scanner . key ( ) = = " IN " ) // Riga e colonna del posizionamento iniziale
{
_ipx = scanner . integer ( ) ;
_ipy = scanner . integer ( ) ;
}
if ( scanner . key ( ) = = " FI " ) // Riga e colonna del posizionamento finale
_fpx = scanner . integer ( ) ;
if ( scanner . key ( ) = = " GR " ) // Carattere di fincatura
set_fincatura ( scanner . string ( ) ) ;
1997-08-01 10:53:24 +00:00
if ( scanner . key ( ) = = " PA " ) // Numero di pagine fisso
_npages = scanner . integer ( ) ;
1999-01-19 09:15:17 +00:00
if ( scanner . key ( ) = = " VA " ) // Valuta/Divisa impiegata
2001-04-30 15:04:10 +00:00
{
_curr_codval = scanner . string ( ) ; // DA ELIMINARE
}
1999-01-19 09:15:17 +00:00
1997-06-16 12:52:23 +00:00
extended_parse_general ( scanner ) ; // Parse non-standard parameters
}
} else scanner . push ( ) ;
return ( ok ) ;
1995-08-31 15:16:13 +00:00
}
void TForm : : print_general ( ostream & out ) const
{
1997-06-16 12:52:23 +00:00
out < < " GENERAL \n BEGIN \n " ;
out < < " OFFSET " < < _x < < " " < < _y < < " \n " ;
out < < " FONT " < < " \" " < < _fontname < < " \" \n " ;
out < < " SIZE " < < _fontsize < < " \n " ;
if ( _char_to_pos ! = ' \0 ' )
{
out < < " CARATTERE \" " < < _char_to_pos < < " \" \n " ;
out < < " INIZIO_POS " < < _ipx < < " " < < _ipy < < " \n " ;
out < < " FINE_POS " < < _fpx < < " \n " ;
}
out < < " GRID \" " < < _fink < < " \" \n " ;
out < < " END \n " < < endl ;
1995-08-31 15:16:13 +00:00
}
1995-05-29 10:25:10 +00:00
1996-02-05 19:00:53 +00:00
// @doc EXTERNAL
1996-01-31 17:19:02 +00:00
// @mfunc Controlla se esiste una sezione di stampa
//
// @rdesc Ritorna la <c TPrint_section> trovata o creata
TPrint_section * TForm : : exist (
1997-06-16 12:52:23 +00:00
char s , // @parm Indica in quale parte deve cercare:
//
// @flag F | Tra i footers
// @flag G | Tra gli sfondi
// @flag H | Tra gli headers
// @flag B | Tra i bodies (default)
pagetype t , // @parm Tipo di pagina (vedi <t pagetype>)
bool create ) // @parm Indica se creare la sezione nel caso non esista
{
TArray * a ;
switch ( toupper ( s ) )
{
case ' F ' :
a = & _foot ; break ;
case ' G ' :
a = & _back ; break ;
case ' H ' :
a = & _head ; break ;
default :
a = & _body ; break ;
}
TPrint_section * sec = ( TPrint_section * ) a - > objptr ( t ) ;
if ( sec = = NULL & & create )
{
sec = ( s = = ' G ' ) ? new TGraphic_section ( this , t ) : new TPrint_section ( this , s , t ) ;
a - > add ( sec , t ) ;
}
return sec ;
1994-12-28 11:01:33 +00:00
}
1999-04-26 15:58:05 +00:00
TForm_item * TForm : : exist_field ( char s , pagetype t , short id ) const
{
const TPrint_section * ps = ( ( TForm * ) this ) - > exist ( s , t ) ;
CHECKD ( ps , " Can't find section for field " , id ) ;
return ps - > exist_field ( id ) ;
}
TForm_subsection * TForm : : exist_field ( char s , pagetype t , const char * section ) const
1997-06-16 12:41:59 +00:00
{
1999-04-26 15:58:05 +00:00
const TPrint_section * ps = ( ( TForm * ) this ) - > exist ( s , t ) ;
CHECKS ( ps , " Can't find section for field " , section ) ;
return ( TForm_subsection * ) ps - > exist_field ( section ) ;
}
TForm_item & TForm : : find_field ( char s , pagetype t , short id ) const
{
1997-06-16 12:52:23 +00:00
const TPrint_section * ps = ( ( TForm * ) this ) - > exist ( s , t ) ;
CHECKD ( ps , " Can't find section for field " , id ) ;
return ps - > find_field ( id ) ;
1997-06-16 12:41:59 +00:00
}
1997-08-22 09:16:55 +00:00
TForm_subsection & TForm : : find_field ( char s , pagetype t , const char * section ) const
1997-06-16 12:41:59 +00:00
{
1997-06-16 12:52:23 +00:00
const TPrint_section * ps = ( ( TForm * ) this ) - > exist ( s , t ) ;
CHECKS ( ps , " Can't find section for field " , section ) ;
1997-08-22 09:16:55 +00:00
return ( TForm_subsection & ) ps - > find_field ( section ) ;
1995-05-18 14:18:01 +00:00
}
1994-12-28 11:01:33 +00:00
1995-12-14 08:00:27 +00:00
TPrint_section & TForm : : section ( char s , pagetype pos )
1997-06-16 12:41:59 +00:00
{
1997-06-16 12:52:23 +00:00
TPrint_section * sec = exist ( s , pos , TRUE ) ;
return * sec ;
1994-12-20 15:11:26 +00:00
}
1995-12-14 08:00:27 +00:00
TPrint_section & TForm : : section ( char s , word pagenum )
1997-06-16 12:41:59 +00:00
{
1997-06-16 12:52:23 +00:00
pagetype pt = odd_page ;
if ( pagenum = = 0 & & exist ( s , last_page ) )
pt = last_page ;
if ( pagenum = = 1 & & exist ( s , first_page ) )
pt = first_page ;
if ( pt = = odd_page & & ( pagenum & 0x1 ) = = 0 & & exist ( s , even_page ) )
pt = even_page ;
1997-06-16 12:41:59 +00:00
1997-06-16 12:52:23 +00:00
return section ( s , pt ) ;
1995-12-14 08:00:27 +00:00
}
1996-02-05 19:00:53 +00:00
// @doc EXTERNAL
1996-01-31 17:19:02 +00:00
// @mfunc Rilegge la sezione specificata
//
// @rdesc Ritorna se ce l'ha fatta
bool TForm : : reread (
1997-06-16 12:52:23 +00:00
char sec , // @parm Sezione da rileggere
pagetype p , // @parm Posizione della pagina
bool force ) // @parm Forza rilettura anche se nessun campo e' cambiato
{
TPrint_section * s = exist ( sec , p ) ;
bool ok = force ;
if ( s ! = NULL )
for ( word j = 0 ; j < s - > fields ( ) ; j + + )
ok | = s - > field ( j ) . dirty ( ) ;
if ( s ! = NULL & & ok )
{
s - > destroy_fields ( ) ; // Distrugge tutti gli items...
// ...si posiziona nel file sorgente alla sezione opportuna...
TFilename n ( _name ) ; n . ext ( " frm " ) ;
TScanner scanner ( n ) ;
bool ok = FALSE ;
while ( ! ok )
{
while ( TRUE ) // ...scans searching for a section...
{
const TString & key = scanner . popkey ( ) ;
if ( key = = " SE " | | key = = " " ) // ..if section or end of file...
break ;
}
1999-01-19 09:15:17 +00:00
const char secr = scanner . popkey ( ) [ 0 ] ; // Section name (GRAPH, HEAD, BODY, FOOT)
1997-06-16 12:52:23 +00:00
if ( secr = = ' \0 ' ) break ;
const pagetype pr = char2page ( scanner . popkey ( ) [ 0 ] ) ; // Section type (odd, even, first, last)
1999-01-19 09:15:17 +00:00
if ( secr = = sec & & pr = = p ) ok = TRUE ; // L'ha trovata...
1997-06-16 12:52:23 +00:00
}
// ...riesegue la parse della sezione leggendo dal file sorgente
if ( ok & & s - > parse ( scanner ) )
{
// Legge le modifiche su archivio e poi e' finita.
s - > set_dirty ( FALSE ) ;
TLocalisamfile rprof ( LF_RFORM ) ;
const char sez [ 3 ] = { sec , p + ' 0 ' , ' \0 ' } ;
rprof . zero ( ) ;
rprof . put ( " TIPOPROF " , _name ) ;
rprof . put ( " CODPROF " , _code ) ;
rprof . put ( " SEZ " , sez ) ;
const TRectype filter ( rprof . curr ( ) ) ;
for ( int err = rprof . read ( _isgteq ) ; err = = NOERR & & rprof . curr ( ) = = filter ; err = rprof . next ( ) )
{
const short id = rprof . get_int ( " ID " ) ;
if ( id = = 0 )
{
TPrint_section & se = section ( sec , p ) ;
se . read_from ( rprof . curr ( ) ) ;
}
else
{
TForm_item & item = find_field ( sec , p , id ) ;
item . read_from ( rprof . curr ( ) ) ;
}
}
set_compulsory_specials ( ) ;
}
}
return ok ;
1995-12-23 12:14:50 +00:00
}
1997-06-16 12:41:59 +00:00
1996-01-09 10:37:29 +00:00
///////////////////////////////////////////////////////////
1997-06-16 12:41:59 +00:00
// TForm
1996-01-09 10:37:29 +00:00
///////////////////////////////////////////////////////////
1995-11-24 09:54:06 +00:00
1996-02-05 19:00:53 +00:00
// @doc EXTERNAL
1996-01-31 17:19:02 +00:00
// @mfunc Cambia il formato di tutte le date nel form
//
// @rdesc Ritorna sempre TRUE
bool TForm : : ps_change_date_format (
1997-06-16 12:52:23 +00:00
TPrint_section & s , // @parm Sezione nella quale modificare le date
const char * f ) // @parm Nuovo formato delle date
1996-01-31 17:19:02 +00:00
// @comm Ha le stesse funzioni di <mf TForm::change_date_format>, ma per <c TPrint_section>,
// all'uopo di chiamarla con ricorsiva insistenza
1997-06-16 12:41:59 +00:00
1995-11-24 09:54:06 +00:00
{
1997-06-16 12:52:23 +00:00
for ( word i = 0 ; i < s . fields ( ) ; i + + )
{
TForm_item & fi = s . field ( i ) ;
1997-08-18 14:11:37 +00:00
if ( fi . is_section ( ) )
1997-06-16 12:52:23 +00:00
{
1998-04-30 15:31:34 +00:00
TPrint_section & ps = ( ( TForm_subsection & ) fi ) . printsection ( ) ;
1997-06-16 12:52:23 +00:00
ps_change_date_format ( ps , f ) ;
}
else if ( strcmp ( fi . class_name ( ) , " DATA " ) = = 0 )
{
( ( TForm_date & ) fi ) . set_format ( f ) ;
if ( ! s . dirty ( ) ) s . set_dirty ( ) ;
if ( ! fi . dirty ( ) ) fi . set_dirty ( ) ;
}
}
return TRUE ;
1995-11-24 09:54:06 +00:00
}
1996-01-31 17:19:02 +00:00
1996-02-05 19:00:53 +00:00
// @doc EXTERNAL
1996-01-31 17:19:02 +00:00
// @mfunc Cambia il formato di tutti i numeri nel form
//
// @rdesc Ritorna sempre TRUE
bool TForm : : ps_change_number_format (
1997-06-16 12:52:23 +00:00
TPrint_section & s , // @parm Sezione nella quale modificare i numeri
int w , // @parm Dimensione massima del fomato numerico
int dec , // @parm Numero di decimali
const char * p ) // @parm Picture del nuovo formato
1996-01-31 17:19:02 +00:00
// @comm Ha le stesse funzioni di <mf TForm::change_number_format>, ma per <c TPrint_section>,
// all'uopo di chiamarla con ricorsiva insistenza
1997-06-16 12:41:59 +00:00
{
1997-06-16 12:52:23 +00:00
for ( word i = 0 ; i < s . fields ( ) ; i + + )
{
TForm_item & fi = s . field ( i ) ;
1997-08-18 14:11:37 +00:00
if ( fi . is_section ( ) )
1997-06-16 12:52:23 +00:00
{
1998-04-30 15:31:34 +00:00
TPrint_section & ps = ( ( TForm_subsection & ) fi ) . printsection ( ) ;
1997-06-16 12:52:23 +00:00
ps_change_number_format ( ps , w , dec , p ) ;
}
else if ( strcmp ( fi . class_name ( ) , " NUMERO " ) = = 0 )
{
TForm_number & fn = ( TForm_number & ) fi ;
fn . width ( ) = w ;
fn . set_decimals ( dec ) ;
fn . set_picture ( p ) ;
if ( ! s . dirty ( ) ) s . set_dirty ( ) ;
if ( ! fn . dirty ( ) ) fn . set_dirty ( ) ;
}
}
return TRUE ;
1997-06-16 12:41:59 +00:00
}
void TForm : : change_date_format ( const char * f )
{
1997-06-16 12:52:23 +00:00
char secs [ ] = { " FHGB " } ;
char ptyp [ ] = { " LOEF " } ;
TPrint_section * ps ;
1995-11-24 09:54:06 +00:00
1997-06-16 12:52:23 +00:00
for ( int sc = 0 ; sc < 4 ; sc + + )
for ( int pt = 0 ; pt < 4 ; pt + + )
if ( ( ps = exist ( secs [ sc ] , char2page ( ptyp [ pt ] ) , FALSE ) ) ! = NULL )
ps_change_date_format ( * ps , f ) ;
1995-11-24 09:54:06 +00:00
}
1994-12-20 15:11:26 +00:00
1995-11-24 09:54:06 +00:00
void TForm : : change_number_format ( int w , int dec , const char * p )
{
1997-06-16 12:52:23 +00:00
char secs [ ] = { " FHGB " } ;
char ptyp [ ] = { " LOEF " } ;
TPrint_section * ps ;
1997-06-16 12:41:59 +00:00
1997-06-16 12:52:23 +00:00
for ( int sc = 0 ; sc < 4 ; sc + + )
for ( int pt = 0 ; pt < 4 ; pt + + )
if ( ( ps = exist ( secs [ sc ] , char2page ( ptyp [ pt ] ) , FALSE ) ) ! = NULL )
ps_change_number_format ( * ps , w , dec , p ) ;
1995-11-24 09:54:06 +00:00
}
1996-02-05 19:00:53 +00:00
// @doc EXTERNAL
1997-06-16 12:41:59 +00:00
1996-01-31 17:19:02 +00:00
// @mfunc Effettua l'update della sezione grafica background
//
// @rdesc Ritorna la lunghezza della pagina da stampare
word TForm : : set_background (
1997-06-16 12:52:23 +00:00
word p , // @parm Numero pagina
bool u ) // @parm Indica se aggiornare lo sfondo nella stampante corrente
1996-01-31 17:19:02 +00:00
// @xref <mf TForm::set_header> <mf TForm::set_body> <mf TForm::set_footer>
1995-03-22 09:07:04 +00:00
{
1997-06-16 12:52:23 +00:00
word len = 0 ;
1997-06-16 12:41:59 +00:00
1997-06-16 12:52:23 +00:00
if ( u & & _back . items ( ) )
{
TPrint_section & graph = section ( ' G ' , p ) ;
graph . update ( ) ;
len = printer ( ) . formlen ( ) ;
}
1997-06-16 12:41:59 +00:00
1997-06-16 12:52:23 +00:00
return len ;
1995-03-22 09:07:04 +00:00
}
1994-12-28 11:01:33 +00:00
1996-02-05 19:00:53 +00:00
// @doc EXTERNAL
1996-01-31 17:19:02 +00:00
// @mfunc Effettua l'update della sezione header
//
// @rdesc Ritorna l'altezza dell'header settato
word TForm : : set_header (
1997-06-16 12:52:23 +00:00
word p , // @parm Numero pagina
1997-08-01 10:53:24 +00:00
bool u ) // @parm Indica se cambiare l'eventuale header o solo ritornare l'altezza
1996-01-31 17:19:02 +00:00
// @xref <mf TForm::set_background> <mf TForm::set_body> <mf TForm::set_footer>
1997-06-16 12:41:59 +00:00
{
1997-06-16 12:52:23 +00:00
TPrinter & pr = printer ( ) ;
pr . resetheader ( ) ;
1994-11-10 14:17:03 +00:00
1997-06-16 12:52:23 +00:00
TPrint_section & head = section ( ' H ' , p ) ;
1997-06-16 12:41:59 +00:00
1997-06-16 12:52:23 +00:00
if ( u ) head . update ( ) ;
else
{
head . reset ( ) ;
pr . headerlen ( head . height ( ) ) ;
}
1997-06-16 12:41:59 +00:00
1997-06-16 12:52:23 +00:00
for ( word j = 0 ; j < head . height ( ) ; j + + )
pr . setheaderline ( j , head . row ( j ) ) ;
1997-06-16 12:41:59 +00:00
1997-06-16 12:52:23 +00:00
return head . height ( ) ;
1994-11-10 14:17:03 +00:00
}
1996-02-05 19:00:53 +00:00
// @doc EXTERNAL
1997-06-16 12:41:59 +00:00
// @mfunc Effettua l'update della sezione body e la sua stampa su Printer
1996-01-31 17:19:02 +00:00
//
// @rdesc Ritorna l'altezza del body settato
word TForm : : set_body (
1997-06-16 12:52:23 +00:00
word p , // @parm Numero pagina
bool u ) // @parm Indica se effettuare l'update (TRUE) o fare il reset (FALSE)
1996-01-31 17:19:02 +00:00
// @xref <mf TForm::set_background> <mf TForm::set_header> <mf TForm::set_footer>
1994-12-20 15:11:26 +00:00
{
1997-06-16 12:52:23 +00:00
TPrint_section & body = section ( ' B ' , p ) ;
1994-12-28 11:01:33 +00:00
1998-04-30 15:31:34 +00:00
if ( u ) body . update_and_print ( printmode_normal ) ;
1997-06-16 12:52:23 +00:00
else body . reset ( ) ;
1997-06-16 12:41:59 +00:00
1997-06-16 12:52:23 +00:00
return body . height ( ) ;
1997-06-16 12:41:59 +00:00
}
TPrint_section * TPrint_section : : section_above ( ) const
1997-07-30 12:36:24 +00:00
{
if ( _upsection )
1997-06-16 12:52:23 +00:00
return & _upsection - > section ( ) ;
return NULL ;
1997-06-16 12:41:59 +00:00
}
// @doc EXTERNAL
// @mfunc Compone e stampa tutte le righe della sezione (valida in caso di BODY)
1998-04-30 15:31:34 +00:00
// ritorna se c'e' stata una valutazione
bool TPrint_section : : update_and_print ( const sec_print_mode show_fields , bool new_page )
1997-06-16 12:41:59 +00:00
{
1998-04-30 15:31:34 +00:00
bool ok = FALSE ;
TPrinter & pr = printer ( ) ;
word last_printed_row = 0 ;
1997-06-16 12:41:59 +00:00
1998-04-30 15:31:34 +00:00
reset ( ) ;
if ( show_fields = = printmode_normal
& & pr . current_row ( ) > pr . headersize ( ) + 1
& & new_page )
{
pr . formfeed ( ) ;
}
int repeat_count = 0 ; // numero di sottosezioni stampate o numero di stampe della stessa sottosezione
int last_hpos = 0 ;
for ( word i = 0 ; i < fields ( ) ; i + + )
{
if ( ! field ( i ) . is_section ( ) )
1997-06-16 12:52:23 +00:00
{
1998-04-30 15:31:34 +00:00
// compose rows using "simple" fields
field ( i ) . update ( ) ;
}
else
{
last_hpos = min ( word ( field ( i ) . y ( ) - 1 ) , height ( ) ) ;
// found a subsection
TForm_subsection & ss = ( TForm_subsection & ) field ( i ) ;
last_printed_row = print_rows ( show_fields , last_printed_row , last_hpos ) ;
1997-08-18 14:11:37 +00:00
1998-04-30 15:31:34 +00:00
// process subsection
1998-08-25 18:07:30 +00:00
if ( ss . enabled ( ) )
1998-04-30 15:31:34 +00:00
ok | = ss . print_body ( show_fields ) ;
}
} // ... loop for each field
const word hgt = height ( ) ;
1998-08-25 18:07:30 +00:00
1998-04-30 15:31:34 +00:00
if ( print_rows ( show_fields , last_printed_row , hgt ) > 0 & & show_fields = = printmode_normal )
ok = TRUE ;
// print footers
if ( subsection_above ( ) ! = NULL & & ! subsection_above ( ) - > is_title ( ) & & ok )
subsection_above ( ) - > print_qtitle ( ) ;
return ok ;
}
1997-08-18 14:11:37 +00:00
1998-05-27 13:41:48 +00:00
word TPrint_section : : print_rows ( const sec_print_mode show_fields , word from , word to )
1998-04-30 15:31:34 +00:00
{
TPrinter & pr = printer ( ) ;
if ( show_fields ! = printmode_noprint & & to > from )
1997-06-16 12:52:23 +00:00
{
1998-04-30 15:31:34 +00:00
// print preceeding rows:are all those rows which have Y coord <= than subsection's Y
if ( subsection_above ( ) ! = NULL & & ! subsection_above ( ) - > is_title ( ) )
{
// find some to print: print titles.....
if ( show_fields = = printmode_normal )
subsection_above ( ) - > print_titles ( ) ;
}
if ( pr . current_row ( ) > pr . headersize ( ) + 1 )
if ( ( to - from + 1 ) > pr . rows_left ( ) & & show_fields = = printmode_normal )
pr . formfeed ( ) ;
for ( word j = from ; j < to ; j + + )
switch ( show_fields )
{
case printmode_normal :
pr . print ( row ( j ) ) ; break ; // print to printer
default :
_titlerows . add ( row ( j ) , j ) ; break ; // print to buffer
}
return to ;
1997-06-16 12:52:23 +00:00
}
1998-04-30 15:31:34 +00:00
return from ;
1994-12-20 15:11:26 +00:00
}
1994-11-10 14:17:03 +00:00
1996-02-05 19:00:53 +00:00
// @doc EXTERNAL
1996-01-31 17:19:02 +00:00
// @mfunc Effettua l'update della sezione footer
//
// @rdesc Ritorna l'altezza del footer settato
word TForm : : set_footer (
1997-06-16 12:52:23 +00:00
word p , // @parm Numero pagina
bool u ) // @parm Indica se cambiare l'eventuale footer corrente!!!
1996-01-31 17:19:02 +00:00
// @xref <mf TForm::set_background> <mf TForm::set_header> <mf TForm::set_body>
1994-11-10 14:17:03 +00:00
{
1997-06-16 12:52:23 +00:00
TPrinter & pr = printer ( ) ;
pr . resetfooter ( ) ;
1994-11-10 14:17:03 +00:00
1997-06-16 12:52:23 +00:00
TPrint_section & foot = section ( ' F ' , p ) ;
1997-06-16 12:41:59 +00:00
1997-06-16 12:52:23 +00:00
if ( u ) foot . update ( ) ;
else
{
foot . reset ( ) ;
pr . footerlen ( foot . height ( ) ) ;
}
1994-11-10 14:17:03 +00:00
1997-06-16 12:52:23 +00:00
for ( word j = 0 ; j < foot . height ( ) ; j + + )
pr . setfooterline ( j , foot . row ( j ) ) ;
1997-06-16 12:41:59 +00:00
1997-06-16 12:52:23 +00:00
return foot . height ( ) ;
1994-12-20 15:11:26 +00:00
}
1994-11-10 14:17:03 +00:00
1994-12-20 15:11:26 +00:00
void TForm : : header_handler ( TPrinter & p )
1999-04-06 15:34:39 +00:00
{
TForm & f = * _cur_form ;
if ( f . firstpage_is_lastpage ( ) )
1997-09-08 07:44:12 +00:00
{
1999-04-06 15:34:39 +00:00
f . set_background ( 1 , TRUE ) ;
f . set_header ( 1 , TRUE ) ;
f . set_footer ( 0 , FALSE ) ;
1997-09-08 07:44:12 +00:00
}
else
{
1999-04-06 15:34:39 +00:00
const word page = f . page ( p ) ;
f . set_background ( page , TRUE ) ;
f . set_header ( page , TRUE ) ;
f . set_footer ( page , FALSE ) ;
1997-08-01 10:53:24 +00:00
}
1994-12-20 15:11:26 +00:00
}
void TForm : : footer_handler ( TPrinter & p )
{
1999-04-06 15:34:39 +00:00
TForm & f = * _cur_form ;
if ( f . firstpage_is_lastpage ( ) )
{
f . set_footer ( 0 , TRUE ) ;
}
else
{
const word currp = f . page ( p ) ;
f . set_footer ( currp , TRUE ) ;
1997-08-01 10:53:24 +00:00
if ( currp )
1999-04-06 15:34:39 +00:00
f . set_header ( f . next_page ( p ) , FALSE ) ;
1997-08-01 10:53:24 +00:00
}
}
// @doc EXTERNAL
// @mfunc Ritorna se la prima pagina coincide conl'ultima
bool TForm : : firstpage_is_lastpage ( ) const
{
return _first_eq_last ;
1997-06-16 12:41:59 +00:00
}
1994-12-20 15:11:26 +00:00
1996-02-05 19:00:53 +00:00
// @doc EXTERNAL
1994-12-20 15:11:26 +00:00
1996-01-31 17:19:02 +00:00
// @mfunc Ritorna il numero di pagina correntemente in stampa
//
// @rdesc Se <md _TForm::lastpage> e' TRUE (sta stampando l'ultima pagina)
1997-08-01 10:53:24 +00:00
// ritorna 0, altrimenti ritorna il numero della pagina corrente da stampare
1996-01-31 17:19:02 +00:00
// (chiam <mf TPrinter::getcurrentepage>).
word TForm : : page (
1997-06-16 12:52:23 +00:00
const TPrinter & p ) const // @parm Operazione corrente di stampa
1994-12-20 15:11:26 +00:00
{
1997-08-01 10:53:24 +00:00
return _lastpage | | fixed_pages ( ) & & p . getcurrentpage ( ) = = _npages ? 0 : p . getcurrentpage ( ) ;
}
word TForm : : next_page (
const TPrinter & p ) const // @parm Operazione corrente di stampa
{
return _lastpage | | fixed_pages ( ) & & p . getcurrentpage ( ) + 1 = = _npages ? 0 : p . getcurrentpage ( ) + 1 ;
1997-06-16 12:41:59 +00:00
}
1995-10-27 08:28:13 +00:00
1996-02-05 19:00:53 +00:00
// @doc EXTERNAL
1996-01-31 17:19:02 +00:00
// @mfunc Effettua il posizionamento manuale del modulo
1995-10-27 08:28:13 +00:00
void TForm : : arrange_form ( )
1996-01-31 17:19:02 +00:00
1997-06-16 12:41:59 +00:00
// @comm Nota: siccome si scrive direttamente sulla porta, sarebbe necessario
// mandare una stringa di reset alla stampante, o per lo meno far si' che
1996-01-31 17:19:02 +00:00
// ogni volta che si fa il posizionamento il font col quale scrive sia sempre
// lo stesso. Tutto cio' non e' possibile con la generica solo testo, o meglio
// ad ogni stampa col posizionamento e' necessario che la stampante sia resettata.
1997-06-16 12:41:59 +00:00
// <nl>Riassumendo, come regola generale, i posizionamenti devono essere fatti con il
// font di default della stampante (tipicamente 10 cpi). Accade pero' (con la generica
1996-01-31 17:19:02 +00:00
// solo testo) che rimanga settato l'ultimo font, di conseguenza quando si effettua una
1997-06-16 12:41:59 +00:00
// seconda stampa con posizionamento, stampera' tali caratteri in 17"! Per questo
1996-01-31 17:19:02 +00:00
// motivo e' necessario settare a 17 cpi, almeno la prima volta, la stampante!.
1997-06-16 12:41:59 +00:00
// <nl>Quindi, per ovviare a tutto cio, visto che <mf TForm::arange_form> ha senso solo su
// stampanti ad aghi, che le stampanti ad aghi possono andare in emulazione EPSON o IBM,
1996-01-31 17:19:02 +00:00
// che il codice per settare il font draft 17cpi e' lo stesso sia per EPSON che IBM
// CHR(15), allora prima del posizionamento scrivo il chr(15) sulla stampante!
1997-06-16 12:41:59 +00:00
{
2003-03-27 12:14:51 +00:00
/*
1997-06-16 12:52:23 +00:00
int i , x ;
TString str_pos ;
TMask m ( " ba2100c " ) ;
1997-06-16 12:41:59 +00:00
1997-06-16 12:52:23 +00:00
// _ipy viene assunto uguale per entrambi i posizionamneti
str_pos = " \017 " ; // Questo e' 15 in ottale...
for ( i = 1 ; i < _ipy ; i + + ) str_pos < < " \n " ;
1999-04-16 12:02:04 +00:00
os_open_spool_row ( printer ( ) . printername ( ) ) ;
os_spool_row ( str_pos ) ;
os_close_spool_row ( ) ;
1997-06-16 12:52:23 +00:00
str_pos = " " ; //Azzera la stringa di posizionamento
for ( i = 1 ; i < _ipx ; i + + ) str_pos < < " " ; //Aggiunge gli spazi necessari...
if ( _ipx > 0 )
str_pos < < _char_to_pos ; // aggiunge il primo carattere di posizionamento...
x = _fpx - _ipx ; // calcola quanti spazi aggiungere...
for ( i = 1 ; i < x ; i + + ) str_pos < < " " ;
if ( _fpx > 0 )
str_pos < < _char_to_pos ; // aggiunge il secondo carattere di posizionamento
str_pos < < ' \r ' ;
1996-02-26 13:25:34 +00:00
// TString bspc; bspc.fill('\b',str_pos.len()); // Questi servono per tornare indietro...
1997-06-16 12:52:23 +00:00
do
{
1999-04-16 12:02:04 +00:00
os_open_spool_row ( printer ( ) . printername ( ) ) ;
1998-02-24 10:37:28 +00:00
os_spool_row ( str_pos ) ;
1999-04-16 12:02:04 +00:00
os_close_spool_row ( ) ;
1997-06-16 12:52:23 +00:00
} while ( m . run ( ) = = K_ESC ) ; // cicla sulla stampa posizionamento...
1999-01-19 09:15:17 +00:00
printer ( ) . set_offset ( - ( _ipy - 1 ) , printer ( ) . get_column_offset ( ) ) ;
2003-03-27 12:14:51 +00:00
*/
1995-10-27 08:28:13 +00:00
}
1994-12-20 15:11:26 +00:00
long TForm : : records ( ) const
1997-06-16 12:41:59 +00:00
{
1997-06-16 12:52:23 +00:00
const long r = cursor ( ) ? cursor ( ) - > items ( ) : 0 ;
return r ;
1997-06-16 12:41:59 +00:00
}
1995-12-15 11:35:47 +00:00
1996-02-05 19:00:53 +00:00
// @doc EXTERNAL
1996-01-31 17:19:02 +00:00
// @mfunc Genera automaticamente la sezione grafica con colonne fincate
//
// @rdesc Ritorna FALSE se non c'e' il body per quella pagina
bool TForm : : genera_fincatura (
1997-06-16 12:52:23 +00:00
pagetype p , // @parm Posizione della pagina (vedi <t pagetype>)
int y1 , // @parm Prima y per le righe verticali
int y2 , // @parm Ultima y per le righe verticali
const int * rows ) // @parm Array di posizioni riga con 0 per finire
{
TPrint_section * body = exist ( ' B ' , p ) ;
if ( body = = NULL ) return FALSE ;
body - > reset_tabs ( ) ;
bool istemp = exist ( ' G ' , p ) = = NULL ;
TGraphic_section * grs = ( TGraphic_section * ) exist ( ' G ' , p , TRUE ) ;
grs - > temp ( ) = istemp ;
int j = 0 , start = 999 , end = 0 , wlast = 0 ;
int cols [ MAXCOLUMNS ] ;
for ( word k = grs - > fields ( ) ; k > 0 ; k - - )
if ( grs - > field ( k - 1 ) . temp ( ) )
grs - > destroy_field ( k - 1 ) ;
for ( int i = 0 ; i < ( int ) body - > fields ( ) ; i + + )
{
TForm_item & f = body - > field ( i ) ;
1997-08-18 14:11:37 +00:00
if ( ! f . shown ( ) | | f . is_section ( ) )
continue ;
1997-06-16 12:52:23 +00:00
int x = f . x ( ) ;
if ( x < start ) start = x ;
if ( x > end ) { end = x ; wlast = f . width ( ) ; }
cols [ j + + ] = f . finkl ( ) ? - x : x ;
}
// inner lines
for ( i = 0 ; i < j ; i + + )
{
if ( cols [ i ] ! = start & & cols [ i ] > 0 )
{
TForm_line * l = new TForm_line ( grs ) ;
l - > set_x ( cols [ i ] - 1 ) ;
l - > y ( ) = ( word ) y1 ;
l - > id ( ) = - 1 ;
l - > width ( ) = 1 ;
l - > height ( ) = ( int ) ( y2 - y1 + 1 ) ;
l - > set ( " @R " ) ;
l - > temp ( ) = TRUE ;
grs - > add_field ( l ) ;
}
}
// box around
if ( start ! = 999 & & end ! = 0 )
{
TForm_box * l = new TForm_box ( grs ) ;
l - > set_x ( start - 1 ) ;
l - > y ( ) = ( word ) y1 ;
l - > id ( ) = - 1 ;
l - > width ( ) = ( int ) ( end + wlast - start + 2 ) ;
l - > height ( ) = ( int ) ( y2 - y1 + 1 ) ;
l - > set ( " @B@R " ) ;
l - > temp ( ) = TRUE ;
grs - > add_field ( l ) ;
}
// horizontal lines
if ( start ! = 999 & & end ! = 0 )
for ( i = 0 ; rows [ i ] ; i + + )
{
TForm_line * l = new TForm_line ( grs ) ;
l - > set_x ( start - 1 ) ;
l - > y ( ) = ( word ) rows [ i ] ;
l - > id ( ) = - 1 ;
l - > width ( ) = ( int ) ( end + wlast - start + 2 ) ;
l - > height ( ) = 1 ;
l - > set ( " @R " ) ;
l - > temp ( ) = TRUE ;
grs - > add_field ( l ) ;
}
return TRUE ;
1994-11-10 14:17:03 +00:00
}
1996-02-05 19:00:53 +00:00
// @doc EXTERNAL
1996-01-31 17:19:02 +00:00
// @mfunc Genera le righe di intestazione colonna alla riga indicata, vale per COLUMNWISE
//
// @rdesc Ritorna FALSE se non esiste body (o non e' COLUMNWISE) o se non esiste l'header
bool TForm : : genera_intestazioni (
1997-12-11 15:40:11 +00:00
pagetype p , // @parm Posizione della pagina (vedi <t pagetype>)
1997-06-16 12:52:23 +00:00
short y ) // @parm Riga dell'header in cui vanno inserite
1996-01-31 17:19:02 +00:00
// @comm I form_items di intestazione vengono aggiunti alla sezione header di tipo <p p> con ID -1
1996-01-03 15:51:25 +00:00
{
1997-06-16 12:52:23 +00:00
TPrint_section * body = exist ( ' B ' , p ) ;
1997-08-18 14:11:37 +00:00
if ( body = = NULL | | ! body - > columnwise ( ) )
return FALSE ;
1997-06-16 12:52:23 +00:00
TPrint_section * header = exist ( ' H ' , p ) ;
1997-08-18 14:11:37 +00:00
if ( header = = NULL )
return FALSE ;
1997-06-16 12:52:23 +00:00
body - > reset_tabs ( ) ;
1997-08-18 14:11:37 +00:00
// Elimina eventuali campi temporanei precedenti
for ( int k = header - > fields ( ) - 1 ; k > = 0 ; k - - )
if ( header - > field ( k ) . temp ( ) )
header - > destroy_field ( k ) ;
1997-06-16 12:52:23 +00:00
const word items = body - > fields ( ) ;
1997-10-27 10:23:23 +00:00
TForm_string * s ;
1997-06-16 12:52:23 +00:00
for ( word j = 0 ; j < items ; j + + )
{ // Scans all body items to print, and append header items...
TForm_item & fi = body - > field ( j ) ;
1997-08-18 14:11:37 +00:00
if ( ! fi . shown ( ) | | fi . is_section ( ) )
1997-06-16 12:52:23 +00:00
continue ;
1997-10-27 10:23:23 +00:00
char align = ' \0 ' ;
if ( fi . col_head ( ) [ 0 ] = = ' @ ' )
{
switch ( fi . col_head ( ) [ 1 ] )
{
case ' C ' : // centered
case ' c ' :
align = ' c ' ;
break ;
case ' R ' : // right just
case ' r ' :
align = ' r ' ;
break ;
default : // left just
align = ' l ' ;
break ;
}
}
1997-12-11 15:40:11 +00:00
1997-10-27 10:23:23 +00:00
// Paragraph_string has as many items as lines needed...
1997-12-11 15:40:11 +00:00
TParagraph_string prompts ( fi . col_head ( ) . mid ( align ? 2 : 0 ) , fi . width ( ) ) ;
TString p ;
1997-10-27 10:23:23 +00:00
for ( int c = 0 ; c < prompts . items ( ) ; c + + )
{
1997-12-11 15:40:11 +00:00
p = prompts . get ( c ) ;
1997-10-27 10:23:23 +00:00
switch ( align )
{
2001-04-30 15:04:10 +00:00
case ' c ' :
p . center_just ( fi . width ( ) ) ;
break ;
case ' r ' :
p . right_just ( fi . width ( ) ) ;
break ;
default :
break ;
1997-10-27 10:23:23 +00:00
}
s = new TForm_string ( header ) ;
s - > id ( ) = - 1 ;
s - > set_x ( fi . x ( ) ) ;
s - > y ( ) = y + c ;
s - > set_prompt ( p ) ;
s - > temp ( ) = TRUE ;
header - > add_field ( s ) ;
}
1997-06-16 12:52:23 +00:00
}
return TRUE ;
1996-01-03 15:51:25 +00:00
}
1996-01-31 17:19:02 +00:00
/*
void TForm : : remove_temp_items ( char sec , pagetype p )
1997-06-16 12:41:59 +00:00
{
1997-06-16 12:52:23 +00:00
TPrint_section * s = exist ( sec , p ) ;
if ( s ! = NULL )
{
const word items = s - > fields ( ) ;
for ( word j = 0 ; j < items ; j + + )
{
if ( s - > field ( j ) . temp ( ) )
s - > destroy_field ( j , FALSE ) ;
}
s - > field_array ( ) . pack ( ) ;
}
1996-01-31 17:19:02 +00:00
}
void TForm : : put_examples ( char sez , pagetype p )
{
1997-06-16 12:52:23 +00:00
TPrint_section * s = exist ( sez , p ) ;
if ( s ! = NULL )
{
const word items = s - > fields ( ) ;
for ( word i = 0 ; i < items ; i + + )
{
TForm_item & fi = s - > field ( i ) ;
if ( fi . fields ( ) ! = 0 ) continue ;
if ( fi . memo ( ) )
fi . set ( fi . memo_info ( ) ) ;
else
if ( fi . prompt ( ) . empty ( ) )
{
if ( fi . class_name ( ) = = " DATA " )
{
const TDate d ( TODAY ) ;
fi . set ( d ) ;
}
else
if ( fi . class_name ( ) = = " NUMERO " )
{
fi . set_prompt ( fi . example ( ) ) ;
fi . temp ( ) = TRUE ;
}
else
fi . set ( fi . key ( ) ) ;
}
}
}
1996-01-31 17:19:02 +00:00
}
void TForm : : remove_examples ( char sez , pagetype p )
{
1997-06-16 12:52:23 +00:00
TPrint_section * s = exist ( sez , p ) ;
if ( s ! = NULL )
{
const word items = s - > fields ( ) ;
for ( word i = 0 ; i < items ; i + + )
{
TForm_item & fi = s - > field ( i ) ;
if ( fi . fields ( ) ! = 0 ) continue ;
if ( fi . memo ( ) )
fi . set ( " " ) ;
else
if ( fi . class_name ( ) = = " NUMERO " & & fi . temp ( ) )
{
fi . set_prompt ( " " ) ;
fi . temp ( ) = FALSE ;
}
}
}
1996-01-31 17:19:02 +00:00
}
*/
1999-04-06 15:34:39 +00:00
bool TForm : : has_subsections ( )
{
const TPrint_section & b = section ( ' B ' , odd_page ) ;
return b . subsections ( ) > 0 ;
}
1996-02-05 19:00:53 +00:00
// @doc EXTERNAL
1996-01-31 17:19:02 +00:00
// @mfunc Stampa gli items da <p form> a <p to>
//
// @rdesc Ritorna se ha effettuato correttamente la stampa
bool TForm : : print (
1997-06-16 12:52:23 +00:00
long from , // @parm Primo item da stampare (default 0l)
long to ) // @parm Ultimo da stampare (se <lt>0 stampa fino alla fine del file, default -1l)
1994-11-10 14:17:03 +00:00
1997-08-01 10:53:24 +00:00
// @comm Se i parametri di posizionamento sono settati e cosi' pure gli offset genera un <f error_box>.
{
_cur_form = this ;
if ( ( _char_to_pos ! = ' \0 ' | | ( ( _ipx + _ipy + _fpx ) ! = 0 ) ) & & // Se i parametri di posizionamento sono settati e
( _x ! = 0 | | _y ! = 0 ) ) // cosi' pure gli offset genera un errore.
{
error_box ( " Non e' possibile settare contemporaneamente gli offset "
" e i parametri di posizionamento del modulo. " ) ;
return FALSE ;
}
TPrinter & pr = printer ( ) ;
if ( _frompage ) pr . set_from_page ( _frompage ) ;
if ( _topage ) pr . set_to_page ( _topage ) ;
if ( _char_to_pos ! = ' \0 ' | | ( _ipx + _ipy + _fpx ) ! = 0 ) // Effettua il posizionamento del form...
{
if ( _arrange & & pr . printtype ( ) = = winprinter )
arrange_form ( ) ;
}
else
pr . set_offset ( _y , _x ) ;
pr . setheaderhandler ( header_handler ) ; // Setta handlers
pr . setfooterhandler ( footer_handler ) ;
if ( ! pr . is_generic ( ) )
{
for ( pagetype t = odd_page ; t < = last_page ; t = pagetype ( t + 1 ) )
{
if ( height ( t ) > ( word ) pr . formlen ( ) )
{
1999-01-19 09:15:17 +00:00
TString s ( " La lunghezza totale della sezione " ) ;
1997-08-01 10:53:24 +00:00
switch ( t )
{
case odd_page :
s < < " standard " ; break ;
case even_page :
s < < " pagine pari " ; break ;
case first_page :
s < < " prima pagina " ; break ;
case last_page :
s < < " ultima pagina " ; break ;
default :
break ;
}
s < < " eccede la lunghezza reale del foglio. " ;
message_box ( s ) ;
}
}
}
else
{
pr . formlen ( height ( ) ) ;
}
1998-08-25 18:07:30 +00:00
if ( _fontsize ! = 0 )
pr . set_char_size ( _fontsize ) ; // Set font name and size
if ( _fontname . not_empty ( ) )
pr . set_fontname ( _fontname ) ; // according to current form
1997-08-01 10:53:24 +00:00
const bool was_open = pr . isopen ( ) ;
set_last_page ( FALSE ) ; // non e' l'ultima pagina
set_background ( 1 , TRUE ) ;
if ( ! was_open & & ! pr . open ( ) )
return FALSE ;
do_events ( ) ;
long lastrec = records ( ) - 1 ;
if ( to < 0 ) to = lastrec ;
// controlla i casi di stampa
_first_eq_last = FALSE ;
1999-04-06 15:34:39 +00:00
if ( ! fixed_pages ( ) & & ! has_subsections ( ) & & set_body ( 1 , FALSE ) * word ( to - from + 1 ) < = pr . formlen ( ) - set_header ( 1 , FALSE ) - set_footer ( 0 , FALSE ) )
1997-08-01 10:53:24 +00:00
// tutta la stampa sta in una pagina
_first_eq_last = TRUE ;
// if (to == lastrec) to--; // l'ultima pagina <20> gestita come caso particolare
bool ok = TRUE ;
for ( long i = from ; i < = to & & ok ; )
{
1999-04-06 15:34:39 +00:00
if ( pr . frozen ( ) )
break ;
1997-12-11 15:40:11 +00:00
if ( from < 0 )
to = from ;
else if ( cursor ( ) )
{
* cursor ( ) = i ;
match_result ( ) ;
}
1997-08-01 10:53:24 +00:00
if ( pr . current_row ( ) > pr . headersize ( ) + 1 )
{
const word h = set_body ( page ( pr ) , FALSE ) ;
1997-12-11 15:40:11 +00:00
if ( h > pr . rows_left ( ) )
{
1997-08-01 10:53:24 +00:00
pr . formfeed ( ) ;
// quanto resta da stampare sta nell'ultima pagina
1999-04-06 15:34:39 +00:00
if ( ! fixed_pages ( ) & & ! has_subsections ( ) & & set_body ( 0 , FALSE ) * word ( to - i + 1 ) < = pr . formlen ( ) - set_header ( 1 , FALSE ) - set_footer ( 0 , FALSE ) )
1997-08-01 10:53:24 +00:00
{
1998-01-09 16:14:46 +00:00
while ( i < = to & & from > = 0 ) // stampa l'ultima pagina
1997-08-01 10:53:24 +00:00
{
set_last_page ( TRUE ) ;
set_background ( 0 , TRUE ) ;
set_header ( 0 , TRUE ) ;
1998-01-09 16:14:46 +00:00
if ( cursor ( ) )
{
1997-08-01 10:53:24 +00:00
* cursor ( ) = i ;
set_body ( 0 , TRUE ) ;
}
1998-01-09 16:14:46 +00:00
i + + ;
1997-08-01 10:53:24 +00:00
}
1998-01-09 16:14:46 +00:00
break ;
1997-08-01 10:53:24 +00:00
}
}
}
1999-01-19 09:15:17 +00:00
1997-08-01 10:53:24 +00:00
set_body ( page ( pr ) , TRUE ) ;
1997-12-11 15:40:11 +00:00
if ( cursor ( ) )
{
1997-08-01 10:53:24 +00:00
if ( next_match_done ( ) )
i = cursor ( ) - > pos ( ) ;
else
i + + ;
}
1997-12-11 15:40:11 +00:00
else
i + + ;
1997-08-01 10:53:24 +00:00
} // fine ciclo di stampa
while ( fixed_pages ( ) & & page ( pr ) % _npages ! = 0 )
{
pr . formfeed ( ) ;
1999-04-06 15:34:39 +00:00
/*
static TPrintrow empty_line ;
1997-08-01 10:53:24 +00:00
pr . print ( empty_line ) ;
1999-04-06 15:34:39 +00:00
*/
pr . skip ( 1 ) ; // No static when possible
1997-12-11 15:40:11 +00:00
}
1999-04-06 15:34:39 +00:00
1997-12-11 15:40:11 +00:00
if ( from > = 0 )
1999-01-19 09:15:17 +00:00
{
if ( ! _lastpage )
1999-04-06 15:34:39 +00:00
{
TPrint_section * last_foot = exist ( ' F ' , last_page , FALSE ) ;
if ( last_foot ! = NULL )
{
const word lfh = last_foot - > height ( ) ;
const word left = pr . rows_left ( ) + pr . footersize ( ) ;
if ( lfh > left ) // Se l'ultimo footer e' troppo grande ...
pr . formfeed ( ) ; // Stampa il footer normale
pr . footerlen ( lfh ) ; // Fondamentale!
}
1999-01-19 09:15:17 +00:00
set_last_page ( TRUE ) ;
}
1997-12-11 15:40:11 +00:00
pr . formfeed ( ) ;
1999-01-19 09:15:17 +00:00
}
1997-08-01 10:53:24 +00:00
if ( ! was_open )
pr . close ( ) ;
pr . setheaderhandler ( NULL ) ;
pr . setfooterhandler ( NULL ) ;
return ok ;
}
/*bool TForm::print(
long from , // @parm Primo item da stampare (default 0l)
long to ) // @parm Ultimo da stampare (se <lt>0 stampa fino alla fine del file, default -1l)
1996-01-31 17:19:02 +00:00
// @comm Se i parametri di posizionamento sono settati e cosi' pure gli offset genera un <f error_box>.
1997-06-16 12:41:59 +00:00
{
1997-06-16 12:52:23 +00:00
_cur_form = this ;
if ( ( _char_to_pos ! = ' \0 ' | | ( ( _ipx + _ipy + _fpx ) ! = 0 ) ) & & // Se i parametri di posizionamento sono settati e
( _x ! = 0 | | _y ! = 0 ) ) // cosi' pure gli offset genera un errore.
{
error_box ( " Non e' possibile settare contemporaneamente gli offset "
" e i parametri di posizionamento del modulo. " ) ;
return FALSE ;
}
TPrinter & pr = printer ( ) ;
if ( _frompage ) pr . set_from_page ( _frompage ) ;
if ( _topage ) pr . set_to_page ( _topage ) ;
if ( _char_to_pos ! = ' \0 ' | | ( _ipx + _ipy + _fpx ) ! = 0 ) // Effettua il posizionamento del form...
{
if ( _arrange & & pr . printtype ( ) = = winprinter )
arrange_form ( ) ;
}
else
pr . set_offset ( _y , _x ) ;
pr . setheaderhandler ( header_handler ) ; // Setta handlers
pr . setfooterhandler ( footer_handler ) ;
if ( ! pr . is_generic ( ) )
{
for ( pagetype t = odd_page ; t < = last_page ; t = pagetype ( t + 1 ) )
{
if ( height ( t ) > ( word ) pr . formlen ( ) )
{
TString s ( " La lunghezza totale della sezione " ) ;
switch ( t )
{
case odd_page :
s < < " standard " ; break ;
case even_page :
s < < " pagine pari " ; break ;
case first_page :
s < < " prima pagina " ; break ;
case last_page :
s < < " ultima pagina " ; break ;
default :
break ;
}
s < < " eccede la lunghezza reale del foglio. " ;
message_box ( s ) ;
}
}
}
else
{
pr . formlen ( height ( ) ) ;
}
pr . set_char_size ( _fontsize ) ; // Set font name and size
pr . set_fontname ( _fontname ) ; // according to current form
const bool was_open = pr . isopen ( ) ;
set_last_page ( FALSE ) ; // non e' l'ultima pagina
set_background ( 1 , TRUE ) ;
if ( ! was_open & & ! pr . open ( ) )
return FALSE ;
do_events ( ) ;
long lastrec = records ( ) - 1 ;
if ( to < 0 ) to = lastrec ;
if ( to = = lastrec ) to - - ; // l'ultima pagina <20> gestita come caso particolare
bool ok = TRUE ;
1997-06-16 12:41:59 +00:00
for ( long i = from ; i < = to & & ok ; )
1994-11-10 14:17:03 +00:00
{
if ( from < 0 ) to = from ;
1997-06-16 12:41:59 +00:00
else if ( cursor ( ) )
1997-06-16 12:52:23 +00:00
* cursor ( ) = i ;
match_result ( ) ;
1996-03-01 14:02:56 +00:00
if ( pr . current_row ( ) > pr . headersize ( ) + 1 )
{
const word h = set_body ( page ( pr ) , FALSE ) ;
1997-08-01 10:53:24 +00:00
if ( h > pr . rows_left ( ) ) {
1996-03-01 14:02:56 +00:00
pr . formfeed ( ) ;
1997-08-01 10:53:24 +00:00
}
1996-03-01 14:02:56 +00:00
}
1994-11-10 14:17:03 +00:00
1995-04-20 14:35:14 +00:00
set_body ( page ( pr ) , TRUE ) ;
1997-06-16 12:41:59 +00:00
if ( cursor ( ) ) {
1997-06-16 12:52:23 +00:00
if ( next_match_done ( ) )
i = cursor ( ) - > pos ( ) ;
else
i + + ;
1997-06-16 12:41:59 +00:00
}
1994-11-10 14:17:03 +00:00
}
1997-06-16 12:52:23 +00:00
if ( i > = lastrec & & from > = 0 ) // stampa l'ultima pagina (garantisce il footer diverso)
{
set_last_page ( TRUE ) ;
set_background ( 0 , TRUE ) ;
set_header ( 0 , TRUE ) ;
if ( cursor ( ) & & i = = lastrec ) {
* cursor ( ) = i ;
set_body ( 0 , TRUE ) ;
}
pr . formfeed ( ) ;
}
1997-06-16 12:41:59 +00:00
1997-06-16 12:52:23 +00:00
if ( ! was_open )
pr . close ( ) ;
1997-06-16 12:41:59 +00:00
1997-06-16 12:52:23 +00:00
pr . setheaderhandler ( NULL ) ;
pr . setfooterhandler ( NULL ) ;
1997-06-16 12:41:59 +00:00
1997-06-16 12:52:23 +00:00
return ok ;
1997-08-01 10:53:24 +00:00
} */
1994-11-10 14:17:03 +00:00
1994-12-27 14:59:25 +00:00
void TForm : : print_section ( ostream & out , char s ) const
1994-12-20 15:11:26 +00:00
{
1997-06-16 12:52:23 +00:00
for ( pagetype t = odd_page ; t < = last_page ; t = pagetype ( t + 1 ) )
{
const TPrint_section * sec = ( ( TForm * ) this ) - > exist ( s , t ) ;
if ( sec & & sec - > ok ( ) & & ! sec - > temp ( ) )
{
const char * name ;
switch ( s )
{
case ' F ' :
name = " FOOTER " ; break ;
case ' G ' :
name = " GRAPHICS " ; break ;
case ' H ' :
name = " HEADER " ; break ;
default :
name = " BODY " ; break ;
}
out < < " SECTION " < < name ;
out < < * sec ;
out < < " END \n " < < endl ;
}
}
1997-06-16 12:41:59 +00:00
}
// funzione di validazione delle macro
bool TForm : : validate ( TForm_item & cf , TToken_string & s )
{
const TString code ( s . get ( 0 ) ) ; // prende il primo parametro, il codice del messaggio
TString valore ;
1997-08-29 16:37:26 +00:00
if ( code = = " _ISAMREAD " )
{
1997-06-16 12:41:59 +00:00
// lettura generica di un file del database
// sintassi: _ISAMREAD,<file>,<espressione input>[!<espressione input>!...],{<campo file>|<espressione output>[!<espressione output>!...]}
// dove: <file> <20> il numero logico del file o il nome della tabella
// <espressione input> <20> un'espressione del tipo <campo file>=<espressione campi form>
// <espressione campi form> <20> un'espressione di costanti numeriche, stringhe e valori di campi della form (indicati con il loro numero preceduto da #)
// <espressione output> <20> un'espressione del tipo <campo form o gruppo>=<campo file> (se <20> un gruppo deve essere seguito da @) oppure solo <campo file> (il campo della form <20> quello corrente)
int i , j , poseq , posrv , itms ;
pagetype pt ;
char sec ;
TLocalisamfile * file ;
2003-09-23 14:47:55 +00:00
const TString f_code ( s . get ( ) ) ; // prende il codice del file da leggere
if ( atoi ( f_code ) ! = 0 )
file = new TLocalisamfile ( atoi ( f_code ) ) ; // se il codice <20> numerico allora <20> un file
else
file = new TTable ( f_code ) ; // altrimenti <20> una tabella
1997-06-16 12:41:59 +00:00
file - > zero ( ) ; // vuota il record corrente del file
TToken_string in ( s . get ( ) , ' ! ' ) ;
1997-08-29 16:37:26 +00:00
for ( i = 0 ; i < in . items ( ) ; i + + )
{ // scansione sugli elementi dell'input
2003-09-23 14:47:55 +00:00
const TString & curr = in . get ( i ) ;
poseq = curr . find ( ' = ' ) ; // divide la stringa corrente in lvalue e rvalue
posrv = poseq + 1 ;
if ( curr [ posrv ] = = ' = ' )
posrv + + ;
const TString16 fld ( curr . left ( poseq ) ) ; // preleva il nome del campo del file alla sinistra dell'uguale
TExpression rval ( curr . mid ( posrv ) , _strexpr ) ; // preleva l'espressione di assegnamento alla destra dell'uguale
TString16 var ;
1997-08-29 16:37:26 +00:00
for ( j = 0 ; j < rval . numvar ( ) ; j + + )
{ // scansione delle variabili dell'espressione di rvalue
2003-09-23 14:47:55 +00:00
var = rval . varname ( j ) ;
const bool is_form_field = var [ 0 ] = = ' # ' | | // #3
( isdigit ( var [ 0 ] ) & & var . find ( " -> " ) < 0 ) | | // 3
( isalpha ( var [ 0 ] ) & & var . find ( " -> " ) > 0 ) ; // BO->3
if ( is_form_field ) // E' un campo del form
{
if ( var [ 0 ] = = ' # ' )
var . ltrim ( 1 ) ;
TForm_item & fi = cf . find_field ( var ) ;
rval . setvar ( j , fi . get ( ) ) ; // il valore corrente del campo viene settato nell'espressione
}
else // E' un campo della relazione
{
TFieldref fr ( var , 0 ) ; // CODCF oppure 33->CODCF
rval . setvar ( j , fr . read ( * relation ( ) ) ) ; // il valore corrente del campo viene settato nell'espressione
}
1997-06-16 12:41:59 +00:00
}
1998-08-25 18:07:30 +00:00
file - > put ( fld , rval . as_string ( ) ) ; // scrive il risultato dell'espressione nel campo del file
1997-06-16 12:41:59 +00:00
}
1997-08-29 16:37:26 +00:00
if ( file - > read ( ) = = NOERR )
{ // tenta una lettura del file
1997-06-16 12:41:59 +00:00
TToken_string out ( s . get ( ) , ' ! ' ) ;
1997-08-29 16:37:26 +00:00
for ( i = 0 ; i < out . items ( ) ; i + + )
{ // scansione sugli elementi dell'output
1997-06-16 12:41:59 +00:00
TString curr ( out . get ( i ) ) ;
poseq = curr . find ( " == " ) ; // divide la stringa corrente in lvalue e rvalue
1997-08-29 16:37:26 +00:00
if ( poseq = = - 1 )
{
1997-06-16 12:41:59 +00:00
poseq = curr . find ( ' = ' ) ;
if ( poseq ! = - 1 ) posrv = poseq + 1 ;
1997-08-29 16:37:26 +00:00
}
else
posrv = poseq + 2 ;
if ( poseq = = - 1 )
{
1997-06-16 12:41:59 +00:00
const TString & dat = file - > get ( curr ) ; // preleva il nome del campo del file e lo legge dal record
1997-08-29 16:37:26 +00:00
cf . set ( dat ) ;
}
else
{
1997-06-16 12:41:59 +00:00
TString fld ( curr . left ( poseq ) ) ; // preleva il nome del campo del form alla sinistra dell'uguale
const TString & dat = file - > get ( curr . mid ( posrv ) ) ; // preleva il nome del campo del file alla destra dell'uguale e lo legge dal record
if ( fld [ 0 ] = = ' # ' ) fld . ltrim ( 1 ) ;
1997-08-29 16:37:26 +00:00
if ( fld . right ( 1 ) = = " @ " )
{ // se c'<27> la a-commerciale <20> un gruppo
if ( fld . find ( " -> " ) ! = - 1 )
{ // se nel gruppo c'<27> la freccia si riferisce ad un'altra sezione
1997-06-16 12:41:59 +00:00
sec = fld [ 0 ] ;
if ( fld [ 1 ] ! = ' - ' ) pt = char2page ( fld [ 1 ] ) ;
else pt = even_page ;
itms = section ( sec , pt ) . fields ( ) ;
1997-08-29 16:37:26 +00:00
}
else
{ // altrimenti si riferisce alla sezione corrente
1997-06-16 12:41:59 +00:00
sec = cf . section ( ) . section_type ( ) ;
pt = cf . section ( ) . page_type ( ) ;
itms = cf . section ( ) . fields ( ) ;
}
1997-08-29 16:37:26 +00:00
for ( j = 0 ; j < itms ; j + + )
{ // per ogni campo della sezione specificata (o sottointesa)...
1997-06-16 12:41:59 +00:00
TForm_item & fi = section ( sec , pt ) . field ( j ) ;
1997-08-29 16:37:26 +00:00
fi . set ( dat ) ;
1997-06-16 12:41:59 +00:00
}
1997-08-29 16:37:26 +00:00
}
else
{
1997-06-16 12:41:59 +00:00
TForm_item & fi = cf . find_field ( fld ) ;
1997-08-29 16:37:26 +00:00
fi . set ( dat ) ;
1997-06-16 12:41:59 +00:00
}
}
}
}
delete file ;
1997-08-29 16:37:26 +00:00
return TRUE ;
1997-06-16 12:41:59 +00:00
// fine _ISAMREAD
1997-08-29 16:37:26 +00:00
}
if ( code = = " _TABLEREAD " )
{
// lettura generica di un campo di una tabella
// sintassi: _TABLEREAD,<tabella>,<chiave>,<campo file>
// dove: <tabella> nome tabella da leggere
// <chiave> costante stringa o riferimento a campo della form (preceduto da '#') da usare come chiave di ricerca
// <campo file> identificativo del campo da leggere dalla tabella
1997-06-16 12:41:59 +00:00
TTable tab ( s . get ( ) ) ; // prende il nome della tabella
tab . zero ( ) ; // vuota il record corrente della tabella
TString in ( s . get ( ) ) ; // prende il valore o il campo da usare come codice di ricerca
1997-08-29 16:37:26 +00:00
if ( in [ 0 ] = = ' # ' )
{
in . ltrim ( 1 ) ;
TForm_item & fi = cf . find_field ( in ) ;
in = fi . get ( ) ;
1997-06-16 12:41:59 +00:00
}
tab . put ( " CODTAB " , in ) ; // setta la chiave nella tabella
1997-08-29 16:37:26 +00:00
if ( tab . read ( ) = = NOERR )
{
1997-06-16 12:41:59 +00:00
const TString & fld = s . get ( ) ; // prende il nome del campo da leggere...
valore = tab . get ( fld ) ;
cf . set ( valore ) ;
}
1997-08-29 16:37:26 +00:00
return TRUE ;
1997-06-16 12:41:59 +00:00
} // fine _TABLEREAD
1997-08-29 16:37:26 +00:00
if ( code = = " _ALIGN " )
{
1997-06-16 12:41:59 +00:00
// allineamento della posizione di un campo rispetto ad un altro
// sintassi: _ALIGN,<campo form>[,<allineamento>][,<allineamento>...]
// dove: <campo form> <20> il campo della form (preceduto da '#') da cui prendere l'allineamento
// <allineamento> <20> uno dei seguenti valori:
// TOP allinea sulla riga d'inizio
// MIDDLE allinea al centro (effettivo)
// BOTTOM allinea sulla riga di fine (effettiva, non preimpostata)
// LEFT allinea sulla colonna d'inizio
// RIGHT allinea sulla colonna di fine
TString in ( s . get ( ) ) ;
if ( in [ 0 ] = = ' # ' ) in . ltrim ( 1 ) ;
TForm_item & fi = cf . find_field ( in ) ;
1997-08-29 16:37:26 +00:00
1997-06-16 12:41:59 +00:00
int i = 2 ;
1997-08-29 16:37:26 +00:00
for ( const char * cmd = s . get ( ) ; cmd ! = NULL ; cmd = s . get ( ) )
{ // Calcola la nuova posizione
TString align ( cmd ) ;
if ( align [ 0 ] = = ' ! ' )
align . ltrim ( 1 ) ;
1997-06-16 12:41:59 +00:00
if ( align = = " TOP " ) cf . y ( ) = fi . y ( ) ;
1997-08-29 16:37:26 +00:00
else
if ( align = = " MIDDLE " ) cf . y ( ) = fi . y ( ) + fi . effective_height ( ) / 2 ;
else
1998-08-25 18:07:30 +00:00
if ( align = = " BOTTOM " ) cf . y ( ) = fi . y ( ) + ( fi . effective_height ( ) ? fi . effective_height ( ) - 1 : 0 ) ;
1997-08-29 16:37:26 +00:00
else
if ( align = = " LEFT " ) cf . set_x ( fi . x ( ) ) ;
else
if ( align = = " RIGHT " ) cf . set_x ( fi . x ( ) + fi . width ( ) ) ;
1997-06-16 12:41:59 +00:00
}
// altrimenti stampa la stringa cosi' com'e'
1997-08-29 16:37:26 +00:00
return TRUE ;
1997-06-16 12:41:59 +00:00
} // fine _ALIGN
1997-08-29 16:37:26 +00:00
if ( code = = " _PAGENO " ) // Messaggio per stampare il numero di pagina corrente
1997-06-16 12:41:59 +00:00
{
TString16 pg ; pg < < int ( printer ( ) . getcurrentpage ( ) ) ;
cf . set ( pg ) ;
1997-08-29 16:37:26 +00:00
return TRUE ;
1997-06-16 12:41:59 +00:00
}
1997-08-29 16:37:26 +00:00
if ( code = = " _TODAY " ) // Messaggio per stampare la data di oggi
1997-06-16 12:41:59 +00:00
{
TString16 dt ( TDate ( TODAY ) . string ( ) ) ;
cf . set ( dt ) ;
1997-08-29 16:37:26 +00:00
return TRUE ;
1997-06-16 12:41:59 +00:00
}
1997-08-29 16:37:26 +00:00
if ( code = = " _NUMEXPR " | | code = = " _STREXPR " )
{
// Messaggio per la valutazione di espressioni numeriche e stringhe
1998-01-20 15:45:20 +00:00
int comma = s . find ( ' , ' ) ;
TExpression rval ( s . mid ( comma + 1 ) , code [ 1 ] = = ' N ' ? _numexpr : _strexpr , TRUE ) ;
1997-06-16 12:52:23 +00:00
cf . section ( ) . eval_expr ( rval ) ;
1997-06-16 12:41:59 +00:00
if ( ! rval . error ( ) )
1998-08-25 18:07:30 +00:00
cf . set ( rval . as_string ( ) ) ;
1997-08-29 16:37:26 +00:00
return TRUE ;
1997-06-16 12:41:59 +00:00
}
1997-08-29 16:37:26 +00:00
if ( code = = " _DITTA " )
{
1997-06-16 12:41:59 +00:00
// lettura dei dati della ditta
// sintassi: _DITTA,{<campo relazione>|<macro>}
// dove: <campo relazione> <20> un riferimento alla relazione di gestione dei dati della ditta (es. 113@->DENCOM <20> la denominazione del comune di residenza della ditta)
// <macro> <20> uno delle macro seguenti:
// !RAGSOC ragione sociale
// !IND indirizzo (fiscale se c'<27> , oppure di residenza)
// !NUM numero civico (fiscale se c'<27> , oppure di residenza)
// !CAP CAP (fiscale se c'<27> , oppure di residenza)
// !COM comune (fiscale se c'<27> , oppure di residenza)
// !PROV provincia (fiscale se c'<27> , oppure di residenza)
// !IVA partita iva
// !CF codice fiscale
// !TEL numero di telefono (con prefisso)
// !FAX numero di fax (con prefisso)
// !REGSOC numero di registrazione presso il Tribunale
// !CCIAA numero di registrazione presso la camera di commercio
// nota: la relazione della ditta <20> cos<6F> strutturata:
// %NDITTE (9) Dati ditte
// + %ANAGR (6) Anagrafica generale (indirizzo, ecc.)
// + %COMUNI (113@) Comune di residenza
// + %COMUNI (213@) Comune di residenza fiscale
1997-06-16 12:52:23 +00:00
TLocalisamfile firm ( LF_NDITTE ) ;
TLocalisamfile anag ( LF_ANAG ) ;
firm . put ( " CODDITTA " , main_app ( ) . get_firm ( ) ) ;
firm . read ( ) ;
anag . put ( " TIPOA " , firm . get ( " TIPOA " ) ) ;
anag . put ( " CODANAGR " , firm . get ( " CODANAGR " ) ) ;
1997-06-16 12:41:59 +00:00
anag . read ( ) ;
TString in ( s . get ( ) ) ;
if ( in [ 0 ] = = ' ! ' ) {
in . ltrim ( 1 ) ;
bool _fisc = anag . get ( " INDRF " ) . not_empty ( ) ;
if ( in = = " RAGSOC " )
valore = anag . get ( " RAGSOC " ) ;
if ( in = = " IND " ) {
if ( _fisc )
valore = anag . get ( " INDRF " ) ;
else
valore = anag . get ( " INDRES " ) ;
1995-04-20 14:35:14 +00:00
}
1997-06-16 12:41:59 +00:00
if ( in = = " NUM " ) {
if ( _fisc )
valore = anag . get ( " CIVRF " ) ;
else
valore = anag . get ( " CIVRES " ) ;
}
if ( in = = " CAP " ) {
if ( _fisc )
valore = anag . get ( " CAPRF " ) ;
else
valore = anag . get ( " CAPRES " ) ;
}
/*if (in=="COM") {
if ( _fisc )
valore = _firmrel . lfile ( - 213 ) . get ( " DENCOM " ) ;
else
valore = _firmrel . lfile ( - 113 ) . get ( " DENCOM " ) ;
}
if ( in = = " PROV " ) {
if ( _fisc )
valore = _firmrel . lfile ( - 213 ) . get ( " PROVCOM " ) ;
else
valore = _firmrel . lfile ( - 113 ) . get ( " PROVCOM " ) ;
} */
if ( in = = " IVA " )
valore = anag . get ( " PAIV " ) ;
if ( in = = " CF " )
valore = anag . get ( " COFI " ) ;
if ( in = = " TEL " ) {
valore = anag . get ( " PTEL " ) ;
valore < < " / " < < anag . get ( " TEL " ) ;
}
if ( in = = " FAX " ) {
valore = anag . get ( " PFAX " ) ;
valore < < " / " < < anag . get ( " FAX " ) ;
}
/*if (in=="REGSOC") {
valore = _firmrel [ LF_UNLOC ] . get ( " REGTRIB " ) ;
valore < < " Vol. " < < _firmrel [ LF_UNLOC ] . get ( " VOLTRIB " ) ;
valore < < " Fasc. " < < _firmrel [ LF_UNLOC ] . get ( " FASCTRIB " ) ;
}
if ( in = = " CCIAA " ) {
valore = _firmrel [ LF_UNLOC ] . get ( " NUMCCIAA " ) ;
valore < < " del " < < _firmrel [ LF_UNLOC ] . get ( " DATAICCIAA " ) ;
} */
} else {
TFieldref fref ( s . get ( ) , 0 ) ;
valore = fref . read ( anag . curr ( ) ) ;
}
cf . set ( valore ) ;
1997-08-29 16:37:26 +00:00
return TRUE ;
1997-06-16 12:52:23 +00:00
}
1997-08-29 16:37:26 +00:00
return TRUE ;
1997-06-16 12:41:59 +00:00
}
1994-11-10 14:17:03 +00:00
void TForm : : print_on ( ostream & out ) const
1997-06-16 12:41:59 +00:00
{
1997-06-16 12:52:23 +00:00
if ( relation ( ) )
{
out < < * relation ( ) < < " \n END " < < endl ;
print_description ( out ) ;
}
1997-06-16 12:41:59 +00:00
1997-06-16 12:52:23 +00:00
print_general ( out ) ;
1997-06-16 12:41:59 +00:00
1997-06-16 12:52:23 +00:00
print_section ( out , ' G ' ) ;
print_section ( out , ' H ' ) ;
print_section ( out , ' B ' ) ;
print_section ( out , ' F ' ) ;
1997-06-16 12:41:59 +00:00
1997-06-16 12:52:23 +00:00
out < < " END " < < endl ;
1994-12-20 15:11:26 +00:00
}
1994-12-27 14:59:25 +00:00
1995-10-16 17:52:24 +00:00
word TForm : : height ( word page )
1997-06-16 12:41:59 +00:00
{
1997-06-16 12:52:23 +00:00
const pagetype t = ( page = = 1 ) ? first_page : ( ( page & 0x1 ) ? odd_page : even_page ) ;
1996-08-08 09:21:57 +00:00
1997-06-16 12:52:23 +00:00
word h = 0 ;
if ( _back . items ( ) = = 0 )
{
if ( _head . items ( ) & & exist ( ' H ' , t ) ! = NULL )
h + = section ( ' H ' , page ) . height ( ) ;
if ( _body . items ( ) & & exist ( ' B ' , t ) ! = NULL )
h + = section ( ' B ' , page ) . height ( ) ;
if ( _foot . items ( ) & & exist ( ' F ' , t ) ! = NULL )
h + = section ( ' F ' , page ) . height ( ) ;
}
else
h = printer ( ) . formlen ( ) ;
1997-06-16 12:41:59 +00:00
1997-06-16 12:52:23 +00:00
return h ;
1994-11-10 14:17:03 +00:00
}
1996-02-05 19:00:53 +00:00
// @doc EXTERNAL
1996-01-31 17:19:02 +00:00
// @mfunc Legge un profilo
//
// @rdesc Ritorna se e' riuscito nell'operazione:
// @flag TRUE | E' riuscito a leggere il prfilo
// @flag FALSE | Non ha letto il profilo
1995-05-18 14:18:01 +00:00
bool TForm : : read_profile ( )
1996-01-31 17:19:02 +00:00
// @comm Per la lettura del profilo procede leggendo prima la definizione del
// profilo base e successivamente le modifiche relative.
1997-06-16 12:41:59 +00:00
{
1997-06-16 12:52:23 +00:00
TLocalisamfile prof ( LF_FORM ) ;
TLocalisamfile rprof ( LF_RFORM ) ;
prof . zero ( ) ;
prof . put ( " TIPOPROF " , _name ) ;
prof . put ( " CODPROF " , _code ) ;
if ( prof . read ( _isequal ) = = NOERR )
{
rprof . zero ( ) ;
rprof . put ( " TIPOPROF " , _name ) ;
rprof . put ( " CODPROF " , _code ) ;
const TRectype filter ( rprof . curr ( ) ) ;
TString set ( " HGBF " ) ;
for ( int err = rprof . read ( _isgteq ) ; err = = NOERR & & rprof . curr ( ) = = filter ; err = rprof . next ( ) )
{
// controllo lingua per codici profilo
char cl = rprof . curr ( ) . get ( " CODPROF " ) . right ( 1 ) [ 0 ] ;
char cp = _code . right ( 1 ) [ 0 ] ;
// stop se il codice letto e' di un profilo EC in lingua e
// il corrente e' ec non in lingua
if ( ! isdigit ( cl ) & & cl ! = cp ) break ;
const TString & s = rprof . get ( " SEZ " ) ;
const char sec = s [ 0 ] ;
if ( set . find ( sec ) < 0 ) continue ; // Se non fa parte di una sezione standard la salta
const pagetype pt = char2page ( s [ 1 ] ) ;
const short id = rprof . get_int ( " ID " ) ;
if ( id = = 0 )
{
TPrint_section & se = section ( sec , pt ) ;
se . read_from ( rprof . curr ( ) ) ;
}
else
{
TForm_item & item = find_field ( sec , pt , id ) ;
item . read_from ( rprof . curr ( ) ) ;
}
}
if ( _code . not_empty ( ) & & ! _isnew )
{
_x = prof . get_int ( " OFFX " ) ;
_y = prof . get_int ( " OFFY " ) ;
_fontname = prof . get ( " FONTNAME " ) ;
_fontsize = prof . get_int ( " FONTSIZE " ) ;
_char_to_pos = prof . get ( " CTP " ) [ 0 ] ;
_ipx = prof . get_int ( " IPX " ) ;
_ipy = prof . get_int ( " IPY " ) ;
_fpx = prof . get_int ( " FPX " ) ;
set_fincatura ( prof . get ( " GRID " ) ) ;
}
}
return TRUE ;
1995-05-18 14:18:01 +00:00
}
bool TForm : : write_profile ( )
1994-11-10 14:17:03 +00:00
{
1997-06-16 12:52:23 +00:00
const char sechar [ 4 ] = { ' B ' , ' F ' , ' G ' , ' H ' } ;
get_compulsory_specials ( ) ;
TLocalisamfile form ( LF_FORM ) ;
form . zero ( ) ;
form . put ( " TIPOPROF " , _name ) ;
form . put ( " CODPROF " , _code ) ;
if ( form . read ( _isequal , _lock ) = = NOERR )
{
if ( _dirty )
{
form . put ( " OFFY " , _y ) ;
form . put ( " OFFX " , _x ) ;
form . put ( " FONTNAME " , _fontname ) ;
form . put ( " FONTSIZE " , _fontsize ) ;
form . put ( " CTP " , _char_to_pos ) ;
form . put ( " IPX " , _ipx ) ;
form . put ( " IPY " , _ipy ) ;
form . put ( " FPX " , _fpx ) ;
form . put ( " GRID " , _fink ) ;
form . rewrite ( ) ;
_dirty = FALSE ;
}
}
TLocalisamfile rform ( LF_RFORM ) ;
TRectype & cur = rform . curr ( ) ;
int err = NOERR ;
for ( int sn = 0 ; sn < 4 & & err = = NOERR ; sn + + ) // For each section
{
const char sc = sechar [ sn ] ;
for ( pagetype pt = odd_page ; pt < = last_page ; pt = pagetype ( pt + 1 ) ) // For each section type
{
TPrint_section * sec = exist ( sc , pt ) ;
if ( sec ! = NULL & & sec - > dirty ( ) )
{
const char codsez [ 3 ] = { sc , pt + ' 0 ' , ' \0 ' } ;
cur . zero ( ) ;
cur . put ( " TIPOPROF " , name ( ) ) ;
cur . put ( " CODPROF " , code ( ) ) ;
cur . put ( " SEZ " , codsez ) ;
sec - > print_on ( cur ) ;
sec - > set_dirty ( FALSE ) ;
err = _isnew ? rform . write ( ) : rform . rewrite ( ) ;
if ( err ! = NOERR )
err = _isnew ? rform . rewrite ( ) : rform . write ( ) ;
for ( word i = 0 ; i < sec - > fields ( ) & & err = = NOERR ; i + + )
{
TForm_item & fi = sec - > field ( i ) ;
if ( fi . dirty ( ) )
{
fi . print_on ( cur ) ;
err = _isnew ? rform . write ( ) : rform . rewrite ( ) ;
if ( err ! = NOERR )
err = _isnew ? rform . rewrite ( ) : rform . write ( ) ;
fi . set_dirty ( FALSE ) ;
}
}
}
}
}
form . reread ( _unlock ) ;
if ( err ! = NOERR )
return error_box ( " Errore di salvataggio profilo: %d " , err ) ;
return TRUE ;
1997-06-16 12:41:59 +00:00
}
1995-05-18 14:18:01 +00:00
1995-12-04 10:27:42 +00:00
void TForm : : init ( )
{
1997-08-01 10:53:24 +00:00
_npages = 0 ;
1997-06-16 12:52:23 +00:00
_relation = NULL ;
_cursor = NULL ;
_rel_desc = NULL ;
_isnew = FALSE ;
1998-08-25 18:07:30 +00:00
_fontname = " " ;
_fontsize = 0 ;
1997-06-16 12:52:23 +00:00
_x = 0 ;
_y = 0 ;
_char_to_pos = ' \0 ' ;
_ipx = 0 ;
_ipy = 0 ;
_fpx = 0 ;
_arrange = TRUE ;
set_fincatura ( " +++++++++-| " ) ;
1997-06-19 15:04:33 +00:00
set_fink_mode ( TRUE ) ;
1997-06-16 12:52:23 +00:00
_dirty = FALSE ;
_msg_add_enabled = TRUE ;
1999-04-06 15:34:39 +00:00
_magic_currency = FALSE ;
2001-06-25 10:41:20 +00:00
_exchange = NULL ;
1995-12-04 10:27:42 +00:00
}
1996-02-05 19:00:53 +00:00
// @doc EXTERNAL
1996-01-31 17:19:02 +00:00
// @mfunc Carica il form dal file specificato
void TForm : : read (
1997-06-16 12:52:23 +00:00
const char * name , // @parm Nome del profilo di stampa da leggere
const char * code , // @parm Codice del profilo di stampa da leggere
int lev , // @parm Permessi di stampa
const char * desc ) // @parm Descrizione del formato da leggere
{
_name = name ;
2002-04-22 15:07:09 +00:00
1997-06-16 12:52:23 +00:00
_code = code ;
_editlevel = lev ;
_desc = desc ;
if ( _code . not_empty ( ) )
{
// extract base form name
TLocalisamfile forms ( LF_FORM ) ;
forms . zero ( ) ;
forms . put ( " TIPOPROF " , _name ) ;
forms . put ( " CODPROF " , _code ) ;
_isnew = forms . read ( ) ! = NOERR ;
if ( _isnew )
{
// create new form
forms . put ( " TIPOPROF " , _name ) ;
forms . put ( " CODPROF " , _code ) ;
forms . put ( " DESC " , _desc ) ;
forms . put ( " OFFY " , _y ) ;
forms . put ( " OFFX " , _x ) ;
forms . put ( " FONTNAME " , _fontname ) ;
forms . put ( " FONTSIZE " , _fontsize ) ;
forms . put ( " CTP " , _char_to_pos ) ;
forms . put ( " IPX " , _ipx ) ;
forms . put ( " IPY " , _ipy ) ;
forms . put ( " FPX " , _fpx ) ;
forms . put ( " GRID " , _fink ) ;
forms . write ( ) ;
}
else
if ( forms . status ( ) = = NOERR )
{
_desc = forms . get ( " DESC " ) ;
1998-05-27 13:41:48 +00:00
if ( desc & & * desc & & _desc ! = desc ) // Controlla se la descrizione e' diversa, in questo caso l'aggiorna
1997-06-16 12:52:23 +00:00
{
forms . reread ( _lock ) ;
forms . put ( " DESC " , desc ) ;
forms . rewrite ( ) ;
}
}
}
// read base form
TFilename n ( _name ) ; n . ext ( " frm " ) ;
2002-04-22 15:07:09 +00:00
n . custom_path ( ) ;
2003-10-29 14:52:23 +00:00
if ( n . exist ( ) )
2003-11-03 15:39:51 +00:00
{
2003-10-29 14:52:23 +00:00
_filename = n ;
2003-11-06 16:58:01 +00:00
printer ( ) . set_form_name ( n ) ;
2003-11-03 15:39:51 +00:00
}
2003-10-29 14:52:23 +00:00
else
2003-06-11 07:44:57 +00:00
fatal_box ( " Il form '%s' non esiste. " , ( const char * ) n ) ;
1997-06-16 12:52:23 +00:00
TScanner scanner ( n ) ;
bool ok = TRUE ;
if ( scanner . popkey ( ) = = " US " ) // Parse relation
{
ok = parse_use ( scanner ) ;
while ( ok & & scanner . popkey ( ) = = " JO " | | scanner . key ( ) = = " SO " )
{
if ( scanner . key ( ) = = " JO " )
ok = parse_join ( scanner ) ;
else // join a sorted file
{
ok = parse_sortedjoin ( scanner ) ;
}
}
parse_description ( scanner ) ; // Parse description
}
else scanner . push ( ) ;
if ( ok ) parse_general ( scanner ) ; // Parse general
while ( ok )
{
if ( scanner . popkey ( ) ! = " SE " ) // SECTION or END
break ;
const char sec = scanner . popkey ( ) [ 0 ] ; // Section name (GRAPH, HEAD, BODY, FOOT)
const pagetype p = char2page ( scanner . popkey ( ) [ 0 ] ) ; // Section type (odd, even, first, last)
TPrint_section * ps = exist ( sec , p , TRUE ) ; // Create section
ok = ps - > parse ( scanner ) ; // Parse section
}
if ( _code . not_empty ( ) )
read_profile ( ) ; // read from LF_RFORM file
set_compulsory_specials ( ) ;
TPrinter & pr = printer ( ) ;
pr . set_offset ( _y , _x ) ;
1997-10-06 08:31:21 +00:00
if ( _fontname . not_empty ( ) )
{
1997-10-20 15:39:13 +00:00
pr . set_char_size ( _fontsize ) ;
pr . set_fontname ( _fontname ) ;
}
1997-06-19 15:04:33 +00:00
set_fink_mode ( TRUE ) ;
1997-06-16 12:41:59 +00:00
}
1994-11-10 14:17:03 +00:00
1997-06-16 12:41:59 +00:00
void TForm : : set_compulsory_specials ( )
{
1997-06-16 12:52:23 +00:00
const char sechar [ 3 ] = { ' B ' , ' F ' , ' H ' } ;
for ( int sn = 0 ; sn < 3 ; sn + + )
{
const char sc = sechar [ sn ] ;
for ( pagetype pt = odd_page ; pt < = last_page ; pt = pagetype ( pt + 1 ) )
{
1997-12-11 15:40:11 +00:00
const TPrint_section * sec = exist ( sc , pt ) ;
if ( sec ! = NULL & & sec - > columnwise ( ) )
1997-06-16 12:52:23 +00:00
{
const word fields = sec - > fields ( ) ;
1997-12-11 15:40:11 +00:00
for ( word i = 0 ; i < fields ; i + + )
1997-06-16 12:52:23 +00:00
{
TForm_item & fi = sec - > field ( i ) ;
1997-12-11 15:40:11 +00:00
if ( fi . special_items ( ) > 0 )
1997-06-16 12:52:23 +00:00
{
fi . set_col_head ( fi . get_special_value ( " INTESTAZIONE " ) ) ;
fi . ofs ( ) = ( short ) atoi ( fi . get_special_value ( " OFFSET " ) ) ;
1997-12-11 15:40:11 +00:00
const TString & fnk = fi . get_special_value ( " FINCATURA " ) ;
if ( fnk . not_empty ( ) )
{
fi . set_finkl ( fnk [ 0 ] ! = ' X ' ) ; // !finkl significa fincatura abilitata
fi . set_finkr ( fnk [ 1 ] ! = ' X ' ) ; // !finkr significa fincatura abilitata
}
1997-06-16 12:52:23 +00:00
}
}
}
}
}
1994-11-10 14:17:03 +00:00
}
1997-06-16 12:41:59 +00:00
void TForm : : get_compulsory_specials ( )
1997-05-28 12:44:01 +00:00
{
1997-06-16 12:52:23 +00:00
const char sechar [ 3 ] = { ' B ' , ' F ' , ' H ' } ;
for ( int sn = 0 ; sn < 3 ; sn + + )
{
const char sc = sechar [ sn ] ;
for ( pagetype pt = odd_page ; pt < = last_page ; pt = pagetype ( pt + 1 ) )
{
TPrint_section * sec = exist ( sc , pt ) ;
if ( sec ! = NULL )
{
const word fields = sec - > fields ( ) ;
const bool col_wise = sec - > columnwise ( ) ;
for ( word i = 0 ; col_wise & & i < fields ; i + + )
{
TForm_item & fi = sec - > field ( i ) ;
if ( fi . special_items ( ) > 0 )
{
fi . set_special_value ( " INTESTAZIONE " , fi . col_head ( ) ) ;
fi . set_special_value ( " OFFSET " , format ( " %d " , fi . ofs ( ) ) ) ;
TString fnk ( fi . finkl ( ) ? " " : " X " ) ;
fnk < < ( fi . finkr ( ) ? " " : " X " ) ;
fi . set_special_value ( " FINCATURA " , fnk ) ;
}
}
}
}
}
1997-05-28 12:44:01 +00:00
}
1997-06-16 12:41:59 +00:00
void TForm : : set_fincatura ( const char * s )
1997-05-28 12:44:01 +00:00
{
1997-06-16 12:52:23 +00:00
_fink = s ; _fink . cut ( 11 ) ;
printer ( ) . set_fincatura ( _fink ) ;
1997-05-28 12:44:01 +00:00
}
1997-06-19 15:04:33 +00:00
void TForm : : set_fink_mode ( bool f )
{
printer ( ) . set_fink_mode ( f ) ;
1996-02-03 10:52:05 +00:00
}
1997-06-19 15:04:33 +00:00
bool TForm : : get_fink_mode ( )
{
return printer ( ) . get_fink_mode ( ) ;
}
1997-06-16 12:41:59 +00:00
// @cmember Indica se ignorare il prossimo skip del ciclo sul file
void TForm : : match_result ( int file , int val )
1996-02-03 10:52:05 +00:00
{
1997-06-16 12:52:23 +00:00
if ( file = = 0 )
file = cursor ( ) - > file ( ) . num ( ) ;
if ( val < 0 )
_skip_info . destroy ( file ) ;
else
{
TForm_skip_info info ;
if ( next_match_done ( file ) )
1999-04-07 14:41:07 +00:00
info . _match_number = ( ( TForm_skip_info & ) _skip_info [ file ] ) . _match_number ;
1997-06-16 12:52:23 +00:00
if ( val )
1999-04-07 14:41:07 +00:00
info . _match_number + + ;
info . _match_result = val ! = 0 ;
1997-06-16 12:52:23 +00:00
_skip_info . add ( info , file ) ;
}
1997-06-16 12:41:59 +00:00
}
// @cmember Indica se ignorare (default) o non ignorare il prossimo skip del ciclo sul file
bool TForm : : last_match_result ( int file )
{
1997-06-16 12:52:23 +00:00
if ( file = = 0 )
file = cursor ( ) - > file ( ) . num ( ) ;
if ( next_match_done ( file ) )
1999-04-07 14:41:07 +00:00
return ( ( TForm_skip_info & ) _skip_info [ file ] ) . _match_result ;
1997-06-16 12:52:23 +00:00
return fatal_box ( " Tryed to get result of a never executed skip in file %d " , file ) ;
1997-06-16 12:41:59 +00:00
}
// @mfunc Memorizza l'avvenuto next_match sul file passato
bool TForm : : next_match_done ( int file )
{
1997-06-16 12:52:23 +00:00
if ( file = = 0 )
file = cursor ( ) - > file ( ) . num ( ) ;
return _skip_info . objptr ( file ) ! = NULL ;
1996-02-03 10:52:05 +00:00
}
1997-06-16 12:41:59 +00:00
// @mfunc Indica l'avvenuto next_match sul file passato
int TForm : : matches_done ( int file )
{
1997-06-16 12:52:23 +00:00
if ( file = = 0 )
file = cursor ( ) - > file ( ) . num ( ) ;
if ( next_match_done ( file ) )
1999-04-07 14:41:07 +00:00
return ( ( TForm_skip_info & ) _skip_info [ file ] ) . _match_number ;
1997-06-16 12:52:23 +00:00
return 0 ;
1995-12-22 12:01:15 +00:00
}
2001-04-30 15:04:10 +00:00
void TForm : : set_output_exchange ( const char * codval , real exchange , exchange_type et )
{
2001-06-25 10:41:20 +00:00
if ( _exchange = = NULL )
_exchange = new TExchange ;
_exchange - > set ( codval , exchange , et ) ;
2001-04-30 15:04:10 +00:00
}
1995-12-04 10:27:42 +00:00
TForm : : TForm ( )
{
1997-06-16 12:52:23 +00:00
init ( ) ;
_frompage = _topage = 0 ;
1999-04-06 15:34:39 +00:00
_magic_currency = FALSE ;
1995-12-04 10:27:42 +00:00
}
1997-06-16 12:41:59 +00:00
TForm : : TForm ( const char * name , const char * code , int lev , const char * desc )
1995-12-04 10:27:42 +00:00
{
1997-06-16 12:52:23 +00:00
init ( ) ;
read ( name , code , lev , desc ) ;
_frompage = _topage = 0 ;
1999-04-06 15:34:39 +00:00
_magic_currency = FALSE ;
1995-12-04 10:27:42 +00:00
}
1994-12-20 15:11:26 +00:00
1994-11-10 14:17:03 +00:00
TForm : : ~ TForm ( )
{
1997-06-16 12:52:23 +00:00
if ( _cursor )
{
delete _cursor ;
delete _relation ;
if ( _rel_desc )
delete _rel_desc ;
}
2001-06-25 10:41:20 +00:00
if ( _exchange )
delete _exchange ;
1994-11-10 14:17:03 +00:00
}