Patch level : 2.1 nopatch
Files correlati : ba8.exe Ricompilazione Demo : [ ] Commento : Salvataggio dello stato dell'arte im materia di report git-svn-id: svn://10.65.10.50/trunk@11932 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
		
							parent
							
								
									f0efcb3946
								
							
						
					
					
						commit
						6011c75885
					
				@ -236,6 +236,7 @@ END
 | 
			
		||||
MEMO 106 58 8
 | 
			
		||||
BEGIN
 | 
			
		||||
  PROMPT 1 3 "Condizione "
 | 
			
		||||
  FLAGS "D"
 | 
			
		||||
END
 | 
			
		||||
 | 
			
		||||
BUTTON DLG_CANCEL 10 2
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										331
									
								
								ba/ba8201.cpp
									
									
									
									
									
								
							
							
						
						
									
										331
									
								
								ba/ba8201.cpp
									
									
									
									
									
								
							@ -13,7 +13,224 @@
 | 
			
		||||
 | 
			
		||||
#include "ba8201.h"
 | 
			
		||||
 | 
			
		||||
const TString& TRecordset::get(const char* column_name) const
 | 
			
		||||
///////////////////////////////////////////////////////////
 | 
			
		||||
// TVariant
 | 
			
		||||
///////////////////////////////////////////////////////////
 | 
			
		||||
 | 
			
		||||
static const TVariant NULL_VARIANT;
 | 
			
		||||
 | 
			
		||||
