#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <limits.h>
#include <db.h>
#include <dialog.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include "ui_objects.h"

#define PATHMAX		1024
#define DEFDIR		".tele"
#define DEFDB		"default.db"
#define DEFDBLOCK	".lock"

#define ATTR_TITLE	button_active_attr

#define DMENU_NORMAL_TYPE	0x1
#define DMENU_RADIO_TYPE	0x2
#define DMENU_CHECKLIST_TYPE	0x4
#define DMENU_SELECTION_RETURNS	0x8

#define TYPE_OF_OBJ(type)	((type) & 0xff)
#define ATTR_OF_OBJ(type)	((type) >> 16)

#define CLEAR(v)		memset(v, 0, sizeof v)

#define NLEN			100

/* definicje typow */

typedef unsigned int Boolean;

typedef struct _dmenu {
	int type;
	char *title;
	char *prompt;
	char *helpline;
	char *helpfile;
	dialogMenuItem items[0];
} DMenu;

typedef struct _layout {
	int y;
	int x;
	int len;
	int maxlen;
	char *prompt;
	char *help;
	void *var;
	int type;
	void *obj;
} Layout;

typedef struct _osoba {
	char imie[NLEN];
	char nazw[NLEN];
	char adres[NLEN];
	char tel[NLEN];
	char mail[NLEN];
	char kom[NLEN];
} Osoba;

/* zmienne globalne */

extern Boolean		ColorDisplay;
extern Boolean		DialogActive;
extern int		StatusLine;
extern DB		*db;

extern int		errno;
extern Osoba		rek;
extern Boolean		refr;

/* podstawowe funkcje systemowe */

extern void	systemInitialize(int argc, char **argv);
extern void	systemShutdown(int status);
extern char	*systemHelpFile(char *file, char *buf);
extern void	handle_intr(int sig);

/* obsługa okienek z wiadomościami */

extern void	msgFatal(char *fmt, ...);
extern void	msgConfirm(char *fmt, ...);
extern int	msgYesNo(char *fmt, ...);

/* pomocnicze */

extern WINDOW	*savescr(void);
extern void	restorescr(WINDOW *w);
extern Boolean	file_readable(char *fname);
extern WINDOW	*openLayoutDialog(char *helpfile, char *title, int x,
		int y, int width, int height);
extern ComposeObj *initLayoutDialog(WINDOW *win, Layout *layout, int x,
		int y, int *max);
extern int	layoutDialogLoop(WINDOW *win, Layout *layout,
		ComposeObj **obj, int *n, int max, int *cbutton, int *cancel);
extern void 	display_helpfile(void);
extern void 	display_helpline(WINDOW *w, int y, int width);

/* obsługa menu */

extern DMenu	MenuInitial;
extern DMenu	MenuAdm;

extern int	dmenuExit(dialogMenuItem *tmp);
extern Boolean	dmenuOpen(DMenu *menu, int *choice, int *scroll, int *curr,
		int *max, Boolean buttons);
extern Boolean	dmenuOpenSimple(DMenu *menu, Boolean buttons);

/* zdarzenia */

extern int	bAdd(dialogMenuItem *tmp);
extern int	bAdm(dialogMenuItem *tmp);

/* hash */
extern int	hash_insert(void);
extern dialogMenuItem	**hash_to_menu(int *ile);

