#include <printapp.h>
#include <iostream.h>
#include <mask.h>
#include <lffiles.h>
#include <stdio.h>
#include <urldefid.h>
#include <tabutil.h>
#include <utility.h> 

#include "ba6100a.h"
#include "ba6100b.h"

#define M_SET_PRINTER MENU_FILE + 1100
#define M_PRINT MENU_FILE + 1101
#define MENU_TYPE MENU_FILE + 1102

enum pt { undefined = 0, elenco = 1, schede = 2, rubriche = 3, etichette = 4 };
enum pw { anafis = 0, anagiu = 1, nditte = 2 };
enum in { residenza = 1, domfisc = 2, corrispondenza = 3 }; 

bool mask_reset_fields(TMask_field& mf, KEY k);

class TAnaprint_app : public TPrintapp
{
  friend bool mask_reset_fields(TMask_field& mf, KEY k);

  pt _pr_type;
  pw _pr_what;
  TRelation* _rel_fis;
  TRelation* _rel_giu;
  TRelation* _rel_dit;
  int _cfis1, _cgiu1, _cdit1;
  int _cfis2, _cgiu2, _cdit2;
  int _sort;
  bool _inclditte;
  TLocalisamfile* _comuni;
  // settings etichette
  in _ind_what;
  int _ind_row, _ind_col, _rows_et, _cols_et;
  int _piv_row, _piv_col, _cod_row, _cod_col;
  bool _is_piv, _is_cod;
  bool* _frpos;
  TString _cod, _cofi, _name, _surname, _address, 
  _cap, _prov, _loc, _com, _civ, _stato, _phone;                 
  TString16 _sex;
  
  int _ana_link, _dit_link;

protected:

  virtual void set_page(int file, int cnt);
  virtual bool preprocess_page(int file, int counter);
  virtual bool user_create();
  virtual bool user_destroy();
  virtual bool set_print(int n);
  virtual void process_link(int id, const char* txt);
  
public:


  int cfis() { return _sort == 1 ? _cfis1 : _cfis2; }
  int cgiu() { return _sort == 1 ? _cgiu1 : _cgiu2; }
  int cdit() { return _sort == 1 ? _cdit1 : _cdit2; }

  TRectype& look_com(const char* cod);
  const char* look_tab(const char* tabname, const char* cod, 
                       const char* fld = "S0");

  // bel casino, le schede
  void set_scheda_anagiu();
  void set_scheda_anafis();
  void set_scheda_ditta();
  void set_scheda_attiv();
  void set_scheda_registro();
  void set_scheda_unloc();
  void set_scheda_socio();
  void preprocess_etichette();
  void set_rubriche();
  void set_elenco();
  void set_schede();
  void set_etichette();
  void set_headers();

  const char* get_field(int ln, const char* fn)
  { return current_cursor()->curr(ln).get(fn); }

  void init_print();

  TAnaprint_app() : TPrintapp(), _cod(5), _cofi(30), _name(20), _surname(30), 
  _address(50), _cap(10), _prov(2), _com(50), _civ(5), 
  _stato(40),   _phone(30)

  { 
    _rel_fis = _rel_giu = _rel_dit = NULL; 
    _pr_type = undefined; _pr_what = anafis; 
    _inclditte = FALSE;
    _ind_what = residenza;
    _rows_et = 9; _cols_et = 40;
    _is_piv = TRUE; _is_cod = FALSE;
    _piv_row = 7; _cod_row = 2; _ind_row = 3;
    _piv_col = _ind_col = 3; _cod_col = 6;
    _frpos = NULL;
  }
};
