#ifndef UI_H
#define UI_H

/***************************
 *** Selection subsystem ***
 ***************************

 Selection subsystem is an object oriented function collection for
 implementing selection menus. A selection is a dialog/screen which consists
 of header lines and choice lines. Header lines are informative text lines
 which give instructions to the user. Choice lines represent alternatives
 which the user may select. There is an integer ID associated with each choice
 line.

 A selection object is created using ui_sel_create(). The selection is
 executed (displayed) using ui_sel_run() and removed using ui_sel_delete().
 The selection is invisible outside invocation of ui_sel_run().

 Header lines are attached to the selection object using ui_sel_addhdr() and
 choice lines using ui_sel_addchoice().
 ********/

#define UI_MAXHDR 15

typedef struct ui_choice
{
  int id;
  char txt[128];
}
ui_choice;

extern int ui_module;
#define UI_TTY		0
#define UI_CURSES	1
#define UI_GTK		2

typedef struct ui_selection
{
  void *priv;			/* For private use of the UI package */
  char title[128];

  int nhdrs;			/* Number of header lines */
  char *hdrs[UI_MAXHDR];
  char hdrdesc[80];

  int maxchoices, nchoices;

  ui_choice *choices;

  int nbuttons;
  char *tbuttons[5];
  long buttonidents[5];

/*
 * Operative data
 */
  int height, width;
  int top;			/* Index of the first choice line visible on the screen */
  int active;			/* Currently selected line */
  int ppageoffs;		/* Offset to the top of the previous page (ui_tty only) */
  int npageoffs;		/* Offset to the top of the next page (ui_tty only) */
  int offs;			/* Offset from top of the window to the first scrollable line */

  int target;			/* 0=scroll area, 1..nbuttons=button */
}
ui_selection;

#define UI_NONEID	0x7fffffff


#define UI_VERSION 12345678

typedef struct
{
  int version;
  int (*ui_check) (void);
  int (*ui_init) (char *path);
  void (*ui_close) (void);
  void (*ui_message) (char *s, int pause);
  int (*ui_input) (char *question, char *answer);
  int (*ui_sel_run) (ui_selection * sel);
  void (*ui_sel_close_window) (ui_selection * sel);
}
ui_plugin;
#endif
int ui_init (char *path);
/*
 * Initializes User Interface (opens Display etc.);
 */

int ui_check (void);
/*
 * Checks if this UI plugin works or not
 */

void ui_close (void);
/*
 * Returns terminal back to normal mode 
 */


void ui_message (char *s, int pause);
/*
 * Displays one line message and optionally waits for a key.
 */

int ui_input (char *question, char *answer);
/*
 * Display a question to user and read the answer. Returns 1 if OK.
 */
ui_selection *ui_sel_create (char *title, int maxchoices);
int ui_sel_run (ui_selection * sel);
void ui_sel_delete (ui_selection * sel);

void ui_sel_delhdrs (ui_selection * sel);
void ui_sel_addhdr (ui_selection * sel, char *hdr);
void ui_sel_hdrdesc (ui_selection * sel, char *s);
/*
 * 'hdr' is a pointer to a NUL terminated string containing one or more lines.
 * Only the first line is displayed. The additional lines serve as a help
 * text.
 */

void ui_sel_addchoice (ui_selection * sel, char *line, int id);

void ui_sel_addbutton (ui_selection * sel, char *label, int id);

void ui_sel_setactive (ui_selection * sel, int num);
int ui_sel_getactive (ui_selection * sel);
void ui_sel_close_window (ui_selection * sel);
int ui_sel_getid (ui_selection * sel);
#ifdef linux
void ui_load_nullplugin (void);
#endif

#ifdef PLUGIN
ui_plugin ui_info = {
  UI_VERSION,
  ui_check,
  ui_init,
  ui_close,
  ui_message,
  ui_input,
  ui_sel_run,
  ui_sel_close_window
};
#endif