void TVariant::set_null()
 | 
			
		||||
{
 | 
			
		||||
  if (_ptr != NULL)
 | 
			
		||||
  {
 | 
			
		||||
    if (_type != _nullfld && _type != _longfld)
 | 
			
		||||
      delete _ptr;
 | 
			
		||||
    _ptr = NULL;
 | 
			
		||||
  }
 | 
			
		||||
  _type = _nullfld;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void TVariant::set(const char* str)
 | 
			
		||||
{
 | 
			
		||||
  if (_type == _alfafld)
 | 
			
		||||
    *((TString*)_ptr) = str;
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    set_null();
 | 
			
		||||
    _type = _alfafld;
 | 
			
		||||
    _ptr = new TString(str);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void TVariant::set(const real& r)
 | 
			
		||||
{
 | 
			
		||||
  if (_type == _realfld)
 | 
			
		||||
    *((real*)_ptr) = r;
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    set_null();
 | 
			
		||||
    _type = _realfld;
 | 
			
		||||
    _ptr = new real(r);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void TVariant::set(const TDate& d)
 | 
			
		||||
{
 | 
			
		||||
  if (_type == _datefld)
 | 
			
		||||
    *((TDate*)_ptr) = d;
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    set_null();
 | 
			
		||||
    _type = _datefld;
 | 
			
		||||
    _ptr = new TDate(d);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void TVariant::set(const long n)
 | 
			
		||||
{
 | 
			
		||||
  if (_type != _longfld)
 | 
			
		||||
    set_null();
 | 
			
		||||
  _type = _longfld;
 | 
			
		||||
  _ptr = (void*)n;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TDate TVariant::as_date() const
 | 
			
		||||
{
 | 
			
		||||
  if (_type == _datefld)
 | 
			
		||||
    return *(TDate*)_ptr;
 | 
			
		||||
 | 
			
		||||
  const TDate d(as_int());
 | 
			
		||||
  return d;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
long TVariant::as_int() const
 | 
			
		||||
{
 | 
			
		||||
  long n = 0;
 | 
			
		||||
  switch(_type)
 | 
			
		||||
  {
 | 
			
		||||
  case _datefld: n = as_date().date2ansi(); break;
 | 
			
		||||
  case _longfld: n = (long)_ptr; break;
 | 
			
		||||
  case _realfld: n = as_real().integer(); break;
 | 
			
		||||
  case _alfafld: n = atoi(as_string()); break;
 | 
			
		||||
  default : break;
 | 
			
		||||
  }
 | 
			
		||||
  return n;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool TVariant::as_bool() const
 | 
			
		||||
{
 | 
			
		||||
  bool ok = false;
 | 
			
		||||
  if (_type == _alfafld)
 | 
			
		||||
    ok = strchr("XY", as_string()[0]) != NULL;
 | 
			
		||||
  else
 | 
			
		||||
    ok = as_int() != 0;
 | 
			
		||||
  return ok;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
real TVariant::as_real() const
 | 
			
		||||
{
 | 
			
		||||
  if (_type == _realfld)
 | 
			
		||||
    return *(real*)_ptr;
 | 
			
		||||
  switch(_type)
 | 
			
		||||
  {
 | 
			
		||||
  case _alfafld: return real(as_string()); break;
 | 
			
		||||
  case _longfld: return real(as_int()); break;
 | 
			
		||||
  default : break;
 | 
			
		||||
  }
 | 
			
		||||
  return ZERO;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool TVariant::as_string(TString& tmp) const
 | 
			
		||||
{
 | 
			
		||||
  tmp.cut(0);
 | 
			
		||||
  switch(_type)
 | 
			
		||||
  {
 | 
			
		||||
  case _alfafld: tmp = *(TString*)_ptr; break;
 | 
			
		||||
  case _datefld: tmp = as_date().string(); break;
 | 
			
		||||
  case _longfld: tmp << as_int(); break;
 | 
			
		||||
  case _realfld: tmp = as_real().string(); break;
 | 
			
		||||
  default: break;
 | 
			
		||||
  }
 | 
			
		||||
  return !is_null();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const TString& TVariant::as_string() const
 | 
			
		||||
{
 | 
			
		||||
  if (_type == _alfafld)
 | 
			
		||||
    return *(TString*)_ptr;
 | 
			
		||||
  TString& tmp = get_tmp_string();
 | 
			
		||||
  as_string(tmp);
 | 
			
		||||
  return tmp;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void TVariant::convert_to(TFieldtypes ft)
 | 
			
		||||
{
 | 
			
		||||
  if (_type != ft)
 | 
			
		||||
  {
 | 
			
		||||
    switch (ft)
 | 
			
		||||
    {
 | 
			
		||||
    case _alfafld: set(as_string()); break;
 | 
			
		||||
    case _datefld: set(as_date()); break;
 | 
			
		||||
    case _longfld: set(as_int()); break;
 | 
			
		||||
    case _realfld: set(as_real()); break;
 | 
			
		||||
    default      : set_null(); break;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void TVariant::copy(const TVariant& var)
 | 
			
		||||
{
 | 
			
		||||
  switch (var._type)
 | 
			
		||||
  {
 | 
			
		||||
  case _datefld: set(var.as_date()); break;
 | 
			
		||||
  case _longfld: set(var.as_int()); break;
 | 
			
		||||
  case _realfld: set(var.as_real()); break;
 | 
			
		||||
  case _alfafld: set(var.as_string()); break;
 | 
			
		||||
  default : set_null(); break;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int TVariant::compare(const TSortable& s) const
 | 
			
		||||
{
 | 
			
		||||
  const TVariant& var = (const TVariant&)s;
 | 
			
		||||
  int cmp = 0;
 | 
			
		||||
  switch (_type)
 | 
			
		||||
  {
 | 
			
		||||
  case _datefld: cmp = as_date() - var.as_date(); break;
 | 
			
		||||
  case _longfld: cmp = as_int() - var.as_int(); break;
 | 
			
		||||
  case _realfld: 
 | 
			
		||||
    {
 | 
			
		||||
      const real n = as_real() - var.as_real();
 | 
			
		||||
      cmp = n.sign(); 
 | 
			
		||||
    }
 | 
			
		||||
    break;
 | 
			
		||||
  case _alfafld: cmp = as_string().compare(var.as_string()); break;
 | 
			
		||||
  default : cmp = var.is_null() ? 0 : -1;
 | 
			
		||||
  }
 | 
			
		||||
  return cmp;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TVariant& TVariant::add(const TVariant& var)
 | 
			
		||||
{
 | 
			
		||||
  switch (_type)
 | 
			
		||||
  {
 | 
			
		||||
  case _datefld: set(as_date() + var.as_int()); break;
 | 
			
		||||
  case _longfld: set(as_int() + var.as_int()); break;
 | 
			
		||||
  case _alfafld: *(TString*)_ptr << var.as_string(); break;
 | 
			
		||||
  case _realfld: *(real*)_ptr += var.as_real(); break;
 | 
			
		||||
  default: copy(var); break;
 | 
			
		||||
  }
 | 
			
		||||
  return *this;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TVariant& TVariant::sub(const TVariant& var)
 | 
			
		||||
{
 | 
			
		||||
  switch (_type)
 | 
			
		||||
  {
 | 
			
		||||
  case _datefld: set(as_date() - var.as_int()); break;
 | 
			
		||||
  case _longfld:
 | 
			
		||||
    if (var.type() == _longfld)
 | 
			
		||||
    {
 | 
			
		||||
      set(as_int() - var.as_int());
 | 
			
		||||
      break;
 | 
			
		||||
    }
 | 
			
		||||
    // Fall down
 | 
			
		||||
  default:
 | 
			
		||||
    {
 | 
			
		||||
      real n = as_real();
 | 
			
		||||
      n -= var.as_real();
 | 
			
		||||
      set(n);
 | 
			
		||||
    }
 | 
			
		||||
    break;
 | 
			
		||||
  }
 | 
			
		||||
  return *this;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
///////////////////////////////////////////////////////////
 | 
			
		||||
// TRecordset
 | 
			
		||||
///////////////////////////////////////////////////////////
 | 
			
		||||
 | 
			
		||||
const TVariant& TRecordset::get(const char* column_name) const
 | 
			
		||||
{
 | 
			
		||||
  for (unsigned int i = 0; i < columns(); i++)
 | 
			
		||||
  {
 | 
			
		||||
@ -21,7 +238,7 @@ const TString& TRecordset::get(const char* column_name) const
 | 
			
		||||
    if (info._name == column_name)
 | 
			
		||||
      return get(i);
 | 
			
		||||
  }
 | 
			
		||||
  return EMPTY_STRING;
 | 
			
		||||
  return NULL_VARIANT;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const TString& TRecordset::query_text() const
 | 
			
		||||
@ -49,7 +266,7 @@ const TToken_string& TRecordset::sheet_head() const
 | 
			
		||||
        maxlen = len;
 | 
			
		||||
    }
 | 
			
		||||
    head << '@' << max(ci._width, maxlen);
 | 
			
		||||
    if (ci._numeric)
 | 
			
		||||
    if (ci._type == _longfld || ci._type == _realfld)
 | 
			
		||||
      head << 'R';
 | 
			
		||||
  }
 | 
			
		||||
  return head;
 | 
			
		||||
@ -92,10 +309,10 @@ bool TRecordset::save_as_html(const char* path)
 | 
			
		||||
    {
 | 
			
		||||
      const TRecordset_column_info& ci = column_info(c);
 | 
			
		||||
      out << "  <td";
 | 
			
		||||
      if (ci._numeric)
 | 
			
		||||
      if (ci._type == _longfld || ci._type == _realfld)
 | 
			
		||||
        out << " align=\"right\"";
 | 
			
		||||
      out << ">";
 | 
			
		||||
      val = get(c);
 | 
			
		||||
      get(c).as_string(val);
 | 
			
		||||
      if (!val.blank())
 | 
			
		||||
      {
 | 
			
		||||
        val.rtrim();
 | 
			
		||||
@ -136,7 +353,7 @@ bool TRecordset::save_as_silk(const char* path)
 | 
			
		||||
    for (unsigned int c = 0; c < columns(); c++)
 | 
			
		||||
    {
 | 
			
		||||
      out << "C;Y" << (n+2) << ";X" << (c+1) << ";K\"";
 | 
			
		||||
      val = get(c);
 | 
			
		||||
      get(c).as_string(val);
 | 
			
		||||
      if (!val.blank())
 | 
			
		||||
      {
 | 
			
		||||
        val.rtrim();
 | 
			
		||||
@ -164,7 +381,7 @@ bool TRecordset::save_as_text(const char* path)
 | 
			
		||||
    {
 | 
			
		||||
      if (c > 0)
 | 
			
		||||
        out << '\t';
 | 
			
		||||
      val = get(c);
 | 
			
		||||
      get(c).as_string(val);
 | 
			
		||||
      if (!val.blank())
 | 
			
		||||
      {
 | 
			
		||||
        val.rtrim();
 | 
			
		||||
@ -207,7 +424,7 @@ bool TRecordset::save_as_campo(const char* path)
 | 
			
		||||
    {
 | 
			
		||||
      if (c > 0)
 | 
			
		||||
        out << '|';
 | 
			
		||||
      val = get(c);
 | 
			
		||||
      get(c).as_string(val);
 | 
			
		||||
      if (!val.blank())
 | 
			
		||||
      {
 | 
			
		||||
        val.rtrim();
 | 
			
		||||
@ -320,7 +537,7 @@ protected:
 | 
			
		||||
  void logicnum2name(int logicnum, TString& name) const;
 | 
			
		||||
  int name2logicnum(const TString& name) const;
 | 
			
		||||
 | 
			
		||||
  TString& get_sql_value(const TRectype& curr, const RecFieldDes& fd, TString& tmp) const;
 | 
			
		||||
  TVariant& get_sql_value(const TRectype& curr, const RecFieldDes& fd, TVariant& tmp) const;
 | 
			
		||||
 | 
			
		||||
  void build_curr_path(TFilename& name) const;
 | 
			
		||||
  void test_path();
 | 
			
		||||
@ -478,38 +695,19 @@ int TSQLite::name2logicnum(const TString& name) const
 | 
			
		||||
  return atoi(*cod);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TString& TSQLite::get_sql_value(const TRectype& curr, const RecFieldDes& fd, TString& tmp) const
 | 
			
		||||
TVariant& TSQLite::get_sql_value(const TRectype& curr, const RecFieldDes& fd, TVariant& tmp) const
 | 
			
		||||
{
 | 
			
		||||
  tmp = curr.get(fd.Name);
 | 
			
		||||
  switch (fd.TypeF)
 | 
			
		||||
  {
 | 
			
		||||
  case _realfld    : tmp.set(curr.get_real(fd.Name));  break;
 | 
			
		||||
  case _intfld     :
 | 
			
		||||
  case _longfld    :
 | 
			
		||||
  case _realfld:
 | 
			
		||||
  case _wordfld    :
 | 
			
		||||
    if (real::is_null(tmp))
 | 
			
		||||
      tmp.cut(0);
 | 
			
		||||
    break;
 | 
			
		||||
  case _intzerofld :
 | 
			
		||||
  case _longzerofld:
 | 
			
		||||
    break;
 | 
			
		||||
  case _datefld:
 | 
			
		||||
    tmp = TDate(tmp).string(ANSI);
 | 
			
		||||
    break;
 | 
			
		||||
  case _boolfld:
 | 
			
		||||
    break;
 | 
			
		||||
  default:
 | 
			
		||||
/*
 | 
			
		||||
    if (tmp.find('\'') >= 0)
 | 
			
		||||
    {
 | 
			
		||||
      for (int i = 0; tmp[i]; i++)
 | 
			
		||||
      {
 | 
			
		||||
        if (tmp[i] == '\'')
 | 
			
		||||
          tmp.insert("'", i++);
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
*/
 | 
			
		||||
    break;
 | 
			
		||||
  case _longzerofld: tmp.set(curr.get_long(fd.Name)); break;
 | 
			
		||||
  case _datefld    : tmp.set(curr.get_date(fd.Name)); break;
 | 
			
		||||
  case _boolfld    : tmp.set(curr.get_bool(fd.Name)); break;
 | 
			
		||||
  default          : tmp.set(curr.get(fd.Name)); break;
 | 
			
		||||
  }
 | 
			
		||||
  return tmp;
 | 
			
		||||
}
 | 
			
		||||
@ -533,14 +731,17 @@ bool TSQLite::exists(const char* table)
 | 
			
		||||
bool TSQLite::esporta(const TRectype& rec, ostream& sql) const
 | 
			
		||||
{
 | 
			
		||||
  const RecDes& rd = *rec.rec_des();
 | 
			
		||||
  TString tmp;
 | 
			
		||||
  TVariant tmp;
 | 
			
		||||
  for (int i = 0; i < rd.NFields; i++)
 | 
			
		||||
  {
 | 
			
		||||
    if (i > 0) sql << '\t';
 | 
			
		||||
    if (rd.Fd[i].TypeF == _memofld)
 | 
			
		||||
      sql << "\\N";
 | 
			
		||||
    else
 | 
			
		||||
      sql << get_sql_value(rec, rd.Fd[i], tmp);
 | 
			
		||||
    {
 | 
			
		||||
      get_sql_value(rec, rd.Fd[i], tmp);
 | 
			
		||||
      sql << tmp.as_string();
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  sql << '\n';
 | 
			
		||||
  return true;
 | 
			
		||||
@ -677,6 +878,25 @@ TSQLite::~TSQLite()
 | 
			
		||||
// TSQL_recordset
 | 
			
		||||
///////////////////////////////////////////////////////////
 | 
			
		||||
 | 
			
		||||
static bool is_numeric(const char* str)
 | 
			
		||||
{
 | 
			
		||||
  if (str == NULL || *str == '\0' || *str == '0')
 | 
			
		||||
    return false;    // Se comincia per zero va preservato!
 | 
			
		||||
  if (*str == '-')
 | 
			
		||||
  {
 | 
			
		||||
    str++;
 | 
			
		||||
    if (*str <= ' ')
 | 
			
		||||
      return false;
 | 
			
		||||
  }
 | 
			
		||||
  while (*str)
 | 
			
		||||
  {
 | 
			
		||||
    if (strchr("0123456789.", *str) == NULL)
 | 
			
		||||
      return false;
 | 
			
		||||
    str++;
 | 
			
		||||
  }
 | 
			
		||||
  return true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void TSQL_recordset::reset()
 | 
			
		||||
{
 | 
			
		||||
  _firstrow = _items = 0;
 | 
			
		||||
@ -694,7 +914,7 @@ int TSQL_recordset::on_get_items(int argc, char** values, char** columns)
 | 
			
		||||
      TRecordset_column_info* info = new TRecordset_column_info;
 | 
			
		||||
      info->_name = columns[i];
 | 
			
		||||
      info->_width = 1;
 | 
			
		||||
      info->_numeric = true;
 | 
			
		||||
      info->_type = _realfld;
 | 
			
		||||
      _column.add(info);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
@ -706,8 +926,8 @@ int TSQL_recordset::on_get_items(int argc, char** values, char** columns)
 | 
			
		||||
      const int len = strlen(values[i]);
 | 
			
		||||
      if (len > info._width)
 | 
			
		||||
        info._width = len;
 | 
			
		||||
      if (isalpha(*values[i]))
 | 
			
		||||
        info._numeric = false;
 | 
			
		||||
      if (info._type != _alfafld && isalpha(*values[i]))
 | 
			
		||||
        info._type = _alfafld;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@ -744,9 +964,16 @@ const TRecordset_column_info& TSQL_recordset::column_info(unsigned int c) const
 | 
			
		||||
static int query_get_rows(void* jolly, int argc, char** values, char** columns)
 | 
			
		||||
{
 | 
			
		||||
  TArray& arr = *(TArray*)jolly;
 | 
			
		||||
  TString_array* a = new TString_array;
 | 
			
		||||
  for (int i = 0; i < argc; i++)
 | 
			
		||||
    a->add(values[i], i);
 | 
			
		||||
  TArray* a = new TArray;
 | 
			
		||||
  for (int c = 0; c < argc; c++)
 | 
			
		||||
  {
 | 
			
		||||
    TVariant* var = new TVariant;
 | 
			
		||||
    if (is_numeric(values[c]))
 | 
			
		||||
      var->set(real(values[c]));
 | 
			
		||||
    else
 | 
			
		||||
      var->set(values[c]);
 | 
			
		||||
    a->add(var, c);
 | 
			
		||||
  }
 | 
			
		||||
  arr.add(a);
 | 
			
		||||
  return SQLITE_OK;
 | 
			
		||||
}
 | 
			
		||||
@ -779,24 +1006,24 @@ bool TSQL_recordset::move_to(TRecnotype n)
 | 
			
		||||
  return true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const TString_array* TSQL_recordset::row(TRecnotype n)
 | 
			
		||||
const TArray* TSQL_recordset::row(TRecnotype n)
 | 
			
		||||
{
 | 
			
		||||
  const TString_array* a = NULL;
 | 
			
		||||
  const TArray* a = NULL;
 | 
			
		||||
  if (move_to(n))
 | 
			
		||||
    a = (const TString_array*)_page.objptr(n-_firstrow);
 | 
			
		||||
    a = (const TArray*)_page.objptr(n-_firstrow);
 | 
			
		||||
  return a;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const TString& TSQL_recordset::get(unsigned int c) const
 | 
			
		||||
const TVariant& TSQL_recordset::get(unsigned int c) const
 | 
			
		||||
{
 | 
			
		||||
  const TString_array* a = (const TString_array*)_page.objptr(_current_row-_firstrow);
 | 
			
		||||
  const TArray* a = (const TArray*)_page.objptr(_current_row-_firstrow);
 | 
			
		||||
  if (a != NULL)
 | 
			
		||||
  {
 | 
			
		||||
    const TString* s = (const TString*)a->objptr(c);
 | 
			
		||||
    const TVariant* s = (const TVariant*)a->objptr(c);
 | 
			
		||||
    if (s != NULL)
 | 
			
		||||
      return *s;
 | 
			
		||||
  }
 | 
			
		||||
  return EMPTY_STRING;
 | 
			
		||||
  return NULL_VARIANT;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void TSQL_recordset::set(const char* sql) 
 | 
			
		||||
@ -822,8 +1049,12 @@ void TRecordset_sheet::get_row(long r, TToken_string& row)
 | 
			
		||||
  row.cut(0);
 | 
			
		||||
  if (_query.move_to(r))
 | 
			
		||||
  {
 | 
			
		||||
    TString str;
 | 
			
		||||
    for (unsigned int c = 0; c < _query.columns(); c++)
 | 
			
		||||
      row.add(_query.get(c));
 | 
			
		||||
    {
 | 
			
		||||
      _query.get(c).as_string(str);
 | 
			
		||||
      row.add(str);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										69
									
								
								ba/ba8201.h
									
									
									
									
									
								
							
							
						
						
									
										69
									
								
								ba/ba8201.h
									
									
									
									
									
								
							@ -1,5 +1,5 @@
 | 
			
		||||
#ifndef _RECORDSET_H
 | 
			
		||||
#define _RECORDSET_H
 | 
			
		||||
#ifndef __RECORDSET_H
 | 
			
		||||
#define __RECORDSET_H
 | 
			
		||||
 | 
			
		||||
#ifndef __RECTYPES_H
 | 
			
		||||
#include <rectypes.h>
 | 
			
		||||
@ -13,9 +13,64 @@ struct TRecordset_column_info : public TObject
 | 
			
		||||
{
 | 
			
		||||
  TString _name;
 | 
			
		||||
  int _width;
 | 
			
		||||
  bool _numeric;
 | 
			
		||||
  TFieldtypes _type;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
///////////////////////////////////////////////////////////
 | 
			
		||||
// TVariant
 | 
			
		||||
///////////////////////////////////////////////////////////
 | 
			
		||||
 | 
			
		||||
class TVariant : public TSortable
 | 
			
		||||
{
 | 
			
		||||
  TFieldtypes _type;
 | 
			
		||||
  void* _ptr;
 | 
			
		||||
 | 
			
		||||
protected:
 | 
			
		||||
  virtual int compare(const TSortable& s) const;
 | 
			
		||||
  virtual TObject* dup() const { return new TVariant(*this); }
 | 
			
		||||
  void copy(const TVariant& var);
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
  TFieldtypes type() const { return _type; }
 | 
			
		||||
 | 
			
		||||
  bool is_null() const { return _type == _nullfld; }
 | 
			
		||||
  void set_null();
 | 
			
		||||
  
 | 
			
		||||
  void set(const char* str);
 | 
			
		||||
  void set(const real& r);
 | 
			
		||||
  void set(const long n);
 | 
			
		||||
  void set(const TDate& d);
 | 
			
		||||
 | 
			
		||||
  TVariant& operator=(const TVariant& var) { copy(var); return *this; }
 | 
			
		||||
  TVariant& operator=(const char* str) { set(str); return *this; }
 | 
			
		||||
  TVariant& operator=(const real& r) { set(r); return *this; }
 | 
			
		||||
  TVariant& operator=(const long n) { set(n); return *this; }
 | 
			
		||||
  TVariant& operator=(const TDate& d) { set(d); return *this; }
 | 
			
		||||
 | 
			
		||||
  const TString& as_string() const;
 | 
			
		||||
  bool as_string(TString& str) const;
 | 
			
		||||
  real as_real() const;
 | 
			
		||||
  long as_int() const;
 | 
			
		||||
  TDate as_date() const;
 | 
			
		||||
  bool as_bool() const;
 | 
			
		||||
 | 
			
		||||
  void convert_to(TFieldtypes ft);
 | 
			
		||||
 | 
			
		||||
  TVariant& add(const TVariant& var);
 | 
			
		||||
  TVariant& sub(const TVariant& var);
 | 
			
		||||
 | 
			
		||||
  TVariant() : _type(_nullfld), _ptr(NULL) { }
 | 
			
		||||
  TVariant(const char* str) : _type(_alfafld), _ptr(new TString(str)) { }
 | 
			
		||||
  TVariant(const real& num) : _type(_realfld), _ptr(new real(num)) { };
 | 
			
		||||
  TVariant(const TDate& d) : _type(_datefld), _ptr(new TDate(d)) { };
 | 
			
		||||
  TVariant(long num) : _type(_longfld), _ptr((void*)num) { };
 | 
			
		||||
  TVariant(bool ok) : _type(_longfld), _ptr((void*)ok) { };
 | 
			
		||||
  TVariant(const TVariant& var) : _type(_nullfld), _ptr(NULL) { copy(var); }
 | 
			
		||||
  virtual ~TVariant() { set_null(); }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
extern const TVariant NULL_VARIANT;
 | 
			
		||||
 | 
			
		||||
///////////////////////////////////////////////////////////
 | 
			
		||||
// TRecordset
 | 
			
		||||
///////////////////////////////////////////////////////////
 | 
			
		||||
@ -44,10 +99,10 @@ public: // Absolutely needed methods
 | 
			
		||||
  
 | 
			
		||||
  virtual unsigned int columns() const pure;
 | 
			
		||||
  virtual const TRecordset_column_info& column_info(unsigned int column) const pure;
 | 
			
		||||
  virtual const TString& get(unsigned int column) const pure;
 | 
			
		||||
  virtual const TVariant& get(unsigned int column) const pure;
 | 
			
		||||
 | 
			
		||||
  virtual const TString& query_text() const; 
 | 
			
		||||
  virtual const TString& get(const char* column_name) const;
 | 
			
		||||
  virtual const TVariant& get(const char* column_name) const;
 | 
			
		||||
  virtual const TToken_string& sheet_head() const;
 | 
			
		||||
 | 
			
		||||
  virtual bool save_as(const char* path, TRecordsetExportFormat fmt = fmt_unknown);
 | 
			
		||||
@ -74,7 +129,7 @@ public: // TRecordset
 | 
			
		||||
  virtual TRecnotype current_row() const { return _current_row; }
 | 
			
		||||
  virtual unsigned int columns() const;
 | 
			
		||||
  virtual const TRecordset_column_info& column_info(unsigned int c) const;
 | 
			
		||||
  virtual const TString& get(unsigned int column) const;
 | 
			
		||||
  virtual const TVariant& get(unsigned int column) const;
 | 
			
		||||
  const TString& query_text() const { return _sql; }
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
@ -82,7 +137,7 @@ public:
 | 
			
		||||
 | 
			
		||||
  // Internal use only
 | 
			
		||||
  virtual int on_get_items(int argc, char** values, char** columns);
 | 
			
		||||
  const TString_array* row(TRecnotype n);
 | 
			
		||||
  const TArray* row(TRecnotype n);
 | 
			
		||||
  
 | 
			
		||||
  TSQL_recordset(const char* sql);
 | 
			
		||||
  virtual ~TSQL_recordset() { }
 | 
			
		||||
 | 
			
		||||
@ -1,4 +1,4 @@
 | 
			
		||||
#include <xi.h>
 | 
			
		||||
#include <xinclude.h>
 | 
			
		||||
 | 
			
		||||
#include <applicat.h>
 | 
			
		||||
#include <automask.h>
 | 
			
		||||
@ -11,6 +11,7 @@
 | 
			
		||||
#include "ba8201.h"
 | 
			
		||||
#include "ba8300.h"
 | 
			
		||||
#include "ba8301.h"
 | 
			
		||||
#include "ba8303.h"
 | 
			
		||||
#include <bagn003.h>
 | 
			
		||||
 | 
			
		||||
///////////////////////////////////////////////////////////
 | 
			
		||||
@ -72,10 +73,13 @@ public:
 | 
			
		||||
void TFont_button_mask::update()
 | 
			
		||||
{
 | 
			
		||||
  const TMask_field& fld = field(F_FONT_SELECT);
 | 
			
		||||
  if (fld.active())
 | 
			
		||||
  if (fld.active() && win() == win(0))
 | 
			
		||||
  {
 | 
			
		||||
    RCT rct; fld.get_rect(rct);
 | 
			
		||||
    xvt_rect_offset(&rct, rct.right-rct.left + 4*CHARX, 0);
 | 
			
		||||
    RCT rctfld; fld.get_rect(rctfld); 
 | 
			
		||||
    const int x = rctfld.right / CHARX + 1;
 | 
			
		||||
    const int y = rctfld.top / ROWY + 1;
 | 
			
		||||
    RCT& rct = resize_rect(x, y, -3, 2, W_PLAIN, win()); 
 | 
			
		||||
    rct.top =  rctfld.top; rct.bottom = rctfld.bottom;
 | 
			
		||||
    xi_draw_3d_rect((XinWindow)win(), (XinRect*)&rct, TRUE, 2, MASK_LIGHT_COLOR, 
 | 
			
		||||
      _bgcolor, MASK_DARK_COLOR);
 | 
			
		||||
 | 
			
		||||
@ -145,7 +149,7 @@ bool TFont_button_mask::get_font_info(TReport_font& font) const
 | 
			
		||||
 | 
			
		||||
TFont_button_mask::TFont_button_mask(const char* name) 
 | 
			
		||||
                 : TAutomask(name), _font_changed(false),
 | 
			
		||||
                   _halign('L'), _valign('B'),
 | 
			
		||||
                   _halign('C'), _valign('C'),
 | 
			
		||||
                   _fgcolor(COLOR_BLACK), _bgcolor(COLOR_WHITE)
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
@ -182,20 +186,26 @@ long TReport_field_mask::get_num(short id) const
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void TReport_field_mask::update()
 | 
			
		||||
{
 | 
			
		||||
  if (win() == win(0))
 | 
			
		||||
  {
 | 
			
		||||
    for (int i = 0; i < 2; i++)
 | 
			
		||||
    {
 | 
			
		||||
      TMask_field& fld = field(i == 0 ? F_FGCOLOR : F_BGCOLOR);
 | 
			
		||||
      if (fld.active())
 | 
			
		||||
      {
 | 
			
		||||
      RCT rct; fld.get_rect(rct);
 | 
			
		||||
      xvt_rect_offset(&rct, rct.right-rct.left + 4*CHARX, 0);
 | 
			
		||||
        RCT rctfld; fld.get_rect(rctfld); 
 | 
			
		||||
        const int x = rctfld.right / CHARX + 1;
 | 
			
		||||
        const int y = rctfld.top / ROWY + 1;
 | 
			
		||||
        RCT& rct = resize_rect(x, y, -3, 1, W_PLAIN, win());
 | 
			
		||||
        rct.top =  rctfld.top; rct.bottom = rctfld.bottom;
 | 
			
		||||
        xi_draw_3d_rect((XinWindow)win(), (XinRect*)&rct, TRUE, 2, MASK_LIGHT_COLOR, 
 | 
			
		||||
          i == 0 ? _fgcolor : _bgcolor, MASK_DARK_COLOR);
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    TFont_button_mask::update();
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool TReport_field_mask::on_field_event(TOperable_field& o, TField_event e, long jolly) 
 | 
			
		||||
{ 
 | 
			
		||||
@ -237,10 +247,13 @@ void TReport_field_mask::set_field(const TReport_field& rf)
 | 
			
		||||
  set(F_TYPE, str);
 | 
			
		||||
 | 
			
		||||
  const TRectangle& r = rf.get_rect();
 | 
			
		||||
  set(F_ID, rf.id());
 | 
			
		||||
  set_num(F_X, r.left());
 | 
			
		||||
  set_num(F_Y, r.top());
 | 
			
		||||
  set_num(F_DX, r.width());
 | 
			
		||||
  set_num(F_DY, r.height());
 | 
			
		||||
  set(F_HIDDEN, rf.hidden() ? "X" : "");
 | 
			
		||||
  set(F_DISABLED, rf.deactivated() ? "X" : "");
 | 
			
		||||
  str[0] = rf.horizontal_alignment();
 | 
			
		||||
  set(F_HALIGN, str);
 | 
			
		||||
  str[0] = rf.vertical_alignment();
 | 
			
		||||
@ -251,13 +264,18 @@ void TReport_field_mask::set_field(const TReport_field& rf)
 | 
			
		||||
  set(F_TEXT, rf.picture());
 | 
			
		||||
  set(F_SOURCE, rf.field());
 | 
			
		||||
  set_font_info(rf.font());
 | 
			
		||||
  set(F_PRESCRIPT, rf.prescript());
 | 
			
		||||
  set(F_POSTSCRIPT, rf.postscript());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void TReport_field_mask::get_field(TReport_field& rf) const
 | 
			
		||||
{
 | 
			
		||||
  rf.set_type(get(F_TYPE)[0]);
 | 
			
		||||
  rf.set_id(get_int(F_ID));
 | 
			
		||||
  rf.set_pos(get_num(F_X), get_num(F_Y));
 | 
			
		||||
  rf.set_size(get_num(F_DX), get_num(F_DY));
 | 
			
		||||
  rf.show(!get_bool(F_HIDDEN));
 | 
			
		||||
  rf.activate(!get_bool(F_DISABLED));
 | 
			
		||||
  rf.set_horizontal_alignment(get(F_HALIGN)[0]);
 | 
			
		||||
  rf.set_vertical_alignment(get(F_VALIGN)[0]);
 | 
			
		||||
  rf.set_border(get_int(F_BORDER));
 | 
			
		||||
@ -268,6 +286,8 @@ void TReport_field_mask::get_field(TReport_field& rf) const
 | 
			
		||||
  TReport_font f;
 | 
			
		||||
  if (get_font_info(f))
 | 
			
		||||
    rf.set_font(f);
 | 
			
		||||
  rf.set_prescript(get(F_PRESCRIPT));
 | 
			
		||||
  rf.set_postscript(get(F_POSTSCRIPT));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
///////////////////////////////////////////////////////////
 | 
			
		||||
@ -295,12 +315,15 @@ void TReport_sheet::get_row(long r, TToken_string& row)
 | 
			
		||||
  row.cut(0);
 | 
			
		||||
  row.add(checked(r) ? "X" : " ");
 | 
			
		||||
  row.add(rf.type_name());
 | 
			
		||||
  row.add(rf.id());
 | 
			
		||||
  row.add(num2str(rect.top()));
 | 
			
		||||
  row.add(num2str(rect.left()));
 | 
			
		||||
  row.add(num2str(rect.width()));
 | 
			
		||||
  row.add(num2str(rect.height()));
 | 
			
		||||
  row.add(rf.picture());
 | 
			
		||||
  if (rf.field().not_empty())
 | 
			
		||||
    row.add(rf.field());
 | 
			
		||||
  else
 | 
			
		||||
    row.add(rf.picture());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int TReport_sheet::selection(int& first, int& last) const
 | 
			
		||||
@ -350,7 +373,7 @@ KEY TReport_sheet::run()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TReport_sheet::TReport_sheet(TReport_section& sec)
 | 
			
		||||
             : TSheet(-1, -1, -2, -4, "Campi", "@1|Tipo@10|Riga@R|Col.@R|Larg.@R|Alt.@R|Testo@30|Campo@30", 0xE),
 | 
			
		||||
             : TSheet(-1, -1, -2, -4, "Campi", "@1|Tipo@10|ID@4R|Riga@R|Col.@R|Larg.@R|Alt.@R|Testo@50", 0xE),
 | 
			
		||||
               _section(sec)
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
@ -389,7 +412,7 @@ void TSection_properties_mask::vedo_non_vedo()
 | 
			
		||||
{
 | 
			
		||||
  const char type = get(F_TYPE)[0];
 | 
			
		||||
  const int level = get_int(F_LEVEL);
 | 
			
		||||
  show(F_GROUP_BY, level > 1 && type != 'B');
 | 
			
		||||
  show(F_GROUP_BY, type == 'H' && level > 1);
 | 
			
		||||
  show(F_HIDE_IF_NEEDED, level == 0 && type != 'B');
 | 
			
		||||
  enable(DLG_DELREC, level > 1);
 | 
			
		||||
}
 | 
			
		||||
@ -428,8 +451,13 @@ void TSection_properties_mask::set_section(const TReport_section& rs)
 | 
			
		||||
 
 | 
			
		||||
  set(F_GROUP_BY, rs.grouped_by());
 | 
			
		||||
  set(F_HIDE_IF_NEEDED, rs.hidden_if_needed() ? "X" : "");
 | 
			
		||||
  set(F_HIDDEN, rs.hidden() ? "X" : "");
 | 
			
		||||
  set(F_DISABLED, rs.deactivated() ? "X" : "");
 | 
			
		||||
 | 
			
		||||
  set_font_info(rs.font());
 | 
			
		||||
  set(F_PRESCRIPT, rs.prescript());
 | 
			
		||||
  set(F_POSTSCRIPT, rs.postscript());
 | 
			
		||||
 | 
			
		||||
  vedo_non_vedo();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -437,12 +465,18 @@ void TSection_properties_mask::get_section(TReport_section& rs) const
 | 
			
		||||
{
 | 
			
		||||
  rs.set_width(get_num(F_DX));
 | 
			
		||||
  rs.set_height(get_num(F_DY));
 | 
			
		||||
  rs.show(!get_bool(F_HIDDEN));
 | 
			
		||||
  rs.activate(!get_bool(F_DISABLED));
 | 
			
		||||
 | 
			
		||||
  rs.group_by(get(F_GROUP_BY));
 | 
			
		||||
  rs.hide_if_needed(get_bool(F_HIDE_IF_NEEDED));
 | 
			
		||||
 | 
			
		||||
  TReport_font f;
 | 
			
		||||
  if (get_font_info(f))
 | 
			
		||||
    rs.set_font(f);
 | 
			
		||||
 | 
			
		||||
  rs.set_prescript(get(F_PRESCRIPT));
 | 
			
		||||
  rs.set_postscript(get(F_POSTSCRIPT));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TSection_properties_mask::TSection_properties_mask() 
 | 
			
		||||
@ -508,6 +542,7 @@ protected:
 | 
			
		||||
  void add_field();
 | 
			
		||||
  void edit_field(TReport_field& rf);
 | 
			
		||||
  void fields_properties();
 | 
			
		||||
  void add_section();
 | 
			
		||||
  void section_properties();
 | 
			
		||||
  void report_properties();
 | 
			
		||||
 | 
			
		||||
@ -768,6 +803,36 @@ void TReport_mask::fields_properties()
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void TReport_mask::add_section()
 | 
			
		||||
{
 | 
			
		||||
  TMask m(TR("Nuova sezione"), 1, 32, 5);
 | 
			
		||||
  m.add_radio(101, 0, "", 1, 0, 22, "H|B", TR("Raggruppamento|Corpo alternativo"), "");
 | 
			
		||||
  m.add_button(DLG_OK, 0, "", -12, -1, 10, 2);
 | 
			
		||||
  m.add_button(DLG_CANCEL, 0, "", -22, -1, 10, 2);
 | 
			
		||||
  if (m.run() == K_ENTER)
 | 
			
		||||
  {
 | 
			
		||||
    const char type = m.get(101)[0];
 | 
			
		||||
    int level = 0;
 | 
			
		||||
    if (type == 'H')
 | 
			
		||||
    {
 | 
			
		||||
      const int hl = _report.find_max_level('H');
 | 
			
		||||
      const int fl = _report.find_max_level('F');
 | 
			
		||||
      level = max(hl, fl) + 1;
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
      level = _report.find_max_level('B')+1;
 | 
			
		||||
    
 | 
			
		||||
    if (level > 1 && level <= 9)
 | 
			
		||||
    {
 | 
			
		||||
      _tree.goto_node(type, level);
 | 
			
		||||
      tfield(F_SECTIONS).select_current();
 | 
			
		||||
      section_properties();
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
      error_box(TR("Livello non ammesso: %d"), level);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void TReport_mask::section_properties()
 | 
			
		||||
{
 | 
			
		||||
  TReport_section& rs = curr_section();
 | 
			
		||||
@ -780,8 +845,14 @@ void TReport_mask::section_properties()
 | 
			
		||||
    _is_dirty = true;
 | 
			
		||||
    break;
 | 
			
		||||
  case K_DEL: 
 | 
			
		||||
    rs.report().kill_section(rs.type(), rs.level()); 
 | 
			
		||||
    {
 | 
			
		||||
      const char t = rs.type();
 | 
			
		||||
      const int l = rs.level();
 | 
			
		||||
      rs.report().kill_section(t, l); 
 | 
			
		||||
      _tree.goto_node(t, l-1);
 | 
			
		||||
      tfield(F_SECTIONS).select_current();
 | 
			
		||||
      _is_dirty = true;
 | 
			
		||||
    }
 | 
			
		||||
    break;
 | 
			
		||||
  default: 
 | 
			
		||||
    break;
 | 
			
		||||
@ -828,7 +899,7 @@ bool TReport_mask::on_field_event(TOperable_field& o, TField_event e, long jolly
 | 
			
		||||
      enable(-1, ok);
 | 
			
		||||
    }
 | 
			
		||||
    break;
 | 
			
		||||
  case F_TYPE:
 | 
			
		||||
  case F_FLD_ADD:
 | 
			
		||||
    if (e == fe_button && o.active())
 | 
			
		||||
      add_field();
 | 
			
		||||
    break;
 | 
			
		||||
@ -836,6 +907,10 @@ bool TReport_mask::on_field_event(TOperable_field& o, TField_event e, long jolly
 | 
			
		||||
    if (e == fe_button && o.active())
 | 
			
		||||
      fields_properties();
 | 
			
		||||
    break;
 | 
			
		||||
  case F_SEC_ADD:
 | 
			
		||||
    if (e == fe_button && o.active())
 | 
			
		||||
      add_section();
 | 
			
		||||
    break;
 | 
			
		||||
  case F_SEC_PROPERTIES:
 | 
			
		||||
    if (e == fe_button && o.active())
 | 
			
		||||
      section_properties();
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										16
									
								
								ba/ba8300.h
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								ba/ba8300.h
									
									
									
									
									
								
							@ -3,10 +3,14 @@
 | 
			
		||||
 | 
			
		||||
#define F_SECTIONS       103
 | 
			
		||||
#define F_REPORT         104
 | 
			
		||||
#define F_TYPE           105
 | 
			
		||||
#define F_FLD_ADD        105
 | 
			
		||||
#define F_FLD_PROPERTIES 106
 | 
			
		||||
#define F_SEC_PROPERTIES 107
 | 
			
		||||
#define F_REP_PROPERTIES 108
 | 
			
		||||
#define F_SEC_ADD        107
 | 
			
		||||
#define F_SEC_PROPERTIES 108
 | 
			
		||||
#define F_REP_PROPERTIES 109
 | 
			
		||||
 | 
			
		||||
#define F_TYPE           109
 | 
			
		||||
#define F_ID             110
 | 
			
		||||
#define F_X              111
 | 
			
		||||
#define F_Y              112
 | 
			
		||||
#define F_DX             113
 | 
			
		||||
@ -19,9 +23,15 @@
 | 
			
		||||
#define F_FGCOLOR        120
 | 
			
		||||
#define F_BGCOLOR        121
 | 
			
		||||
#define F_FONT_SELECT    122
 | 
			
		||||
#define F_HIDDEN         123
 | 
			
		||||
#define F_DISABLED       124
 | 
			
		||||
#define F_PRESCRIPT      125
 | 
			
		||||
#define F_POSTSCRIPT     126
 | 
			
		||||
 | 
			
		||||
#define F_LEVEL          130
 | 
			
		||||
#define F_GROUP_BY       131
 | 
			
		||||
#define F_HIDE_IF_NEEDED 132
 | 
			
		||||
#define F_PAGE_BREAK     133
 | 
			
		||||
 | 
			
		||||
#define F_SQL            201
 | 
			
		||||
#define F_IMPORT_QRY     202
 | 
			
		||||
 | 
			
		||||
@ -43,14 +43,9 @@ ENDPAGE
 | 
			
		||||
 | 
			
		||||
PAGE "@bReport" -1 -1 78 23
 | 
			
		||||
 | 
			
		||||
GROUPBOX DLG_NULL 78 3
 | 
			
		||||
BEGIN
 | 
			
		||||
  PROMPT 1 0 "Report"
 | 
			
		||||
END
 | 
			
		||||
 | 
			
		||||
STRING F_CODICE 16
 | 
			
		||||
BEGIN
 | 
			
		||||
  PROMPT 2 1 "Codice "
 | 
			
		||||
  PROMPT 1 0 "Report "
 | 
			
		||||
  FLAGS "B"
 | 
			
		||||
  WARNING "E' necessario specificare il codice"
 | 
			
		||||
  CHECKTYPE REQUIRED
 | 
			
		||||
@ -58,22 +53,22 @@ END
 | 
			
		||||
 | 
			
		||||
STRING F_DESCR 50 46
 | 
			
		||||
BEGIN
 | 
			
		||||
  PROMPT 30 1 ""
 | 
			
		||||
  PROMPT 30 0 ""
 | 
			
		||||
END
 | 
			
		||||
 | 
			
		||||
TREE F_SECTIONS 30 12
 | 
			
		||||
BEGIN
 | 
			
		||||
  PROMPT 0 3 ""
 | 
			
		||||
  PROMPT 0 1 ""
 | 
			
		||||
END
 | 
			
		||||
 | 
			
		||||
REPORT F_REPORT -3 -3
 | 
			
		||||
BEGIN
 | 
			
		||||
  PROMPT 21 3 ""
 | 
			
		||||
  PROMPT 21 1 ""
 | 
			
		||||
END
 | 
			
		||||
 | 
			
		||||
BUTTON F_TYPE 10 2
 | 
			
		||||
BUTTON F_FLD_ADD 10 2
 | 
			
		||||
BEGIN
 | 
			
		||||
  PROMPT -16 -1 "Campo"
 | 
			
		||||
  PROMPT -16 -1 "Campo +"
 | 
			
		||||
  GROUP 1
 | 
			
		||||
END
 | 
			
		||||
 | 
			
		||||
@ -83,25 +78,21 @@ BEGIN
 | 
			
		||||
  GROUP 1
 | 
			
		||||
END
 | 
			
		||||
 | 
			
		||||
BUTTON F_SEC_ADD 10 2
 | 
			
		||||
BEGIN
 | 
			
		||||
  PROMPT -36 -1 "Sezione +"
 | 
			
		||||
  GROUP 1
 | 
			
		||||
END
 | 
			
		||||
 | 
			
		||||
BUTTON F_SEC_PROPERTIES 10 2
 | 
			
		||||
BEGIN
 | 
			
		||||
  PROMPT -36 -1 "Sezione"
 | 
			
		||||
  PROMPT -46 -1 "Sezione"
 | 
			
		||||
  GROUP 1
 | 
			
		||||
END
 | 
			
		||||
 | 
			
		||||
BUTTON F_REP_PROPERTIES 10 2
 | 
			
		||||
BEGIN
 | 
			
		||||
  PROMPT -46 -1 "Generali"
 | 
			
		||||
END
 | 
			
		||||
 | 
			
		||||
NUMBER F_Y 3
 | 
			
		||||
BEGIN
 | 
			
		||||
  PROMPT 58 -1 "Riga "
 | 
			
		||||
END
 | 
			
		||||
 | 
			
		||||
NUMBER F_X 3
 | 
			
		||||
BEGIN
 | 
			
		||||
  PROMPT 68 -1 "Colonna "
 | 
			
		||||
  PROMPT -66 -1 "Report"
 | 
			
		||||
END
 | 
			
		||||
 | 
			
		||||
ENDPAGE
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										114
									
								
								ba/ba8300b.uml
									
									
									
									
									
								
							
							
						
						
									
										114
									
								
								ba/ba8300b.uml
									
									
									
									
									
								
							@ -1,10 +1,10 @@
 | 
			
		||||
#include "ba8300.h"
 | 
			
		||||
 | 
			
		||||
PAGE "Campo" -1 -1 60 15
 | 
			
		||||
PAGE "Campo" -1 -1 72 17
 | 
			
		||||
 | 
			
		||||
RADIOBUTTON F_TYPE 1 16
 | 
			
		||||
LIST F_TYPE 1 16
 | 
			
		||||
BEGIN
 | 
			
		||||
  PROMPT 1 0 "@bTipo"
 | 
			
		||||
  PROMPT 2 1 "Tipo "
 | 
			
		||||
  ITEM "T|Testo"
 | 
			
		||||
    MESSAGE SHOW,1@|HIDE,F_SOURCE
 | 
			
		||||
  ITEM "S|Stringa"
 | 
			
		||||
@ -23,38 +23,60 @@ BEGIN
 | 
			
		||||
    MESSAGE HIDE,1@|SHOW,F_SOURCE
 | 
			
		||||
END
 | 
			
		||||
 | 
			
		||||
GROUPBOX DLG_NULL 40 11
 | 
			
		||||
GROUPBOX DLG_NULL 70 5
 | 
			
		||||
BEGIN
 | 
			
		||||
  PROMPT 18 0 "@bParametri"
 | 
			
		||||
  PROMPT 1 0 "@bParametri generali"
 | 
			
		||||
END
 | 
			
		||||
 | 
			
		||||
NUMBER F_ID 4
 | 
			
		||||
BEGIN
 | 
			
		||||
  PROMPT 30 1 "Identificatore "
 | 
			
		||||
  FLAGS "U"
 | 
			
		||||
END
 | 
			
		||||
 | 
			
		||||
STRING F_Y 6
 | 
			
		||||
BEGIN
 | 
			
		||||
  PROMPT 20 1 "Riga      "
 | 
			
		||||
  PROMPT 2 2 "Riga      "
 | 
			
		||||
  FLAGS "R"
 | 
			
		||||
END
 | 
			
		||||
 | 
			
		||||
STRING F_X 6
 | 
			
		||||
BEGIN
 | 
			
		||||
  PROMPT 40 1 "Colonna "
 | 
			
		||||
  PROMPT 21 2 "Colonna "
 | 
			
		||||
  FLAGS "R"
 | 
			
		||||
END
 | 
			
		||||
 | 
			
		||||
STRING F_DX 6
 | 
			
		||||
BEGIN
 | 
			
		||||
  PROMPT 20 2 "Larghezza "
 | 
			
		||||
  PROMPT 2 3 "Larghezza "
 | 
			
		||||
  FLAGS "R"
 | 
			
		||||
END
 | 
			
		||||
 | 
			
		||||
STRING F_DY 6
 | 
			
		||||
BEGIN
 | 
			
		||||
  PROMPT 40 2 "Altezza "
 | 
			
		||||
  PROMPT 21 3 "Altezza "
 | 
			
		||||
  FLAGS "R"
 | 
			
		||||
END
 | 
			
		||||
 | 
			
		||||
BOOLEAN F_HIDDEN
 | 
			
		||||
BEGIN
 | 
			
		||||
  PROMPT 41 2 "Nascosto"
 | 
			
		||||
END
 | 
			
		||||
 | 
			
		||||
BOOLEAN F_DISABLED
 | 
			
		||||
BEGIN
 | 
			
		||||
  PROMPT 41 3 "Disattivato"
 | 
			
		||||
END
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
GROUPBOX DLG_NULL 70 8
 | 
			
		||||
BEGIN
 | 
			
		||||
  PROMPT 1 5 "@bParametri aspetto"
 | 
			
		||||
END
 | 
			
		||||
 | 
			
		||||
LIST F_HALIGN 1 12
 | 
			
		||||
BEGIN
 | 
			
		||||
  PROMPT 20 3 "Allineamento orizz. "
 | 
			
		||||
  PROMPT 2 6 "Allineamento orizzontale "
 | 
			
		||||
  ITEM "L|Sinistra"
 | 
			
		||||
  ITEM "R|Destra"
 | 
			
		||||
  ITEM "C|Centrato"
 | 
			
		||||
@ -64,46 +86,46 @@ END
 | 
			
		||||
 | 
			
		||||
LIST F_VALIGN 1 12
 | 
			
		||||
BEGIN
 | 
			
		||||
  PROMPT 20 4 "Allineamento vert.  "
 | 
			
		||||
  ITEM "B|Basso"
 | 
			
		||||
  ITEM "C|Centrato"
 | 
			
		||||
  PROMPT 44 6 "verticale "
 | 
			
		||||
  ITEM "T|Alto"
 | 
			
		||||
  ITEM "C|Centrato"
 | 
			
		||||
  ITEM "B|Basso"
 | 
			
		||||
  GROUP 1
 | 
			
		||||
END
 | 
			
		||||
 | 
			
		||||
BUTTON F_FGCOLOR 14 1
 | 
			
		||||
BEGIN
 | 
			
		||||
  PROMPT 2 7 "Colore ~Testo"
 | 
			
		||||
END
 | 
			
		||||
 | 
			
		||||
BUTTON F_BGCOLOR 14 1
 | 
			
		||||
BEGIN
 | 
			
		||||
  PROMPT 2 8 "Colore ~Sfondo"
 | 
			
		||||
END
 | 
			
		||||
 | 
			
		||||
BUTTON F_FONT_SELECT 14 2
 | 
			
		||||
BEGIN
 | 
			
		||||
  PROMPT 2 9 "~Font"
 | 
			
		||||
  GROUP 1
 | 
			
		||||
END
 | 
			
		||||
 | 
			
		||||
LIST F_BORDER 1 12
 | 
			
		||||
BEGIN
 | 
			
		||||
  PROMPT 20 5 "Bordo               "
 | 
			
		||||
  PROMPT 2 11 "Bordo "
 | 
			
		||||
  ITEM "0|Nessuno"
 | 
			
		||||
  ITEM "1|Normale"
 | 
			
		||||
  ITEM "3|Spesso"
 | 
			
		||||
END
 | 
			
		||||
 | 
			
		||||
BUTTON F_FGCOLOR 14 1
 | 
			
		||||
ZOOM F_TEXT 58
 | 
			
		||||
BEGIN
 | 
			
		||||
  PROMPT 20 6 "Colore ~Testo"
 | 
			
		||||
END
 | 
			
		||||
 | 
			
		||||
BUTTON F_BGCOLOR 14 1
 | 
			
		||||
BEGIN
 | 
			
		||||
  PROMPT 20 7 "Colore ~Sfondo"
 | 
			
		||||
END
 | 
			
		||||
 | 
			
		||||
BUTTON F_FONT_SELECT 14 2
 | 
			
		||||
BEGIN
 | 
			
		||||
  PROMPT 20 8 "~Font"
 | 
			
		||||
  PROMPT 1 13 "Testo    "
 | 
			
		||||
  GROUP 1
 | 
			
		||||
END
 | 
			
		||||
 | 
			
		||||
STRING F_TEXT 196 50
 | 
			
		||||
ZOOM F_SOURCE 58 
 | 
			
		||||
BEGIN
 | 
			
		||||
  PROMPT 1 12 "Formato "
 | 
			
		||||
  GROUP 1
 | 
			
		||||
END
 | 
			
		||||
 | 
			
		||||
STRING F_SOURCE 80 50 
 | 
			
		||||
BEGIN
 | 
			
		||||
  PROMPT 1 13 "Dato    "
 | 
			
		||||
  PROMPT 1 14 "Sorgente "
 | 
			
		||||
  GROUP 1
 | 
			
		||||
END
 | 
			
		||||
 | 
			
		||||
@ -124,5 +146,29 @@ END
 | 
			
		||||
 | 
			
		||||
ENDPAGE
 | 
			
		||||
 | 
			
		||||
PAGE "Avanzate" -1 -1 72 16
 | 
			
		||||
 | 
			
		||||
MEMO F_PRESCRIPT 70 7
 | 
			
		||||
BEGIN
 | 
			
		||||
  PROMPT 1 0 "Script iniziale"
 | 
			
		||||
END
 | 
			
		||||
 | 
			
		||||
MEMO F_POSTSCRIPT 70 7
 | 
			
		||||
BEGIN
 | 
			
		||||
  PROMPT 1 7 "Script finale"
 | 
			
		||||
END
 | 
			
		||||
 | 
			
		||||
BUTTON DLG_CANCEL 10 2
 | 
			
		||||
BEGIN
 | 
			
		||||
  PROMPT -13 -1 ""
 | 
			
		||||
END
 | 
			
		||||
 | 
			
		||||
BUTTON DLG_OK 10 2
 | 
			
		||||
BEGIN
 | 
			
		||||
  PROMPT -33 -1 ""
 | 
			
		||||
END
 | 
			
		||||
 | 
			
		||||
ENDMASK
 | 
			
		||||
 | 
			
		||||
ENDMASK
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -1,6 +1,6 @@
 | 
			
		||||
#include "ba8300.h"
 | 
			
		||||
 | 
			
		||||
PAGE "Sezione" -1 -1 60 13
 | 
			
		||||
PAGE "Sezione" -1 -1 50 16
 | 
			
		||||
 | 
			
		||||
LISTBOX F_TYPE 1 8
 | 
			
		||||
BEGIN
 | 
			
		||||
@ -19,37 +19,52 @@ END
 | 
			
		||||
 | 
			
		||||
STRING F_DX 6
 | 
			
		||||
BEGIN
 | 
			
		||||
  PROMPT 1 2 "Larghezza "
 | 
			
		||||
  PROMPT 1 3 "Larghezza "
 | 
			
		||||
  FLAGS "R"
 | 
			
		||||
END
 | 
			
		||||
 | 
			
		||||
STRING F_DY 6
 | 
			
		||||
BEGIN
 | 
			
		||||
  PROMPT 21 2 "Altezza "
 | 
			
		||||
  PROMPT 21 3 "Altezza "
 | 
			
		||||
  FLAGS "R"
 | 
			
		||||
END
 | 
			
		||||
 | 
			
		||||
STRING F_GROUP_BY 80 50
 | 
			
		||||
BOOLEAN F_HIDDEN
 | 
			
		||||
BEGIN
 | 
			
		||||
  // Visibile per sezioni con livello > 1
 | 
			
		||||
  PROMPT 1 3 "Raggruppamento "
 | 
			
		||||
  FLAGS "H"
 | 
			
		||||
  CHECKTYPE REQUIRED
 | 
			
		||||
  PROMPT 1 4 "Nascosta"
 | 
			
		||||
END
 | 
			
		||||
 | 
			
		||||
BOOLEAN F_DISABLED
 | 
			
		||||
BEGIN
 | 
			
		||||
  PROMPT 21 4 "Disattivata"
 | 
			
		||||
END
 | 
			
		||||
 | 
			
		||||
BOOLEAN F_PAGE_BREAK
 | 
			
		||||
BEGIN
 | 
			
		||||
  PROMPT 1 5 "Forza salto pagina"
 | 
			
		||||
END
 | 
			
		||||
 | 
			
		||||
BOOLEAN F_HIDE_IF_NEEDED
 | 
			
		||||
BEGIN
 | 
			
		||||
  // Visibile per testa e coda di pagina
 | 
			
		||||
  PROMPT 1 3 "Nascondi sezione sulla prima/ultima pagina"
 | 
			
		||||
  PROMPT 1 6 "Nascondi sezione sulla prima/ultima pagina"
 | 
			
		||||
  FLAGS "H"
 | 
			
		||||
END
 | 
			
		||||
 | 
			
		||||
MEMO F_GROUP_BY 48 3
 | 
			
		||||
BEGIN
 | 
			
		||||
  // Visibile per sezioni con livello > 1
 | 
			
		||||
  PROMPT 1 6 "Raggruppamento "
 | 
			
		||||
  FLAGS "H"
 | 
			
		||||
  CHECKTYPE REQUIRED
 | 
			
		||||
END
 | 
			
		||||
 | 
			
		||||
BUTTON F_FONT_SELECT 10 2
 | 
			
		||||
BEGIN
 | 
			
		||||
  PROMPT -13 -3 "~Font"
 | 
			
		||||
END
 | 
			
		||||
 | 
			
		||||
BUTTON DLG_CANCEL 10 2
 | 
			
		||||
BUTTON DLG_OK 10 2
 | 
			
		||||
BEGIN
 | 
			
		||||
  PROMPT -13 -1 ""
 | 
			
		||||
END
 | 
			
		||||
@ -59,12 +74,35 @@ BEGIN
 | 
			
		||||
  PROMPT -23 -1 ""
 | 
			
		||||
END
 | 
			
		||||
 | 
			
		||||
BUTTON DLG_OK 10 2
 | 
			
		||||
BUTTON DLG_CANCEL 10 2
 | 
			
		||||
BEGIN
 | 
			
		||||
  PROMPT -33 -1 ""
 | 
			
		||||
END
 | 
			
		||||
 | 
			
		||||
ENDPAGE
 | 
			
		||||
 | 
			
		||||
PAGE "Avanzate" -1 -1 50 16
 | 
			
		||||
 | 
			
		||||
MEMO F_PRESCRIPT 48 7
 | 
			
		||||
BEGIN
 | 
			
		||||
  PROMPT 1 0 "Script iniziale"
 | 
			
		||||
END
 | 
			
		||||
 | 
			
		||||
MEMO F_POSTSCRIPT 48 7
 | 
			
		||||
BEGIN
 | 
			
		||||
  PROMPT 1 7 "Script finale"
 | 
			
		||||
END
 | 
			
		||||
 | 
			
		||||
BUTTON DLG_CANCEL 10 2
 | 
			
		||||
BEGIN
 | 
			
		||||
  PROMPT -13 -1 ""
 | 
			
		||||
END
 | 
			
		||||
 | 
			
		||||
BUTTON DLG_OK 10 2
 | 
			
		||||
BEGIN
 | 
			
		||||
  PROMPT -33 -1 ""
 | 
			
		||||
END
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
ENDMASK
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										198
									
								
								ba/ba8301.cpp
									
									
									
									
									
								
							
							
						
						
									
										198
									
								
								ba/ba8301.cpp
									
									
									
									
									
								
							@ -1,4 +1,5 @@
 | 
			
		||||
#include <xi.h>
 | 
			
		||||
#include <xinclude.h>
 | 
			
		||||
#include <statbar.h>
 | 
			
		||||
 | 
			
		||||
#include <diction.h>
 | 
			
		||||
#include <image.h>
 | 
			
		||||
@ -13,19 +14,43 @@
 | 
			
		||||
 | 
			
		||||
bool TReport_tree::get_description(TString& str) const
 | 
			
		||||
{
 | 
			
		||||
  str.cut(0);
 | 
			
		||||
  switch (_curr[0])
 | 
			
		||||
  const char type = _curr[0];
 | 
			
		||||
  const int level = atoi(_curr.mid(1));
 | 
			
		||||
  str = "     ";
 | 
			
		||||
  if (level <= 0)
 | 
			
		||||
  {
 | 
			
		||||
  case 'H': str << "    " << TR("Testa");  break;
 | 
			
		||||
  case 'B': str << "    " << TR("Corpo");  break;
 | 
			
		||||
  case 'F': str << "    " << TR("Coda");   break;
 | 
			
		||||
  case 'P': str << TR("Pagina"); break;   // Virtual section
 | 
			
		||||
  case 'R': str << TR("Report"); break;   // Virtual section
 | 
			
		||||
  case 'S': str << TR("Speciali"); break; // Virtual section
 | 
			
		||||
    switch (type)
 | 
			
		||||
    {
 | 
			
		||||
    case 'H': str << TR("Testa");  break;
 | 
			
		||||
    case 'B': str << TR("Sfondo");  break;
 | 
			
		||||
    case 'F': str << TR("Coda");   break;
 | 
			
		||||
    case 'P': str = TR("Pagina"); break;   // Virtual section
 | 
			
		||||
    case 'R': str = TR("Report"); break;   // Virtual section
 | 
			
		||||
    default : break;
 | 
			
		||||
    }
 | 
			
		||||
  if (_curr[1] > '0')
 | 
			
		||||
    str << ' ' << _curr[1];
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    switch (type)
 | 
			
		||||
    {
 | 
			
		||||
    case 'H': str << TR("Testa");  break;
 | 
			
		||||
    case 'B': str << TR("Corpo");  break;
 | 
			
		||||
    case 'F': str << TR("Coda");   break;
 | 
			
		||||
    default : break;
 | 
			
		||||
    }
 | 
			
		||||
    str << ' ';
 | 
			
		||||
    if (type == 'H' || type == 'F')
 | 
			
		||||
    {
 | 
			
		||||
      if (level <= 1)
 | 
			
		||||
        str << TR("Report");
 | 
			
		||||
      else
 | 
			
		||||
        str << TR("Gruppo") << ' ' << (level-1);
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
      str << level;
 | 
			
		||||
  }
 | 
			
		||||
  if (type != 'R' && type != 'P')
 | 
			
		||||
    str << " (" << _curr << ')';
 | 
			
		||||
  return true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -66,14 +91,7 @@ bool TReport_tree::goto_firstson()
 | 
			
		||||
    nlevel = 0;
 | 
			
		||||
    break;
 | 
			
		||||
  case 'R': 
 | 
			
		||||
    nlevel = _report.find_max_level('H'); 
 | 
			
		||||
    break;
 | 
			
		||||
  case 'S': 
 | 
			
		||||
    if (_report.find_section('B',2) != NULL)
 | 
			
		||||
    {
 | 
			
		||||
      ntype = 'B'; 
 | 
			
		||||
      nlevel = 2; 
 | 
			
		||||
    }
 | 
			
		||||
    nlevel = 1; 
 | 
			
		||||
    break;
 | 
			
		||||
  default : break;
 | 
			
		||||
  }
 | 
			
		||||
@ -93,7 +111,6 @@ bool TReport_tree::goto_rbrother()
 | 
			
		||||
    case 'H': ntype = 'B'; break;
 | 
			
		||||
    case 'B': ntype = 'F'; break;
 | 
			
		||||
    case 'P': ntype = 'R'; break;
 | 
			
		||||
    case 'R': ntype = 'S'; break;
 | 
			
		||||
    default : break;
 | 
			
		||||
    }
 | 
			
		||||
    nlevel = level;
 | 
			
		||||
@ -103,10 +120,10 @@ bool TReport_tree::goto_rbrother()
 | 
			
		||||
    switch (type)
 | 
			
		||||
    {
 | 
			
		||||
    case 'H':
 | 
			
		||||
      if (level > 1)
 | 
			
		||||
      if (level < _report.find_max_level('H'))
 | 
			
		||||
      {
 | 
			
		||||
        ntype = type;
 | 
			
		||||
        nlevel = level-1;
 | 
			
		||||
        ntype = 'H';
 | 
			
		||||
        nlevel = level+1;
 | 
			
		||||
      }
 | 
			
		||||
      else
 | 
			
		||||
      {
 | 
			
		||||
@ -115,14 +132,22 @@ bool TReport_tree::goto_rbrother()
 | 
			
		||||
      }
 | 
			
		||||
      break;
 | 
			
		||||
    case 'B':
 | 
			
		||||
      ntype = 'F';
 | 
			
		||||
      nlevel = 1;
 | 
			
		||||
      break;
 | 
			
		||||
    case 'F':
 | 
			
		||||
      if (level < _report.find_max_level('F'))
 | 
			
		||||
      if (level < _report.find_max_level('B'))
 | 
			
		||||
      {
 | 
			
		||||
        ntype = 'B';
 | 
			
		||||
        nlevel = level+1;
 | 
			
		||||
      }
 | 
			
		||||
      else
 | 
			
		||||
      {
 | 
			
		||||
        ntype = 'F';
 | 
			
		||||
        nlevel = level+1;
 | 
			
		||||
        nlevel = _report.find_max_level('F');
 | 
			
		||||
      }
 | 
			
		||||
      break;
 | 
			
		||||
    case 'F':
 | 
			
		||||
      if (level > 1)
 | 
			
		||||
      {
 | 
			
		||||
        ntype = 'F';
 | 
			
		||||
        nlevel = level-1;
 | 
			
		||||
      }
 | 
			
		||||
      break;
 | 
			
		||||
    default: 
 | 
			
		||||
@ -146,9 +171,6 @@ bool TReport_tree::has_son() const
 | 
			
		||||
  case 'R':
 | 
			
		||||
    yes = true;
 | 
			
		||||
    break;
 | 
			
		||||
  case 'S':
 | 
			
		||||
    yes = _report.find_section('B', 2) != NULL;
 | 
			
		||||
    break;
 | 
			
		||||
  default:
 | 
			
		||||
    break;
 | 
			
		||||
  }
 | 
			
		||||
@ -179,16 +201,7 @@ bool TReport_tree::goto_father()
 | 
			
		||||
  bool yes = has_father();
 | 
			
		||||
  if (yes)
 | 
			
		||||
  {
 | 
			
		||||
    char ntype = ' ';
 | 
			
		||||
    if (_curr[1] == '0')
 | 
			
		||||
      ntype = 'P';
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
      if (_curr[0] == 'B' && _curr[1] > '1')
 | 
			
		||||
        ntype = 'S';
 | 
			
		||||
      else
 | 
			
		||||
        ntype = 'R';
 | 
			
		||||
    }
 | 
			
		||||
    const char ntype = _curr[1] == '0' ? 'P' : 'R';
 | 
			
		||||
    yes = goto_node(ntype, 0);
 | 
			
		||||
  }
 | 
			
		||||
  return yes;
 | 
			
		||||
@ -216,7 +229,6 @@ bool TReport_tree::goto_lbrother()
 | 
			
		||||
    case 'B': ntype = 'H'; break;
 | 
			
		||||
    case 'F': ntype = 'B'; break;
 | 
			
		||||
    case 'R': ntype = 'P'; break;
 | 
			
		||||
    case 'S': ntype = 'R'; break;
 | 
			
		||||
    default : break;
 | 
			
		||||
    }
 | 
			
		||||
    nlevel = level;
 | 
			
		||||
@ -226,26 +238,34 @@ bool TReport_tree::goto_lbrother()
 | 
			
		||||
    switch (type)
 | 
			
		||||
    {
 | 
			
		||||
    case 'F':
 | 
			
		||||
      if (level > 1)
 | 
			
		||||
      if (level < _report.find_max_level('F'))
 | 
			
		||||
      {
 | 
			
		||||
        ntype = type;
 | 
			
		||||
        nlevel = level-1;
 | 
			
		||||
        ntype = 'F';
 | 
			
		||||
        nlevel = level+1;
 | 
			
		||||
      }
 | 
			
		||||
      else
 | 
			
		||||
      {
 | 
			
		||||
        ntype = 'B';
 | 
			
		||||
        nlevel = 1;
 | 
			
		||||
        nlevel = _report.find_max_level('B');
 | 
			
		||||
      }
 | 
			
		||||
      break;
 | 
			
		||||
    case 'B':
 | 
			
		||||
      ntype = 'H';
 | 
			
		||||
      nlevel = 1;
 | 
			
		||||
      break;
 | 
			
		||||
    case 'H':
 | 
			
		||||
      if (level < _report.find_max_level('H'))
 | 
			
		||||
      if (level > 1)
 | 
			
		||||
      {
 | 
			
		||||
        ntype = 'B';
 | 
			
		||||
        nlevel = level-1;
 | 
			
		||||
      }
 | 
			
		||||
      else
 | 
			
		||||
      {
 | 
			
		||||
        ntype = 'H';
 | 
			
		||||
        nlevel = level+1;
 | 
			
		||||
        nlevel = 1;
 | 
			
		||||
      }
 | 
			
		||||
      break;
 | 
			
		||||
    case 'H':
 | 
			
		||||
      if (level > 1)
 | 
			
		||||
      {
 | 
			
		||||
        ntype = 'H';
 | 
			
		||||
        nlevel = level-1;
 | 
			
		||||
      }
 | 
			
		||||
      break;
 | 
			
		||||
    default: 
 | 
			
		||||
@ -298,10 +318,7 @@ protected:
 | 
			
		||||
  virtual bool on_key(KEY k);
 | 
			
		||||
  
 | 
			
		||||
protected:
 | 
			
		||||
  void draw_square(int x, int y, int s);
 | 
			
		||||
  void draw_field(const TReport_field& f);
 | 
			
		||||
  void draw_grid();
 | 
			
		||||
  void draw_fields();
 | 
			
		||||
  void snap_drag(PNT& pnt) const;
 | 
			
		||||
  void draw_dragster();
 | 
			
		||||
 | 
			
		||||
@ -339,53 +356,6 @@ TReport_section& TReport_window::curr_section() const
 | 
			
		||||
  return tree.curr_section();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void TReport_window::draw_square(int x, int y, int s)
 | 
			
		||||
{
 | 
			
		||||
  RCT rct; rct.left = x; rct.top = y; rct.right = x+s; rct.bottom = y+s;
 | 
			
		||||
  xvt_dwin_draw_rect(win(), &rct);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void TReport_window::draw_field(const TReport_field& f)
 | 
			
		||||
{
 | 
			
		||||
  RCT r; TWindow::log2dev(f.get_rect(), r);
 | 
			
		||||
 | 
			
		||||
  switch (f.type())
 | 
			
		||||
  {
 | 
			
		||||
  case 'D':
 | 
			
		||||
  case 'N':
 | 
			
		||||
  case 'S':
 | 
			
		||||
  case 'T': 
 | 
			
		||||
    if (f.border() <= 0)
 | 
			
		||||
    {
 | 
			
		||||
      set_pen(COLOR_LTGRAY);
 | 
			
		||||
      set_brush(f.back_color(), PAT_NONE);
 | 
			
		||||
      xvt_dwin_draw_rect(win(), &r);
 | 
			
		||||
    }
 | 
			
		||||
    f.draw(*this, rdm_edit); 
 | 
			
		||||
    break;
 | 
			
		||||
  default: f.draw(*this, rdm_edit); break;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if (f.selected())
 | 
			
		||||
  {
 | 
			
		||||
    set_pen(COLOR_BLACK);
 | 
			
		||||
    set_brush(COLOR_BLACK);
 | 
			
		||||
    const int s = 5;
 | 
			
		||||
    draw_square(r.left, r.top, s);
 | 
			
		||||
    draw_square(r.right-s, r.bottom-s, s);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void TReport_window::draw_fields()
 | 
			
		||||
{
 | 
			
		||||
  TReport_section& rs = curr_section();
 | 
			
		||||
  FOR_EACH_ARRAY_ITEM(rs, i, o)
 | 
			
		||||
  {
 | 
			
		||||
    const TReport_field& f = *(const TReport_field*)o;
 | 
			
		||||
    draw_field(f);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool TReport_window::pick(const TPoint& ptlog) const
 | 
			
		||||
{
 | 
			
		||||
  TReport_section& rs = curr_section();
 | 
			
		||||
@ -507,10 +477,11 @@ bool TReport_window::on_key(KEY k)
 | 
			
		||||
#define POPUP_DUP        20886
 | 
			
		||||
#define POPUP_CLEAR      20887
 | 
			
		||||
#define POPUP_PROPERTIES 20888
 | 
			
		||||
#define POPUP_NEWFIELD   20889
 | 
			
		||||
 | 
			
		||||
void TReport_window::popup_menu(EVENT* ep)
 | 
			
		||||
{
 | 
			
		||||
  MENU_ITEM menu[8];
 | 
			
		||||
  MENU_ITEM menu[16];  // Stiamo larghi
 | 
			
		||||
  memset(menu, 0, sizeof(menu));
 | 
			
		||||
 | 
			
		||||
  TRectangle rct; 
 | 
			
		||||
@ -524,6 +495,7 @@ void TReport_window::popup_menu(EVENT* ep)
 | 
			
		||||
  menu[4].tag = POPUP_CLEAR; menu[4].text = "Cancella"; menu[4].enabled = sel;
 | 
			
		||||
  menu[5].tag = -1;          menu[5].separator = true;
 | 
			
		||||
  menu[6].tag = POPUP_PROPERTIES; menu[6].text = "Proprieta'"; menu[6].enabled = true;
 | 
			
		||||
  menu[7].tag = POPUP_NEWFIELD; menu[7].text = "Nuovo"; menu[7].enabled = true;
 | 
			
		||||
 | 
			
		||||
  const PNT& p = ep->v.mouse.where;
 | 
			
		||||
  _pt_drag_start = dev2log(p);
 | 
			
		||||
@ -626,8 +598,13 @@ void TReport_window::handler(WINDOW win, EVENT* ep)
 | 
			
		||||
    {
 | 
			
		||||
      TMask& m = owner().mask();
 | 
			
		||||
      const TPoint p = dev2log(ep->v.mouse.where);
 | 
			
		||||
      m.set(F_X, p.x/100);
 | 
			
		||||
      m.set(F_Y, p.y/100);
 | 
			
		||||
 | 
			
		||||
      if (true) // Needs an option?
 | 
			
		||||
      {
 | 
			
		||||
        TString16 str; str.format("r:%3d c:%3d", p.y/100, p.x/100);
 | 
			
		||||
        statbar_set_title(TASK_WIN, str);
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      if (_dragging != 0)
 | 
			
		||||
      {
 | 
			
		||||
        draw_dragster();
 | 
			
		||||
@ -717,6 +694,9 @@ void TReport_window::handler(WINDOW win, EVENT* ep)
 | 
			
		||||
          owner().mask().send_key(K_SPACE, F_SEC_PROPERTIES);
 | 
			
		||||
      }
 | 
			
		||||
      break;
 | 
			
		||||
    case POPUP_NEWFIELD:
 | 
			
		||||
      owner().mask().send_key(K_SPACE, F_FLD_ADD);
 | 
			
		||||
      break;
 | 
			
		||||
    default: 
 | 
			
		||||
      break;
 | 
			
		||||
    }
 | 
			
		||||
@ -729,8 +709,8 @@ void TReport_window::handler(WINDOW win, EVENT* ep)
 | 
			
		||||
 | 
			
		||||
PNT TReport_window::log2dev(long x, long y) const
 | 
			
		||||
{
 | 
			
		||||
  x -= origin().x*100;
 | 
			
		||||
  y -= origin().y*100;
 | 
			
		||||
  x -= origin().x * 100L;
 | 
			
		||||
  y -= origin().y * 100L;
 | 
			
		||||
  PNT p;
 | 
			
		||||
  p.h = short((x * _dpi.h) / (cpi() * 100L));
 | 
			
		||||
  p.v = short((y * _dpi.v) / (lpi() * 100L));
 | 
			
		||||
@ -765,7 +745,7 @@ void TReport_window::draw_grid()
 | 
			
		||||
void TReport_window::update()
 | 
			
		||||
{
 | 
			
		||||
  draw_grid();
 | 
			
		||||
  draw_fields();
 | 
			
		||||
  curr_section().draw(*this, rdm_edit);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int TReport_window::cpi() const 
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										874
									
								
								ba/ba8302.cpp
									
									
									
									
									
								
							
							
						
						
									
										874
									
								
								ba/ba8302.cpp
									
									
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										170
									
								
								ba/ba8302.h
									
									
									
									
									
								
							
							
						
						
									
										170
									
								
								ba/ba8302.h
									
									
									
									
									
								
							@ -13,6 +13,14 @@
 | 
			
		||||
#include <xml.h>
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifndef __RECORDSET_H
 | 
			
		||||
#include "ba8201.h"
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifndef __ALEX_H
 | 
			
		||||
#include "ba8304.h"
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
///////////////////////////////////////////////////////////
 | 
			
		||||
// TReport_font
 | 
			
		||||
///////////////////////////////////////////////////////////
 | 
			
		||||
@ -58,6 +66,28 @@ class TReport_field;
 | 
			
		||||
 | 
			
		||||
enum TReport_draw_mode { rdm_edit, rdm_print, rdm_print_preview };
 | 
			
		||||
 | 
			
		||||
class TReport_script : public TObject
 | 
			
		||||
{
 | 
			
		||||
  TBytecode* _bc;  // Chesire's cat class
 | 
			
		||||
  TString _src;
 | 
			
		||||
 | 
			
		||||
protected:
 | 
			
		||||
  void destroy();
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
  virtual bool ok() const { return !_src.blank(); }
 | 
			
		||||
  void set(const char* source);
 | 
			
		||||
  const TString& get() const { return _src; }
 | 
			
		||||
 | 
			
		||||
  bool execute(TReport& report, TString& output);
 | 
			
		||||
  bool execute(TReport_field& rf);
 | 
			
		||||
 | 
			
		||||
  void save(TXmlItem& root, const char* tag) const;
 | 
			
		||||
  bool load(const TXmlItem& root, const char* tag);
 | 
			
		||||
  TReport_script();
 | 
			
		||||
  virtual ~TReport_script();
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class TReport_section : public TArray
 | 
			
		||||
{
 | 
			
		||||
  TReport& _report;
 | 
			
		||||
@ -66,7 +96,8 @@ class TReport_section : public TArray
 | 
			
		||||
  int _level;   // 0,1,2,...
 | 
			
		||||
  TPoint _size; // In centesimi
 | 
			
		||||
  TString _groupby;
 | 
			
		||||
  bool _hidden_if_needed;
 | 
			
		||||
  bool _page_break, _hidden_if_needed, _hidden, _deactivated;
 | 
			
		||||
  TReport_script _prescript, _postscript;
 | 
			
		||||
 | 
			
		||||
  TReport_font* _font;
 | 
			
		||||
 | 
			
		||||
@ -78,6 +109,7 @@ public:
 | 
			
		||||
  virtual int add(TObject& obj);
 | 
			
		||||
  TReport_field& field(int i) { return *(TReport_field*)objptr(i); }
 | 
			
		||||
  const TReport_field& field(int i) const { return *(TReport_field*)objptr(i); }
 | 
			
		||||
  TReport_field* field(const TString& code);
 | 
			
		||||
  TReport& report() { return _report; }
 | 
			
		||||
 
 | 
			
		||||
  char type() const { return _type; }
 | 
			
		||||
@ -91,19 +123,39 @@ public:
 | 
			
		||||
  TPoint compute_size() const;
 | 
			
		||||
  bool compute_rect(TRectangle& rct) const;
 | 
			
		||||
 | 
			
		||||
  bool page_break() const { return _page_break; }
 | 
			
		||||
  void force_page_break(bool pb) { _page_break = pb; }
 | 
			
		||||
 | 
			
		||||
  const TString& grouped_by() const { return _groupby; }
 | 
			
		||||
  void group_by(const char* gb) { _groupby = gb; }
 | 
			
		||||
 | 
			
		||||
  bool hidden_if_needed() const { return _hidden_if_needed; }
 | 
			
		||||
  void hide_if_needed(bool h) { _hidden_if_needed = h; }
 | 
			
		||||
  bool hidden() const { return _hidden; }
 | 
			
		||||
  bool shown() const { return !hidden(); }
 | 
			
		||||
  void show(bool on) { _hidden = !on; }
 | 
			
		||||
  void hide() { show(false); }
 | 
			
		||||
  bool deactivated() const { return _deactivated; }
 | 
			
		||||
  bool active() const { return !deactivated(); }
 | 
			
		||||
  void activate(bool on) { _deactivated = !on; }
 | 
			
		||||
  void deactivate() { activate(false); }
 | 
			
		||||
 | 
			
		||||
  const TString& prescript() const { return _prescript.get(); }
 | 
			
		||||
  void set_prescript(const char* src) { _prescript.set(src); }
 | 
			
		||||
  const TString& postscript() const { return _postscript.get(); }
 | 
			
		||||
  void set_postscript(const char* src) { _postscript.set(src); }
 | 
			
		||||
 | 
			
		||||
  bool has_font() const { return _font != NULL; }
 | 
			
		||||
  const TReport_font& font() const;
 | 
			
		||||
  void set_font(const TReport_font& f);
 | 
			
		||||
 | 
			
		||||
  void compute_values();
 | 
			
		||||
  bool execute_prescript();
 | 
			
		||||
  bool execute_postscript();
 | 
			
		||||
  void draw(TWindow& win, TReport_draw_mode mode) const;
 | 
			
		||||
 | 
			
		||||
  void save(TXmlItem& report) const;
 | 
			
		||||
  void load(const TXmlItem& sec);
 | 
			
		||||
 | 
			
		||||
  TReport_section(TReport& r, char t, int l);
 | 
			
		||||
  virtual ~TReport_section();
 | 
			
		||||
};
 | 
			
		||||
@ -111,19 +163,22 @@ public:
 | 
			
		||||
class TReport_field : public TObject
 | 
			
		||||
{
 | 
			
		||||
  TReport_section* _section;
 | 
			
		||||
  int _id;
 | 
			
		||||
  char _type;   // Text, String, Numeric, Date, Line, Rectangle, Image
 | 
			
		||||
  TRectangle _rct; // In centesimi
 | 
			
		||||
  COLOR _fgcolor, _bgcolor;
 | 
			
		||||
  short _border;
 | 
			
		||||
  char _halign, _valign;
 | 
			
		||||
  TString _picture, _field;
 | 
			
		||||
  TString _value;
 | 
			
		||||
  TVariant _var;
 | 
			
		||||
  TReport_script _prescript, _postscript;
 | 
			
		||||
 | 
			
		||||
  TReport_font* _font;
 | 
			
		||||
  bool _selected;
 | 
			
		||||
  bool _hidden, _deactivated, _selected;
 | 
			
		||||
 | 
			
		||||
protected:
 | 
			
		||||
  void copy(const TReport_field& rf);
 | 
			
		||||
  TFieldtypes var_type() const;
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
  virtual TObject* dup() const { return new TReport_field(*this); } 
 | 
			
		||||
@ -132,9 +187,6 @@ public:
 | 
			
		||||
  TReport_section& section() { return *_section; } 
 | 
			
		||||
  void set_section(TReport_section* sec) { _section = sec; } 
 | 
			
		||||
 | 
			
		||||
  char type() const { return _type; }
 | 
			
		||||
  const char* type_name() const;
 | 
			
		||||
 | 
			
		||||
  bool has_font() const { return _font != NULL; }
 | 
			
		||||
  const TReport_font& font() const;
 | 
			
		||||
  void set_font(const TReport_font& f);
 | 
			
		||||
@ -144,8 +196,18 @@ public:
 | 
			
		||||
 | 
			
		||||
  const TString& field() const { return _field; }
 | 
			
		||||
  void set_field(const char* str) { _field = str; }
 | 
			
		||||
  bool compute_value();
 | 
			
		||||
 | 
			
		||||
  const TVariant& get() const { return _var; }
 | 
			
		||||
  void set(const char* str);
 | 
			
		||||
  void set(const TVariant& var);
 | 
			
		||||
 | 
			
		||||
  bool execute_prescript();
 | 
			
		||||
  bool execute_postscript();
 | 
			
		||||
 | 
			
		||||
  int id() const { return _id; }
 | 
			
		||||
  void set_id(int id) { _id = id; }
 | 
			
		||||
  char type() const { return _type; }
 | 
			
		||||
  const char* type_name() const;
 | 
			
		||||
  void set_type(char t) { _type = t; }
 | 
			
		||||
  void set_pos(long x, long y);
 | 
			
		||||
  void set_row(long y) { _rct.y = y; }
 | 
			
		||||
@ -155,6 +217,15 @@ public:
 | 
			
		||||
  void set_height(long dy) { _rct.set_height(dy); }
 | 
			
		||||
  const TRectangle& get_rect() const { return _rct; }
 | 
			
		||||
  
 | 
			
		||||
  bool hidden() const { return _hidden; }
 | 
			
		||||
  bool shown() const { return !hidden(); }
 | 
			
		||||
  void show(bool on) { _hidden = !on; }
 | 
			
		||||
  void hide() { show(false); }
 | 
			
		||||
  bool deactivated() const { return _deactivated; }
 | 
			
		||||
  bool active() const { return !deactivated(); }
 | 
			
		||||
  void activate(bool on) { _deactivated = !on; }
 | 
			
		||||
  void deactivate() { activate(false); }
 | 
			
		||||
 | 
			
		||||
  void set_fore_color(COLOR c) { _fgcolor = c; }
 | 
			
		||||
  COLOR fore_color() const { return _fgcolor; }
 | 
			
		||||
  void set_back_color(COLOR c) { _bgcolor = c; }
 | 
			
		||||
@ -166,6 +237,11 @@ public:
 | 
			
		||||
  void set_vertical_alignment(char a) { _valign = a; }
 | 
			
		||||
  char vertical_alignment() const { return _valign; }
 | 
			
		||||
  
 | 
			
		||||
  const TString& prescript() const { return _prescript.get(); }
 | 
			
		||||
  void set_prescript(const char* src) { _prescript.set(src); }
 | 
			
		||||
  const TString& postscript() const { return _postscript.get(); }
 | 
			
		||||
  void set_postscript(const char* src) { _postscript.set(src); }
 | 
			
		||||
 | 
			
		||||
  void select(bool ok = true) { _selected = ok; }
 | 
			
		||||
  bool selected() const { return _selected; }
 | 
			
		||||
  void offset(const TPoint& pt);
 | 
			
		||||
@ -182,9 +258,7 @@ public:
 | 
			
		||||
  virtual ~TReport_field();
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class TRecordset;
 | 
			
		||||
 | 
			
		||||
class TReport : public TObject
 | 
			
		||||
class TReport : public TAlex_virtual_machine
 | 
			
		||||
{
 | 
			
		||||
  TAssoc_array _sections;
 | 
			
		||||
  TFilename _path; 
 | 
			
		||||
@ -192,8 +266,17 @@ class TReport : public TObject
 | 
			
		||||
  TReport_font _font;
 | 
			
		||||
  int _lpi;  // Lines per inch
 | 
			
		||||
  TRecordset* _recordset;
 | 
			
		||||
  TAssoc_array _expressions;
 | 
			
		||||
  
 | 
			
		||||
  TString16 _curr_page;
 | 
			
		||||
  TReport_field* _curr_field;
 | 
			
		||||
 | 
			
		||||
protected:
 | 
			
		||||
  virtual unsigned int compile_usr_word(const TString& name) const;
 | 
			
		||||
  virtual bool execute_usr_word(unsigned int opcode, TVariant_stack& stack);
 | 
			
		||||
  virtual bool get_usr_val(const TString& name, TVariant& var) const;
 | 
			
		||||
  virtual bool set_usr_val(const TString& name, const TVariant& var);
 | 
			
		||||
  
 | 
			
		||||
  void build_section_key(char type, int level, TString& key) const;
 | 
			
		||||
  short get_num_attr(const TXmlItem& item, const char* attr, short def = 0) const;
 | 
			
		||||
  COLOR get_col_attr(const TXmlItem& item, const char* attr, COLOR defcol = COLOR_BLACK) const;
 | 
			
		||||
@ -216,6 +299,8 @@ public:
 | 
			
		||||
  bool set_recordset(const TString& sql);
 | 
			
		||||
  bool set_recordset(TRecordset* sql);
 | 
			
		||||
  TRecordset* recordset() const { return _recordset; }
 | 
			
		||||
  bool evaluate_atom(const char* atom, TVariant& var);
 | 
			
		||||
  bool evaluate(const char* expr, TVariant& var, TFieldtypes force_type);
 | 
			
		||||
 | 
			
		||||
  void set_description(const char* d) { _description = d; }
 | 
			
		||||
  const TString& description() const { return _description; }
 | 
			
		||||
@ -224,66 +309,19 @@ public:
 | 
			
		||||
  bool save(const char* fname) const;
 | 
			
		||||
  bool load(const char* fname);
 | 
			
		||||
 | 
			
		||||
  // Used by TReport_printer
 | 
			
		||||
  void set_curr_page(const char* str) { _curr_page = str; }  // string 1-A
 | 
			
		||||
  const TString& curr_page() const { return _curr_page; }
 | 
			
		||||
  void set_curr_field(TReport_field* fld) { _curr_field = fld; }
 | 
			
		||||
  TReport_field* curr_field() const { return _curr_field; }
 | 
			
		||||
 | 
			
		||||
  TReport_field* field(const TString& code);
 | 
			
		||||
 
 | 
			
		||||
  void destroy();
 | 
			
		||||
  TReport();
 | 
			
		||||
  virtual ~TReport();
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class TPage_printer : public TWindow
 | 
			
		||||
{
 | 
			
		||||
protected:
 | 
			
		||||
  PRINT_RCD* _rcd;
 | 
			
		||||
  long _pw, _ph, _phr, _pvr; // Printer width, height, horizontal and vertical resolution
 | 
			
		||||
  word _copies, _pagefrom, _pageto, _page;
 | 
			
		||||
  bool _page_is_open;
 | 
			
		||||
 | 
			
		||||
  virtual word pages() const { return 0; }
 | 
			
		||||
  virtual bool print_loop() pure;
 | 
			
		||||
 | 
			
		||||
protected:
 | 
			
		||||
  virtual const char* form_name() const;
 | 
			
		||||
  virtual const char* font_name() const;
 | 
			
		||||
  virtual int font_size() const;
 | 
			
		||||
  virtual bool ask_pages();
 | 
			
		||||
 | 
			
		||||
  virtual bool open_page();
 | 
			
		||||
  virtual bool close_page();
 | 
			
		||||
  bool page_in_range() const;
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
  bool main_loop();          // Internal use only  
 | 
			
		||||
  virtual bool print();      // Use this
 | 
			
		||||
  TPage_printer();
 | 
			
		||||
  virtual ~TPage_printer();
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class TReport_printer : public TPage_printer
 | 
			
		||||
{
 | 
			
		||||
  TReport& _report;
 | 
			
		||||
  TPoint _delta;
 | 
			
		||||
  double _kx, _ky;
 | 
			
		||||
  long _logical_page_height;
 | 
			
		||||
  long _logical_foot_pos;
 | 
			
		||||
  bool _is_last_page;
 | 
			
		||||
 | 
			
		||||
protected:
 | 
			
		||||
  virtual const char* form_name() const;
 | 
			
		||||
  virtual const char* font_name() const;
 | 
			
		||||
  virtual int font_size() const;
 | 
			
		||||
 | 
			
		||||
  virtual PNT log2dev(long x, long y) const;
 | 
			
		||||
  virtual TPoint dev2log(const PNT& p) const;
 | 
			
		||||
  virtual bool print_loop();
 | 
			
		||||
 | 
			
		||||
  virtual bool open_page();
 | 
			
		||||
  virtual bool close_page();
 | 
			
		||||
  long print_section(TReport_section& rs);
 | 
			
		||||
  long print_section(char type, int level);
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
  TReport_printer(TReport& r) : _report(r) { }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
void advanced_draw_rect(TWindow& win, const RCT& r, int border, COLOR fore, COLOR back);
 | 
			
		||||
void advanced_draw_text(TWindow& win, const char* text, const RCT& r, 
 | 
			
		||||
                        char halign, char valign);
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										307
									
								
								ba/ba8303.cpp
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										307
									
								
								ba/ba8303.cpp
									
									
									
									
									
										Executable file
									
								
							@ -0,0 +1,307 @@
 | 
			
		||||
#include <mask.h>
 | 
			
		||||
#include <printer.h>
 | 
			
		||||
 | 
			
		||||
#include <bagn003.h>
 | 
			
		||||
#include "ba8201.h"
 | 
			
		||||
#include "ba8303.h"
 | 
			
		||||
 | 
			
		||||
///////////////////////////////////////////////////////////
 | 
			
		||||
// TPage_printer
 | 
			
		||||
///////////////////////////////////////////////////////////
 | 
			
		||||
 | 
			
		||||
const char* TPage_printer::form_name() const
 | 
			
		||||
{
 | 
			
		||||
  return printer().get_form_name();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const char* TPage_printer::font_name() const
 | 
			
		||||
{
 | 
			
		||||
  return printer().fontname();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int TPage_printer::font_size() const
 | 
			
		||||
{
 | 
			
		||||
  return printer().get_char_size();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool TPage_printer::ask_pages()
 | 
			
		||||
{
 | 
			
		||||
  if (_pageto <= 0)
 | 
			
		||||
    _pageto = pages();
 | 
			
		||||
 | 
			
		||||
  TPrinter& p = printer();
 | 
			
		||||
  TMask msk("bagn003");
 | 
			
		||||
  msk.set(F_PRINTER, p.printername());
 | 
			
		||||
  msk.set(F_FORM, form_name());
 | 
			
		||||
  msk.set(F_FONT, font_name());
 | 
			
		||||
  msk.set(F_SIZE, font_size());
 | 
			
		||||
  msk.set(F_ISGRAPHICS, p.isgraphics() ? "X" : "");
 | 
			
		||||
  msk.set(F_FROMPAGE, _pagefrom);
 | 
			
		||||
  msk.set(F_TOPAGE, _pageto);
 | 
			
		||||
  msk.set(F_COPIES, _copies);
 | 
			
		||||
  const bool ok = msk.run() == K_ENTER;
 | 
			
		||||
  if (ok)
 | 
			
		||||
  {
 | 
			
		||||
    _copies = msk.get_int(F_COPIES);
 | 
			
		||||
    _pagefrom = msk.get_int(F_FROMPAGE);
 | 
			
		||||
    _pageto = msk.get_int(F_TOPAGE);
 | 
			
		||||
    if (_pageto < _pagefrom)
 | 
			
		||||
      _pageto = 0;
 | 
			
		||||
  }
 | 
			
		||||
  return ok;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool TPage_printer::main_loop()
 | 
			
		||||
{
 | 
			
		||||
  TPrinter& p = printer();
 | 
			
		||||
  _rcd = p.get_printrcd();
 | 
			
		||||
  if (!xvt_print_is_valid(_rcd))
 | 
			
		||||
    return TRUE; // aborted
 | 
			
		||||
  
 | 
			
		||||
  WINDOW prwin = xvt_print_create_win(_rcd, (char*)(const char*)form_name());
 | 
			
		||||
  if (prwin == NULL_WIN) 
 | 
			
		||||
    return TRUE; // aborted
 | 
			
		||||
  set_win(prwin);
 | 
			
		||||
 | 
			
		||||
  xvt_app_escape (XVT_ESC_GET_PRINTER_INFO, _rcd, &_ph, &_pw, &_pvr, &_phr);
 | 
			
		||||
 | 
			
		||||
  bool ok = true;
 | 
			
		||||
  for (word c = 0; c < _copies && ok; c++)
 | 
			
		||||
  {
 | 
			
		||||
    _page = 0;
 | 
			
		||||
    ok = print_loop();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  xvt_vobj_destroy(prwin);
 | 
			
		||||
  set_win(NULL_WIN);
 | 
			
		||||
  
 | 
			
		||||
  return !ok;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool TPage_printer::page_in_range() const
 | 
			
		||||
{
 | 
			
		||||
  if (_page < _pagefrom)
 | 
			
		||||
    return false;
 | 
			
		||||
  return _pageto < _pagefrom || _page <= _pageto;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool TPage_printer::open_page()
 | 
			
		||||
{
 | 
			
		||||
  _page++;
 | 
			
		||||
  if (page_in_range())
 | 
			
		||||
    _page_is_open = xvt_print_open_page(_rcd) != 0;
 | 
			
		||||
  else
 | 
			
		||||
    _page_is_open = false;
 | 
			
		||||
  
 | 
			
		||||
  return _page_is_open;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool TPage_printer::close_page()
 | 
			
		||||
{
 | 
			
		||||
  const bool was_open = _page_is_open;
 | 
			
		||||
  if (was_open)
 | 
			
		||||
  {
 | 
			
		||||
    xvt_print_close_page(_rcd);
 | 
			
		||||
    _page_is_open = false;
 | 
			
		||||
  }
 | 
			
		||||
  return was_open;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static BOOLEAN main_loop_callback(long jolly)
 | 
			
		||||
{
 | 
			
		||||
  TPage_printer* pp = (TPage_printer*)jolly;
 | 
			
		||||
  return pp->main_loop();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool TPage_printer::print()
 | 
			
		||||
{
 | 
			
		||||
  bool ok = ask_pages();
 | 
			
		||||
  if (ok)
 | 
			
		||||
    ok = xvt_print_start_thread(main_loop_callback, long(this)) == FALSE;
 | 
			
		||||
  return ok;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TPage_printer::TPage_printer() : _pagefrom(1), _pageto(0), _copies(1)
 | 
			
		||||
{ }
 | 
			
		||||
 | 
			
		||||
TPage_printer::~TPage_printer() 
 | 
			
		||||
{ }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
///////////////////////////////////////////////////////////
 | 
			
		||||
// TReport_printer
 | 
			
		||||
///////////////////////////////////////////////////////////
 | 
			
		||||
 | 
			
		||||
const char* TReport_printer::form_name() const
 | 
			
		||||
{
 | 
			
		||||
  return _report.filename();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const char* TReport_printer::font_name() const
 | 
			
		||||
{
 | 
			
		||||
  return _report.font().name();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int TReport_printer::font_size() const
 | 
			
		||||
{
 | 
			
		||||
  return _report.font().size();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
PNT TReport_printer::log2dev(long lx, long ly) const
 | 
			
		||||
{
 | 
			
		||||
  const double cx = (double)_phr / (double)_report.cpi();
 | 
			
		||||
  const double cy = (double)_pvr / (double)_report.lpi();
 | 
			
		||||
 | 
			
		||||
  const short x = short((lx + _delta.x) * cx / 100.0);
 | 
			
		||||
  const short y = short((ly + _delta.y) * cy / 100.0);
 | 
			
		||||
  const PNT pnt = { y, x };
 | 
			
		||||
  return pnt;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TPoint TReport_printer::dev2log(const PNT& pnt) const
 | 
			
		||||
{
 | 
			
		||||
  CHECK(0, "dev2log: Pure virtual funtion call");
 | 
			
		||||
  const TPoint p;
 | 
			
		||||
  return p;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
long TReport_printer::print_section(char type, int level)
 | 
			
		||||
{
 | 
			
		||||
  long h = 0;
 | 
			
		||||
  TReport_section* rs = _report.find_section(type, level);
 | 
			
		||||
  if (rs != NULL)
 | 
			
		||||
    h = print_section(*rs);
 | 
			
		||||
  return h;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool TReport_printer::open_page()
 | 
			
		||||
{
 | 
			
		||||
  const bool ok = TPage_printer::open_page();
 | 
			
		||||
 | 
			
		||||
  TString8 str; str << _page;
 | 
			
		||||
  _report.set_curr_page(str);
 | 
			
		||||
 | 
			
		||||
  _delta.x = _delta.y = 0;
 | 
			
		||||
  _page_break_allowed = false;
 | 
			
		||||
  print_section('B', 0);
 | 
			
		||||
  if (_page == 1)
 | 
			
		||||
    _delta.y += print_section('H', 1);
 | 
			
		||||
 | 
			
		||||
  TReport_section* page_head = _report.find_section('H', 0);
 | 
			
		||||
  if (page_head != NULL && (_page > 1 || !page_head->hidden_if_needed()))
 | 
			
		||||
    _delta.y += print_section(*page_head);
 | 
			
		||||
 | 
			
		||||
  return ok;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool TReport_printer::close_page()
 | 
			
		||||
{
 | 
			
		||||
  if (_page_is_open)
 | 
			
		||||
  {
 | 
			
		||||
    TReport_section* page_foot = _report.find_section('F', 0);
 | 
			
		||||
    if (page_foot != NULL && (!_is_last_page || !page_foot->hidden_if_needed()))
 | 
			
		||||
    {
 | 
			
		||||
      _delta.x = 0;
 | 
			
		||||
      _delta.y = _logical_foot_pos;
 | 
			
		||||
      print_section(*page_foot);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  return TPage_printer::close_page();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
long TReport_printer::print_section(TReport_section& rs)
 | 
			
		||||
{
 | 
			
		||||
  rs.execute_prescript();
 | 
			
		||||
  const long height = rs.compute_size().y; // Compute size after the initilization script!
 | 
			
		||||
 | 
			
		||||
  if (height > 0) // Has some visible fields
 | 
			
		||||
  {
 | 
			
		||||
    bool page_break = _page_break_allowed && rs.page_break();
 | 
			
		||||
    if (!page_break)
 | 
			
		||||
      page_break = (_delta.y + height > _logical_foot_pos);
 | 
			
		||||
    if (page_break && rs.level() > 0) // Avoid recursion
 | 
			
		||||
    {
 | 
			
		||||
      close_page();
 | 
			
		||||
      open_page();
 | 
			
		||||
    }
 | 
			
		||||
    if (_page_is_open)
 | 
			
		||||
      rs.draw(*this, rdm_print);
 | 
			
		||||
 | 
			
		||||
    if (rs.level() > 0) // Ho stampa qualcosa che non sia lo sfondo!
 | 
			
		||||
      _page_break_allowed = true;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  rs.execute_postscript();
 | 
			
		||||
  
 | 
			
		||||
  return height;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool TReport_printer::print_loop()
 | 
			
		||||
{
 | 
			
		||||
  if (_report.recordset() == NULL)
 | 
			
		||||
    return false;
 | 
			
		||||
  TRecordset& rex = *_report.recordset();
 | 
			
		||||
  if (rex.items() <= 0)
 | 
			
		||||
    return false;
 | 
			
		||||
 | 
			
		||||
  _kx = double(_phr) / double(_report.cpi()*100.0);
 | 
			
		||||
  _ky = double(_pvr) / double(_report.lpi()*100.0);
 | 
			
		||||
 | 
			
		||||
  const double pollici_pagina = (double)_ph / (double)_pvr;
 | 
			
		||||
  const double righe_pagina = pollici_pagina *  _report.lpi();
 | 
			
		||||
  _logical_page_height = long(righe_pagina*100.0);
 | 
			
		||||
  const long logical_footer_height = _report.section('F',0).compute_size().y;
 | 
			
		||||
  _logical_foot_pos = _logical_page_height - logical_footer_height;  
 | 
			
		||||
 | 
			
		||||
  TString_array oldgroup, newgroup;
 | 
			
		||||
  const int max_group = _report.find_max_level('H');
 | 
			
		||||
  if (max_group >= 2)
 | 
			
		||||
  {
 | 
			
		||||
    for (int g = 2; g <= max_group; g++)
 | 
			
		||||
      oldgroup.add(EMPTY_STRING, g);
 | 
			
		||||
  }
 | 
			
		||||
  const int max_body = _report.find_max_level('B');
 | 
			
		||||
  
 | 
			
		||||
  _is_last_page = false;
 | 
			
		||||
  open_page();
 | 
			
		||||
  for (bool ok = rex.move_to(0); ok; ok = rex.move_next())
 | 
			
		||||
  {
 | 
			
		||||
    if (_pageto >= _pagefrom && _page > _pageto) // out of range
 | 
			
		||||
      break;
 | 
			
		||||
 | 
			
		||||
    if (max_group >= 2) // Gestione raggruppamenti
 | 
			
		||||
    {
 | 
			
		||||
      int changed = 0;
 | 
			
		||||
      TVariant var;
 | 
			
		||||
      for (int g = 2; g <= max_group; g++)
 | 
			
		||||
      {
 | 
			
		||||
        const TString& expr = _report.section('H', g).grouped_by();
 | 
			
		||||
        _report.evaluate(expr, var, _alfafld);
 | 
			
		||||
        newgroup.add(var.as_string(), g);
 | 
			
		||||
        if (newgroup.row(g) != oldgroup.row(g))
 | 
			
		||||
          changed = g;
 | 
			
		||||
      }
 | 
			
		||||
      if (changed)
 | 
			
		||||
      {
 | 
			
		||||
        oldgroup = newgroup;
 | 
			
		||||
        if (rex.current_row() > 0)
 | 
			
		||||
        {
 | 
			
		||||
          for (int g = 2; g <= changed; g++)
 | 
			
		||||
            _delta.y += print_section('F', g);
 | 
			
		||||
        }
 | 
			
		||||
        for (int g = changed; g >= 2 ; g--)
 | 
			
		||||
          _delta.y += print_section('H', g);
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    for (int b = 1; b <= max_body; b++)
 | 
			
		||||
      _delta.y += print_section('B', b);
 | 
			
		||||
  }
 | 
			
		||||
  if (rex.eof())
 | 
			
		||||
    print_section('F', 1);
 | 
			
		||||
  _is_last_page = true;
 | 
			
		||||
  close_page();
 | 
			
		||||
 | 
			
		||||
  return true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										67
									
								
								ba/ba8303.h
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										67
									
								
								ba/ba8303.h
									
									
									
									
									
										Executable file
									
								
							@ -0,0 +1,67 @@
 | 
			
		||||
#ifndef __REPRINT_H
 | 
			
		||||
#define __REPRINT_H
 | 
			
		||||
 | 
			
		||||
#ifndef __REPORT_H
 | 
			
		||||
#include "ba8302.h"
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
class TPage_printer : public TWindow
 | 
			
		||||
{
 | 
			
		||||
protected:
 | 
			
		||||
  PRINT_RCD* _rcd;
 | 
			
		||||
  long _pw, _ph, _phr, _pvr; // Printer width, height, horizontal and vertical resolution
 | 
			
		||||
  word _copies, _pagefrom, _pageto, _page;
 | 
			
		||||
  bool _page_is_open;
 | 
			
		||||
 | 
			
		||||
  virtual word pages() const { return 0; }
 | 
			
		||||
  virtual bool print_loop() pure;
 | 
			
		||||
 | 
			
		||||
protected:
 | 
			
		||||
  virtual const char* form_name() const;
 | 
			
		||||
  virtual const char* font_name() const;
 | 
			
		||||
  virtual int font_size() const;
 | 
			
		||||
  virtual bool ask_pages();
 | 
			
		||||
 | 
			
		||||
  virtual bool open_page();
 | 
			
		||||
  virtual bool close_page();
 | 
			
		||||
  bool page_in_range() const;
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
  bool main_loop();          // Internal use only  
 | 
			
		||||
  virtual bool print();      // Use this
 | 
			
		||||
  TPage_printer();
 | 
			
		||||
  virtual ~TPage_printer();
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class TReport_printer : public TPage_printer
 | 
			
		||||
{
 | 
			
		||||
  TReport& _report;
 | 
			
		||||
  TPoint _delta;
 | 
			
		||||
  double _kx, _ky;
 | 
			
		||||
  long _logical_page_height;
 | 
			
		||||
  long _logical_foot_pos;
 | 
			
		||||
  bool _is_last_page, _page_break_allowed;
 | 
			
		||||
 | 
			
		||||
protected:
 | 
			
		||||
  virtual const char* form_name() const;
 | 
			
		||||
  virtual const char* font_name() const;
 | 
			
		||||
  virtual int font_size() const;
 | 
			
		||||
 | 
			
		||||
  virtual PNT log2dev(long x, long y) const;
 | 
			
		||||
  virtual TPoint dev2log(const PNT& p) const;
 | 
			
		||||
  virtual bool print_loop();
 | 
			
		||||
 | 
			
		||||
  virtual bool open_page();
 | 
			
		||||
  virtual bool close_page();
 | 
			
		||||
  long print_section(TReport_section& rs);
 | 
			
		||||
  long print_section(char type, int level);
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
  TReport_printer(TReport& r) : _report(r) { }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
void advanced_draw_rect(TWindow& win, const RCT& r, int border, COLOR fore, COLOR back);
 | 
			
		||||
void advanced_draw_text(TWindow& win, const char* text, const RCT& r, 
 | 
			
		||||
                        char halign, char valign);
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
							
								
								
									
										308
									
								
								ba/ba8304.cpp
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										308
									
								
								ba/ba8304.cpp
									
									
									
									
									
										Executable file
									
								
							@ -0,0 +1,308 @@
 | 
			
		||||
#include <ctype.h>
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
 | 
			
		||||
#include <date.h>
 | 
			
		||||
#include <real.h>
 | 
			
		||||
#include <stack.h>
 | 
			
		||||
 | 
			
		||||
#include "ba8304.h"
 | 
			
		||||
 | 
			
		||||
TVariant& TVariant_stack::peek(int depth)
 | 
			
		||||
{
 | 
			
		||||
  const int sp = _sp-depth-1;
 | 
			
		||||
  return sp >= 0 ? (TVariant&)_var[sp] : NULL_VARIANT;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TVariant& TVariant_stack::pop()
 | 
			
		||||
{
 | 
			
		||||
  TVariant& var = peek();
 | 
			
		||||
  if (_sp > 0)
 | 
			
		||||
    _sp--;
 | 
			
		||||
  return var;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void TVariant_stack::push(const TVariant& var)
 | 
			
		||||
{
 | 
			
		||||
  if (_var.objptr(_sp) == NULL)
 | 
			
		||||
    _var.add(var, _sp);
 | 
			
		||||
  else
 | 
			
		||||
    (TVariant&)_var[_sp] = var;
 | 
			
		||||
  _sp++;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
///////////////////////////////////////////////////////////
 | 
			
		||||
// TAVM_op
 | 
			
		||||
///////////////////////////////////////////////////////////
 | 
			
		||||
 | 
			
		||||
enum AVM_opcode { avm_nop, avm_add, avm_dot, avm_dup, avm_push, avm_sub, 
 | 
			
		||||
                  avm_usrget, avm_usrset, avm_usrword };
 | 
			
		||||
 | 
			
		||||
class TAVM_op : public TObject
 | 
			
		||||
{
 | 
			
		||||
  AVM_opcode _op;
 | 
			
		||||
  TVariant _var;
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
  const TVariant& var() const { return _var; }
 | 
			
		||||
  TVariant& var() { return _var; }
 | 
			
		||||
  AVM_opcode op() const { return _op; }
 | 
			
		||||
 | 
			
		||||
  TAVM_op(AVM_opcode o, const TString& str);
 | 
			
		||||
  TAVM_op(AVM_opcode o, const real& num);
 | 
			
		||||
  TAVM_op(AVM_opcode o, const long num);
 | 
			
		||||
  TAVM_op(AVM_opcode o);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
TAVM_op::TAVM_op(AVM_opcode o, const TString& str)
 | 
			
		||||
       : _op(o), _var(str)
 | 
			
		||||
{ }
 | 
			
		||||
 | 
			
		||||
TAVM_op::TAVM_op(AVM_opcode o, const real& num)
 | 
			
		||||
       : _op(o), _var(num)
 | 
			
		||||
{ }
 | 
			
		||||
 | 
			
		||||
TAVM_op::TAVM_op(AVM_opcode o, const long num)
 | 
			
		||||
       : _op(o), _var(num)
 | 
			
		||||
{ }
 | 
			
		||||
 | 
			
		||||
TAVM_op::TAVM_op(AVM_opcode o)
 | 
			
		||||
       : _op(o)
 | 
			
		||||
{ }
 | 
			
		||||
 | 
			
		||||
///////////////////////////////////////////////////////////
 | 
			
		||||
// TAVM
 | 
			
		||||
///////////////////////////////////////////////////////////
 | 
			
		||||
 | 
			
		||||
class TAVM
 | 
			
		||||
{
 | 
			
		||||
  TAlex_virtual_machine* _vm;
 | 
			
		||||
  TString _last_error;
 | 
			
		||||
  TVariant_stack _stack;
 | 
			
		||||
 | 
			
		||||
protected:
 | 
			
		||||
  bool get_token(istream& instr, TString& str) const;
 | 
			
		||||
  AVM_opcode token2opcode(const TString& str) const;
 | 
			
		||||
  void log_error(const char* str);
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
  const TString& get_last_error() const { return _last_error; }
 | 
			
		||||
 | 
			
		||||
  bool compile(istream& instr, TBytecode& bc);
 | 
			
		||||
  bool execute(const TBytecode& bc, ostream& outstr);
 | 
			
		||||
 | 
			
		||||
  TAVM(TAlex_virtual_machine* vm) : _vm(vm) { }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
void TAVM::log_error(const char* str)
 | 
			
		||||
{
 | 
			
		||||
  _last_error = str;
 | 
			
		||||
  error_box(str);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool TAVM::get_token(istream& instr, TString& str) const
 | 
			
		||||
{
 | 
			
		||||
  str.cut(0);
 | 
			
		||||
  instr.eatwhite();
 | 
			
		||||
  if (instr.eof())
 | 
			
		||||
    return false;
 | 
			
		||||
  char c;
 | 
			
		||||
  instr.get(c);
 | 
			
		||||
  str << c;
 | 
			
		||||
  char* buf = str.get_buffer()+1;
 | 
			
		||||
  const int bufsize = str.size()-1;
 | 
			
		||||
  if (c == '"')
 | 
			
		||||
  {
 | 
			
		||||
    instr.getline(buf, bufsize, '"');
 | 
			
		||||
    str << '"';
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
    instr.getline(buf, bufsize, ' ');
 | 
			
		||||
 | 
			
		||||
  return *str > ' ';
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
AVM_opcode TAVM::token2opcode(const TString& str) const
 | 
			
		||||
{
 | 
			
		||||
  const char* AVM_TOKENS[4] = {
 | 
			
		||||
    "+", "-", ".", 
 | 
			
		||||
    NULL
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  AVM_opcode AVM_OPCODES[4] = {
 | 
			
		||||
    avm_add, avm_sub, avm_dot, 
 | 
			
		||||
    avm_nop
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  for (int i = 0; AVM_TOKENS[i] != NULL; i++)
 | 
			
		||||
  {
 | 
			
		||||
    if (str == AVM_TOKENS[i])
 | 
			
		||||
      return AVM_OPCODES[i];
 | 
			
		||||
  }
 | 
			
		||||
  return avm_nop;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool TAVM::compile(istream& instr, TBytecode& bytecode)
 | 
			
		||||
{
 | 
			
		||||
  TString str(256);
 | 
			
		||||
  bytecode.destroy();
 | 
			
		||||
  bytecode.set_language("Alex");
 | 
			
		||||
  while (get_token(instr, str))
 | 
			
		||||
  {
 | 
			
		||||
    TAVM_op* op = NULL;
 | 
			
		||||
    if (str[0] == '"')
 | 
			
		||||
    {
 | 
			
		||||
      str.rtrim(1); str.ltrim(1); 
 | 
			
		||||
      op = new TAVM_op(avm_push, str);
 | 
			
		||||
    } else
 | 
			
		||||
    if (str[0] == '@') // Address of field?
 | 
			
		||||
    {
 | 
			
		||||
      str.ltrim(1); 
 | 
			
		||||
      op = new TAVM_op(avm_push, str);
 | 
			
		||||
    } else
 | 
			
		||||
    if (isdigit(str[0]))
 | 
			
		||||
    {
 | 
			
		||||
      const real r(str);
 | 
			
		||||
      op = new TAVM_op(avm_push, r);
 | 
			
		||||
    } else
 | 
			
		||||
    if (str[0] == '#')
 | 
			
		||||
    {
 | 
			
		||||
      op = new TAVM_op(avm_usrget, str);
 | 
			
		||||
    } 
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
      const AVM_opcode oc = token2opcode(str);
 | 
			
		||||
      if (oc != avm_nop)
 | 
			
		||||
        op = new TAVM_op(oc);
 | 
			
		||||
      else
 | 
			
		||||
      {
 | 
			
		||||
        const unsigned int oc = _vm->compile_usr_word(str);
 | 
			
		||||
        if (oc > 0)
 | 
			
		||||
          op = new TAVM_op(avm_usrword, oc);
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    if (op != NULL)
 | 
			
		||||
      bytecode.add(op);
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
      _last_error.cut(0) << "Unknown WORD: " << str;
 | 
			
		||||
      log_error(_last_error);
 | 
			
		||||
      return false;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  return true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool TAVM::execute(const TBytecode& bc, ostream& outstr)
 | 
			
		||||
{
 | 
			
		||||
  int ip = 0;
 | 
			
		||||
  while (ip < bc.items())
 | 
			
		||||
  {
 | 
			
		||||
    const TAVM_op& op = *(const TAVM_op*)bc.objptr(ip);
 | 
			
		||||
    bool jumped_elsewhere = false;
 | 
			
		||||
    switch(op.op())
 | 
			
		||||
    {
 | 
			
		||||
    case avm_add : 
 | 
			
		||||
      {
 | 
			
		||||
        const TVariant& v1 = _stack.pop();
 | 
			
		||||
        TVariant& v0 = (TVariant&)_stack.peek();
 | 
			
		||||
        v0.add(v1);
 | 
			
		||||
      }
 | 
			
		||||
      break;
 | 
			
		||||
    case avm_dot: outstr << _stack.pop().as_string(); break;
 | 
			
		||||
    case avm_dup: _stack.push(_stack.peek()); break;
 | 
			
		||||
    case avm_push: _stack.push(op.var()); break;
 | 
			
		||||
    case avm_sub : 
 | 
			
		||||
      {
 | 
			
		||||
        const TVariant& v1 = _stack.pop();
 | 
			
		||||
        TVariant& v0 = (TVariant&)_stack.peek();
 | 
			
		||||
        v0.sub(v1);
 | 
			
		||||
      }
 | 
			
		||||
      break;
 | 
			
		||||
    case avm_usrget: 
 | 
			
		||||
      {
 | 
			
		||||
        const TString& name = op.var().as_string();
 | 
			
		||||
        TVariant var; _vm->get_usr_val(name, var);
 | 
			
		||||
        _stack.push(var);
 | 
			
		||||
      }
 | 
			
		||||
      break;
 | 
			
		||||
    case avm_usrword: _vm->execute_usr_word(op.var().as_int(), _stack); break;
 | 
			
		||||
    default:
 | 
			
		||||
      _last_error << "Bad op code: " << op.op() << '\n';
 | 
			
		||||
      log_error(_last_error);
 | 
			
		||||
      return false;
 | 
			
		||||
    }
 | 
			
		||||
    if (!jumped_elsewhere)
 | 
			
		||||
      ip++;
 | 
			
		||||
  }
 | 
			
		||||
  return true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
///////////////////////////////////////////////////////////
 | 
			
		||||
// TAlex_virtual_machine
 | 
			
		||||
///////////////////////////////////////////////////////////
 | 
			
		||||
 | 
			
		||||
const TString& TAlex_virtual_machine::get_last_error() const
 | 
			
		||||
{
 | 
			
		||||
  if (_avm != NULL)
 | 
			
		||||
    return _avm->get_last_error();
 | 
			
		||||
 return EMPTY_STRING;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool TAlex_virtual_machine::compile(istream& instr, TBytecode& bc)
 | 
			
		||||
{
 | 
			
		||||
  if (_avm == NULL)
 | 
			
		||||
    _avm = new TAVM(this);
 | 
			
		||||
  return _avm->compile(instr, bc);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool TAlex_virtual_machine::execute(const TBytecode& bc, ostream& outstr)
 | 
			
		||||
{
 | 
			
		||||
  if (_avm == NULL)
 | 
			
		||||
    _avm = new TAVM(this);
 | 
			
		||||
  return _avm->execute(bc, outstr);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool TAlex_virtual_machine::compile(const char* cmd, TBytecode& bc)
 | 
			
		||||
{
 | 
			
		||||
  istrstream instr((char*)cmd, strlen(cmd));
 | 
			
		||||
  return compile(instr, bc);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool TAlex_virtual_machine::execute(const TBytecode& bc, TString& outs)
 | 
			
		||||
{
 | 
			
		||||
  char* buf = outs.get_buffer();
 | 
			
		||||
  memset(buf, 0, outs.size());
 | 
			
		||||
  ostrstream outstr(buf, outs.size());
 | 
			
		||||
  return execute(bc, outstr);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool TAlex_virtual_machine::get_usr_val(const TString& name, TVariant& var) const
 | 
			
		||||
{
 | 
			
		||||
  return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool TAlex_virtual_machine::set_usr_val(const TString& name, const TVariant& var)
 | 
			
		||||
{
 | 
			
		||||
  return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
unsigned int TAlex_virtual_machine::compile_usr_word(const TString& name) const
 | 
			
		||||
{
 | 
			
		||||
  return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool TAlex_virtual_machine::execute_usr_word(unsigned int opcode, TVariant_stack& stack)
 | 
			
		||||
{
 | 
			
		||||
  return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TAlex_virtual_machine::TAlex_virtual_machine() : _avm(NULL)
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TAlex_virtual_machine::~TAlex_virtual_machine()
 | 
			
		||||
{
 | 
			
		||||
  if (_avm != NULL)
 | 
			
		||||
    delete _avm;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										61
									
								
								ba/ba8304.h
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										61
									
								
								ba/ba8304.h
									
									
									
									
									
										Executable file
									
								
							@ -0,0 +1,61 @@
 | 
			
		||||
#ifndef __ALEX_H
 | 
			
		||||
#define __ALEX_H
 | 
			
		||||
 | 
			
		||||
#ifndef __RECORDSET_H
 | 
			
		||||
#include "ba8201.h"
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
class TVariant_stack : public TObject
 | 
			
		||||
{
 | 
			
		||||
  TArray _var;
 | 
			
		||||
  int _sp;
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
  int items() const { return _sp; }
 | 
			
		||||
  void push(const TVariant& var);
 | 
			
		||||
  TVariant& pop();
 | 
			
		||||
  TVariant& peek(int depth = 0);
 | 
			
		||||
  TVariant_stack() : _sp(0) { }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// Generic bytecode for any language
 | 
			
		||||
 | 
			
		||||
class TBytecode : public TArray
 | 
			
		||||
{
 | 
			
		||||
  TString16 _language;
 | 
			
		||||
  TString _name;
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
  void set_language(const char* lang) { _language = lang; }
 | 
			
		||||
  const TString& language() const { return _language; }
 | 
			
		||||
 | 
			
		||||
  const set_name(const char* name) { _name = name; }
 | 
			
		||||
  const TString& name() const { return _name; }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// ALEX = Another Language EXtension
 | 
			
		||||
 | 
			
		||||
class TAVM;
 | 
			
		||||
 | 
			
		||||
class TAlex_virtual_machine : public TObject
 | 
			
		||||
{
 | 
			
		||||
  TAVM* _avm; // Chesire's cat class
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
  virtual unsigned int compile_usr_word(const TString& name) const;
 | 
			
		||||
  virtual bool execute_usr_word(unsigned int opcode, TVariant_stack& stack);
 | 
			
		||||
  virtual bool get_usr_val(const TString& name, TVariant& var) const;
 | 
			
		||||
  virtual bool set_usr_val(const TString& name, const TVariant& var);
 | 
			
		||||
 | 
			
		||||
  const TString& get_last_error() const;
 | 
			
		||||
  bool compile(istream& instr, TBytecode& bc);
 | 
			
		||||
  bool compile(const char* cmd, TBytecode& bc);
 | 
			
		||||
  bool execute(const TBytecode& bc, ostream& outstr);
 | 
			
		||||
  bool execute(const TBytecode& bc, TString& outstr);
 | 
			
		||||
 | 
			
		||||
  TAlex_virtual_machine();
 | 
			
		||||
  virtual ~TAlex_virtual_machine();
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user