#ifndef __FILAPP_H
#include <filapp.h>
#endif 

#ifndef __XVTILITY_H
#include <xvtility.h>
#endif 

#ifndef __EXTCTYPE_H
#include <extctype.h>
#endif 

#ifndef __URLDEFID_H
#include <urldefid.h>
#endif 

#ifndef __STDTYPES_H
#include <stdtypes.h>
#endif 

#ifndef __MASK_H
#include <mask.h>
#endif 

#ifndef __BA1_H
#include "ba1.h"
#endif 


#include <string.h>

// Qui includo la classe TDir_sheet
#ifndef __BA1101_H
#include "ba1101.h"
#endif

#ifndef __BA1201_H
#include "ba1201.h"
#endif 

#ifndef __BA1200_H
#include "ba1200.h"
#endif 

#ifndef __LFFILES_H
#include <lffiles.h>
#endif


class BA1200_application : public TApplication
{
TDir_sheet	* _browse_dir;
TRec_sheet      * _browse_rec;
TMask		* _mask;
bool menu (MENU_TAG);
bool create () ;
bool destroy();
//void insert_riga(long, TToken_string&);
void edit_campo(TToken_string);
void visualizza_tracciato(long);

public:
  BA1200_application();
};

BA1200_application::BA1200_application()
{
}

bool BA1200_application::create() // initvar e arrmask
{
_browse_rec = new TRec_sheet ("Manutenzione tracciati record", "N. |Nome campo|Tipo campo|Lunghezza|Decimali") ;
if (_browse_rec == NULL) fatal_box("Non e' possibile allocare _browse_rec");

_browse_dir = new TDir_sheet ("Manutenzione tracciati record") ;
if (_browse_dir == NULL) fatal_box("Non e' possibile allocare _browse_dir");

_mask = new TMask ("ba1200a");

dispatch_e_menu(BAR_ITEM(1));
return TRUE ;
}

bool BA1200_application::destroy() // releasev e arrmask
{
	delete  _browse_rec;
        delete  _browse_dir;
        delete  _mask;
	return TRUE ;
}

/*
void BA1200_application::insert_riga (long riga_sel, TToken_string& riga)
{
KEY	tasto; 
//FileDes	dep;
long	num_files = _browse->dir()->items();

	_mask->set (FLD_NUM, riga.get());

	tasto=_mask->run();

	switch (tasto) {
		case K_ENTER:

			for (int i=num_files; i>=riga_sel; i--) {
				_browse->dir()->get (i, _nolock, _nordir, _sysdirop);
				_browse->dir()->put (i+1, _nordir, _sysdirop);

			}

			_browse->dir()->set 	(_mask->get (FLD_NOME), 
				atoi(_mask->get (FLD_EOD)),
				atoi(_mask->get (FLD_FLAG)),
				_mask->get (FLD_DESC),
				_mask->get (FLD_FORMULA));

			_browse->dir()->put(riga_sel, _nordir, _sysdirop);
			break;
		default:
			break;
	}
}
*/

void BA1200_application::edit_campo (TToken_string riga_campo)
{
KEY   tasto;

_mask->set (FLD_NUM,riga_campo.get());
_mask->set (FLD_NOME_CAMPO,riga_campo.get());
_mask->set (FLD_TIPO_CAMPO,riga_campo.get());
_mask->set (FLD_LUNGHEZZA,riga_campo.get());
_mask->set (FLD_DECIMALI,riga_campo.get());

tasto = _mask->run();
switch (tasto) {
 case K_ENTER:
    
    break;
  case K_ESC:
    break;
  default:
    break;
    }
}

void BA1200_application::visualizza_tracciato (long file_sel)
{
KEY		tasto;
RecDes	       *dep;
int             nfile;
TToken_string   riga_campo;

tasto = _browse_rec->run();

switch (tasto) {
	case K_ENTER:
                riga_campo=_browse_rec->row();
                edit_campo(riga_campo);
	     	break;
	default:
		break;
	}
}

bool BA1200_application::menu(MENU_TAG m)
{
TTrec		*dep;
TToken_string	riga;
//long		riga_selezionata;
long            num_file_selezionato;
bool		done = FALSE;
KEY		tasto;

while (!done) {

	tasto = _browse_dir->run();

	switch (tasto) {

/* Insert 
		case K_INS: 
			riga_selezionata = _browse->selected();
			riga = _browse->row();
			insert_riga (riga_selezionata, riga);
			break; 
*/

// Edit 
		case K_ENTER: 
			num_file_selezionato = _browse_dir->selected();
			riga = _browse_dir->row();

dep = _browse_rec->rec();
dep->get((int)num_file_selezionato+1, _nordir);

			visualizza_tracciato (num_file_selezionato);
			break;

		case K_ESC: 
	 		done = TRUE;
			break;
//			return TRUE;
			}
}
return TRUE;
}

int ba1200(int argc, char* argv[], bool insmode)
{
	BA1200_application a;

	a.run(argc, argv, "");
	return 0;
}





