#ifndef __FORM_H
#define __FORM_H

#ifndef __PRINTER_H
#include <printer.h>
#endif

#ifndef __RELATION_H
class TRelation;
class TCursor;
#endif

#ifndef __SCANNER_H
#include <scanner.h>
#endif

class TForm;
class TForm_item;

class TPrint_section : public TArray
{
  TString16 _name;
  int _heigth;

  TForm* _form;
  TArray _item;

protected:
  virtual void print_on(ostream& out) const;
  TForm_item* parse_item(TScanner& scanner);

public:
  TPrintrow& row(int num);
  TForm* form() const { return _form; }

  TForm_item* item(int n) const { return (TForm_item*)_item.objptr(n); }
  int items() const { return _item.items(); }

  bool update();
  bool parse(TScanner& scanner);

  bool edit(int mode);

  TPrint_section(const char* name = "", TForm* form = NULL);
  void init(const char* name, TForm* form);
};


class TForm : public TObject
{
  TFilename _name;

  TRelation* _relation;
  TCursor* _cursor;

  TPrint_section _head;
  TPrint_section _body;
  TPrint_section _foot;

protected:
  virtual void print_on(ostream& out) const;

  bool parse_use(TScanner&);
  bool parse_join(TScanner&);

  bool set_header();
  bool set_footer();

public:
  bool print(long from = 0L, long to = -1L);
  TRelation* relation() const { return _relation; }
  TCursor* cursor() const { return _cursor; }

  bool edit(int mode, int section = 1);

  TForm(const char* form);
  ~TForm();
};

#endif
