#ifndef __BA8301_H
#define __BA8301_H

#ifndef __AUTOMASK_H
#include <automask.h>
#endif

#ifndef __TREE_H
#include <tree.h>
#endif

#ifndef __REPORT_H
#include <report.h>
#endif

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

///////////////////////////////////////////////////////////
// TReport_tree
///////////////////////////////////////////////////////////

class TReport_tree : public TBidirectional_tree
{
  TReport& _report;
  TString8 _curr;

protected:
  virtual bool get_description(TString& str) const;
  virtual TImage* image(bool selected) const;
  virtual void node2id(const TObject* node, TString& id) const;
  int curr_level() const;

public:
  virtual bool goto_root();
  virtual bool goto_firstson();
  virtual bool goto_rbrother(); 
  virtual bool goto_node(const TString &id);
  virtual bool has_son() const;
  virtual bool has_rbrother() const;
  virtual TObject* curr_node() const { return (TObject*)&_curr; }

  virtual bool has_root() const;
  virtual bool has_father() const;
  virtual bool has_lbrother() const;
  virtual bool goto_father();
  virtual bool goto_lbrother();

  TReport_section& curr_section() const;
  bool goto_node(char type, int level);

  int image_height() const;
  TReport_tree(TReport& r) : _report(r) { goto_root(); }
};

void describe_section(char type, int level, TString& str);

///////////////////////////////////////////////////////////
// TReport_drawer
///////////////////////////////////////////////////////////

class TReport_drawer : public TWindowed_field
{
protected:
  virtual TField_window* create_window(int x, int y, int dx, int dy, WINDOW parent);

public:
  void set_report_section(TReport_section& sec);
  TReport_section& curr_section();

  TReport_drawer(TMask* m) : TWindowed_field(m) { }
};

///////////////////////////////////////////////////////////
// TReport_base_mask
///////////////////////////////////////////////////////////

class TReport_base_mask : public TAutomask
{
  TReport_font _font;
  bool _font_changed;

  bool choose_printer_font(XVT_FNTID font);

protected:
  TReport& _report;
  char _halign, _valign;
  COLOR _fgcolor, _bgcolor, _shcolor;

  bool draw_3d_rect(short id, COLOR rgb) const;
  virtual void update();
  virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
  void kill_special_pattern();

public:
  void set_font_info(const TReport_font& font);
  bool get_font_info(TReport_font& font) const;
  
  TReport_base_mask(const char* name, TReport& rep);
};

class TReport_field_mask : public TReport_base_mask
{
  TReport_field& _rf;
  COLOR _txcolor;

protected:
  void vedo_non_vedo();
  virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
  virtual void update();

public:
  void set_num(short id, long n);
  long get_num(short id) const;

  void set_field(const TReport_field& rf);
  void get_field(TReport_field& rf) const;

  TReport_field_mask(TReport_field& rf); 
};

const TString& num2str(int num);
short str2num(const TString& str);

#define POPUP_CUT        20883
#define POPUP_COPY       20884
#define POPUP_PASTE      20885
#define POPUP_DUP        20886
#define POPUP_CLEAR      20887
#define POPUP_ZOOMIN     20888
#define POPUP_ZOOMOUT    20889
#define POPUP_BACKGROUND 20890
#define POPUP_SELALL     20891
#define POPUP_UNSELALL   20892
#define POPUP_PROPERTIES 20893
#define POPUP_NEWFIELD   20894
#define POPUP_SECTION    20895
#define POPUP_GROUP      20896
#define POPUP_UNGROUP    20897

#endif